From f6ed74787c103ba8809f720b7aede765d83bdf50 Mon Sep 17 00:00:00 2001 From: James Skimming Date: Mon, 29 Jul 2013 08:10:12 +0100 Subject: [PATCH] Added complex generic types #1 These are excluded from tests at the moment as the framework cannot handle them. --- .../Issues/Issue001/Issue001.cs | 15 +++++- .../RequiresArgNullExAutoMoqAttribute.cs | 4 +- .../AutoTest.ExampleLibrary.csproj | 1 + .../Issues/Issue001/ComplexGenericMethods.cs | 52 +++++++++++++++++++ .../Issue001/InterfaceGenericMethods.cs | 2 +- 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/ComplexGenericMethods.cs diff --git a/src/Tests/AutoTest.ExampleLibrary.Tests/Issues/Issue001/Issue001.cs b/src/Tests/AutoTest.ExampleLibrary.Tests/Issues/Issue001/Issue001.cs index ab68acd..0fbbd60 100644 --- a/src/Tests/AutoTest.ExampleLibrary.Tests/Issues/Issue001/Issue001.cs +++ b/src/Tests/AutoTest.ExampleLibrary.Tests/Issues/Issue001/Issue001.cs @@ -44,7 +44,6 @@ public async Task MixedStringValue(MethodData method) } [Theory, RequiresArgNullExAutoMoq(typeof(InterfaceGenericMethods))] - [Include(Type = typeof(InterfaceGenericMethods))] [Include( ExclusionType = ExclusionType.All, Type = typeof(InterfaceGenericMethods), @@ -58,7 +57,6 @@ public async Task InterfaceClassValue(MethodData method) } [Theory, RequiresArgNullExAutoMoq(typeof(InterfaceGenericMethods))] - [Include(Type = typeof(InterfaceGenericMethods))] [Include( ExclusionType = ExclusionType.All, Type = typeof(InterfaceGenericMethods), @@ -70,5 +68,18 @@ public async Task InterfaceStringValue(MethodData method) Assert.True(InterfaceGenericMethods.StringValueTested); } + + [Theory, RequiresArgNullExAutoMoq(typeof(ComplexGenericMethods))] + [Include( + ExclusionType = ExclusionType.Parameters, + Type = typeof(ComplexGenericMethods), + Method = "NonGenericMethod", + Parameter = "value")] + public async Task ComplexNonGeneric(MethodData method) + { + await method.Execute(); + + Assert.True(ComplexGenericMethods.NonGenericTested); + } } } diff --git a/src/Tests/AutoTest.ExampleLibrary.Tests/RequiresArgNullExAutoMoqAttribute.cs b/src/Tests/AutoTest.ExampleLibrary.Tests/RequiresArgNullExAutoMoqAttribute.cs index e8ffe7d..9c2c12d 100644 --- a/src/Tests/AutoTest.ExampleLibrary.Tests/RequiresArgNullExAutoMoqAttribute.cs +++ b/src/Tests/AutoTest.ExampleLibrary.Tests/RequiresArgNullExAutoMoqAttribute.cs @@ -5,6 +5,7 @@ using System.Reflection; using AutoTest.ArgNullEx; using AutoTest.ArgNullEx.Xunit; + using AutoTest.ExampleLibrary.Issues.Issue001; using Ploeh.AutoFixture; using Ploeh.AutoFixture.AutoMoq; @@ -40,7 +41,8 @@ private static IArgumentNullExceptionFixture CreateFixture(Assembly assemblyUnde // Don't need to create complex graphs, just need objects. fixture.OmitAutoProperties = true; - return new ArgumentNullExceptionFixture(assemblyUnderTest, fixture); + return new ArgumentNullExceptionFixture(assemblyUnderTest, fixture) + .ExcludeType(typeof(ComplexGenericMethods)); // Exclude until it can be tested. } } } diff --git a/src/Tests/AutoTest.ExampleLibrary/AutoTest.ExampleLibrary.csproj b/src/Tests/AutoTest.ExampleLibrary/AutoTest.ExampleLibrary.csproj index a691015..02c90e4 100644 --- a/src/Tests/AutoTest.ExampleLibrary/AutoTest.ExampleLibrary.csproj +++ b/src/Tests/AutoTest.ExampleLibrary/AutoTest.ExampleLibrary.csproj @@ -38,6 +38,7 @@ Properties\AssemblyInfoCommon.cs + diff --git a/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/ComplexGenericMethods.cs b/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/ComplexGenericMethods.cs new file mode 100644 index 0000000..4edc7ca --- /dev/null +++ b/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/ComplexGenericMethods.cs @@ -0,0 +1,52 @@ +namespace AutoTest.ExampleLibrary.Issues.Issue001 +{ + using System; + + public static class ComplexGenericMethods + { + /// + /// Gets a value indicating if the value parameter has been tested. + /// + public static bool NonGenericTested { get; private set; } + + public interface ITest1 + { + string String1 { get; set; } + } + + public interface ITest2 + { + string String2 { get; set; } + } + + public static void NonGenericMethod(string value) + { + NonGenericTested = false; + if (value == null) + { + NonGenericTested = true; + throw new ArgumentNullException("value"); + } + + throw new Exception("Shouldn't ever get here."); + } + + public static void GenericClassMethod(TClass classValue, string stringValue) + where TClass : class, ITest1, ITest2 + { + throw new Exception("Shouldn't ever get here."); + } + + public static void GenericExceptionMethod(TException classValue, string stringValue) + where TException : Exception, ITest1, ITest2 + { + throw new Exception("Shouldn't ever get here."); + } + + public static void GenericStructMethod(TStruct classValue, string stringValue) + where TStruct : struct, ITest1, ITest2 + { + throw new Exception("Shouldn't ever get here."); + } + } +} diff --git a/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/InterfaceGenericMethods.cs b/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/InterfaceGenericMethods.cs index 9c67391..f6666ac 100644 --- a/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/InterfaceGenericMethods.cs +++ b/src/Tests/AutoTest.ExampleLibrary/Issues/Issue001/InterfaceGenericMethods.cs @@ -27,7 +27,7 @@ public interface ITest2 public static void GenericMethod(TClass classValue, string stringValue) where TClass : ITest1, ITest2 { - ClassValueTested = false; + StringValueTested = ClassValueTested = false; if (classValue == null) {