private static void Main(string[] args) { var testHelper = new ModuleWeaverTestHelper <ModuleWeaver>( "DbTestMonkey.NUnit.Tests.dll", modifyOriginalBinaries: true); // Keeping this zombie code in for diagnostic purposes in future. // MSBuild task fails if I leave it in. /* * Console.WriteLine("Weaving informational messages:"); * * foreach (var msg in testHelper.InfoMessages) * { * Console.WriteLine(msg); * } * * Console.WriteLine("Weaving error messages:"); */ if (testHelper.Errors.Count != 0) { foreach (var err in testHelper.Errors) { Console.WriteLine(err); } throw new InvalidOperationException( "Failed to weave DbTestMonkey.NUnit.Tests assembly. Number of errors: " + testHelper.Errors.Count); } }
public void Classes_with_existing_constructor_and_class_fixture_should_have_constructor_merged() { // Arrange. // Act. var testHelper = new ModuleWeaverTestHelper<ModuleWeaver>("XUnitAssemblyNoConfig.dll"); // Assert. testHelper.Errors.Count.Should().Be(0); var type = testHelper.ModuleDefinition.GetType("XUnitAssemblyNoConfig.ClassWithExistingConstructorAndClassFixture"); type.HasDisposeMethod().Should().BeTrue(); var ctor = type.Methods.Single(m => m.IsInstanceConstructor()); ctor.Parameters.Count.Should().Be(4); ctor.Parameters.ElementAt(0).ParameterType.FullName.Should().Be("XUnitAssemblyNoConfig.ArbitraryFixtureClass"); ctor.Parameters.ElementAt(1).ParameterType.FullName.Should().Be(typeof(ITestOutputHelper).FullName); ctor.Parameters.ElementAt(2).ParameterType.FullName.Should().Be(typeof(ClassDatabaseFixture).FullName); ctor.Parameters.ElementAt(3).ParameterType.FullName.Should().Be(typeof(CollectionDatabaseFixture).FullName); type.Interfaces.Count().Should().Be(3); type.Interfaces.ElementAt(0).FullName.Should().Be("Xunit.IClassFixture`1<XUnitAssemblyNoConfig.ArbitraryFixtureClass>"); type.Interfaces.ElementAt(1).FullName.Should().Be("System.IDisposable"); type.Interfaces.ElementAt(2).FullName.Should().Be("Xunit.IClassFixture`1<DbTestMonkey.XUnit.Fody.ClassDatabaseFixture>"); type.CustomAttributes.Count().Should().Be(1); type.CustomAttributes.ElementAt(0).AttributeType.FullName.Should().Be(typeof(CollectionAttribute).FullName); }
private static void Main(string[] args) { var testHelper = new ModuleWeaverTestHelper<ModuleWeaver>( "DbTestMonkey.XUnit.Tests.dll", modifyOriginalBinaries: true); // Keeping this zombie code in for diagnostic purposes in future. // MSBuild task fails if I leave it in. /* Console.WriteLine("Weaving informational messages:"); foreach (var msg in testHelper.InfoMessages) { Console.WriteLine(msg); } Console.WriteLine("Weaving error messages:"); */ if (testHelper.Errors.Count != 0) { foreach (var err in testHelper.Errors) { Console.WriteLine(err); } throw new InvalidOperationException( "Failed to weave DbTestMonkey.XUnit.Tests assembly. Number of errors: " + testHelper.Errors.Count); } }
public void Classes_with_existing_constructor_and_class_fixture_should_have_constructor_merged() { // Arrange. // Act. var testHelper = new ModuleWeaverTestHelper <ModuleWeaver>("XUnitAssemblyNoConfig.dll"); // Assert. testHelper.Errors.Count.Should().Be(0); var type = testHelper.ModuleDefinition.GetType("XUnitAssemblyNoConfig.ClassWithExistingConstructorAndClassFixture"); type.HasDisposeMethod().Should().BeTrue(); var ctor = type.Methods.Single(m => m.IsInstanceConstructor()); ctor.Parameters.Count.Should().Be(4); ctor.Parameters.ElementAt(0).ParameterType.FullName.Should().Be("XUnitAssemblyNoConfig.ArbitraryFixtureClass"); ctor.Parameters.ElementAt(1).ParameterType.FullName.Should().Be(typeof(ITestOutputHelper).FullName); ctor.Parameters.ElementAt(2).ParameterType.FullName.Should().Be(typeof(ClassDatabaseFixture).FullName); ctor.Parameters.ElementAt(3).ParameterType.FullName.Should().Be(typeof(CollectionDatabaseFixture).FullName); type.Interfaces.Count().Should().Be(3); type.Interfaces.ElementAt(0).FullName.Should().Be("Xunit.IClassFixture`1<XUnitAssemblyNoConfig.ArbitraryFixtureClass>"); type.Interfaces.ElementAt(1).FullName.Should().Be("System.IDisposable"); type.Interfaces.ElementAt(2).FullName.Should().Be("Xunit.IClassFixture`1<DbTestMonkey.XUnit.Fody.ClassDatabaseFixture>"); type.CustomAttributes.Count().Should().Be(1); type.CustomAttributes.ElementAt(0).AttributeType.FullName.Should().Be(typeof(CollectionAttribute).FullName); }
public void FixtureSetUp() { var assembly = Assembly.GetExecutingAssembly(); var directoryThisAssembly = Path.GetDirectoryName(assembly.Location); _moduleWeaverTestHelper = new ModuleWeaverTestHelper(Path.Combine(directoryThisAssembly, "../../../../AssemblyToProcess/bin/Debug/netstandard2.1/AssemblyToProcess.dll")); _consoleOutput = new StringWriter(); Console.SetOut(_consoleOutput); _originalLogWriter = DisposeTracker.LogWriter; }
public void Empty_classes_with_connection_attributes_only_should_receive_correct_structure() { // Arrange. // Act. var testHelper = new ModuleWeaverTestHelper<ModuleWeaver>("XUnitAssemblyNoConfig.dll"); // Assert. testHelper.Errors.Count.Should().Be(0); var type = testHelper.ModuleDefinition.GetType("XUnitAssemblyNoConfig.ClassWithConnectionButNoUsesDatabases"); type.HasDisposeMethod().Should().BeTrue(); var ctor = type.Methods.Single(m => m.IsConstructor); ctor.Parameters.Count.Should().Be(3); ctor.Parameters.ElementAt(0).ParameterType.FullName.Should().Be(typeof(ITestOutputHelper).FullName); ctor.Parameters.ElementAt(1).ParameterType.FullName.Should().Be(typeof(ClassDatabaseFixture).FullName); ctor.Parameters.ElementAt(2).ParameterType.FullName.Should().Be(typeof(CollectionDatabaseFixture).FullName); }
public void Empty_classes_with_connection_attributes_only_should_receive_correct_structure() { // Arrange. // Act. var testHelper = new ModuleWeaverTestHelper <ModuleWeaver>("XUnitAssemblyNoConfig.dll"); // Assert. testHelper.Errors.Count.Should().Be(0); var type = testHelper.ModuleDefinition.GetType("XUnitAssemblyNoConfig.ClassWithConnectionButNoUsesDatabases"); type.HasDisposeMethod().Should().BeTrue(); var ctor = type.Methods.Single(m => m.IsConstructor); ctor.Parameters.Count.Should().Be(3); ctor.Parameters.ElementAt(0).ParameterType.FullName.Should().Be(typeof(ITestOutputHelper).FullName); ctor.Parameters.ElementAt(1).ParameterType.FullName.Should().Be(typeof(ClassDatabaseFixture).FullName); ctor.Parameters.ElementAt(2).ParameterType.FullName.Should().Be(typeof(CollectionDatabaseFixture).FullName); }
public void Empty_classes_with_usesdatabasesattribute_should_receive_correct_structure() { // Arrange. // Act. var testHelper = new ModuleWeaverTestHelper <ModuleWeaver>("XUnitAssemblyNoConfig.dll"); // Assert. testHelper.InfoMessages.ForEach(e => _outputHelper.WriteLine(e)); testHelper.Errors.ForEach(e => _outputHelper.WriteLine(e)); testHelper.Errors.Count.Should().Be(0); var type = testHelper.ModuleDefinition.GetType("XUnitAssemblyNoConfig.EmptyClassWithDefaultProvider"); type.HasDisposeMethod().Should().BeTrue(); var ctor = type.Methods.Single(m => m.IsConstructor); ctor.Parameters.Count.Should().Be(3); ctor.Parameters.ElementAt(0).ParameterType.FullName.Should().Be(typeof(ITestOutputHelper).FullName); ctor.Parameters.ElementAt(1).ParameterType.FullName.Should().Be(typeof(ClassDatabaseFixture).FullName); ctor.Parameters.ElementAt(2).ParameterType.FullName.Should().Be(typeof(CollectionDatabaseFixture).FullName); }
public void Empty_classes_with_usesdatabasesattribute_should_receive_correct_structure() { // Arrange. // Act. var testHelper = new ModuleWeaverTestHelper<ModuleWeaver>("XUnitAssemblyNoConfig.dll"); // Assert. testHelper.InfoMessages.ForEach(e => _outputHelper.WriteLine(e)); testHelper.Errors.ForEach(e => _outputHelper.WriteLine(e)); testHelper.Errors.Count.Should().Be(0); var type = testHelper.ModuleDefinition.GetType("XUnitAssemblyNoConfig.EmptyClassWithDefaultProvider"); type.HasDisposeMethod().Should().BeTrue(); var ctor = type.Methods.Single(m => m.IsConstructor); ctor.Parameters.Count.Should().Be(3); ctor.Parameters.ElementAt(0).ParameterType.FullName.Should().Be(typeof(ITestOutputHelper).FullName); ctor.Parameters.ElementAt(1).ParameterType.FullName.Should().Be(typeof(ClassDatabaseFixture).FullName); ctor.Parameters.ElementAt(2).ParameterType.FullName.Should().Be(typeof(CollectionDatabaseFixture).FullName); }
public void Verity_throws_an_exception() { var testHelper = new ModuleWeaverTestHelper(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyWithReadOnly\bin\Debug\AssemblyWithReadOnly.dll")); Assert.AreEqual("Could not add dispose for field 'WithReadOnly.stream' since it is marked as readonly. Change this field to not be readonly.", testHelper.Errors[0]); }
public ModuleWeaverTests() { moduleWeaverTestHelper = new ModuleWeaverTestHelper(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll")); }
public ModuleWeaverTests() { moduleWeaverTestHelper = new ModuleWeaverTestHelper(@"..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); }
public void Verity_throws_an_exception() { var testHelper = new ModuleWeaverTestHelper(@"..\..\..\AssemblyWithReadOnly\bin\Debug\AssemblyWithReadOnly.dll"); Assert.AreEqual("Could not add dispose for field 'WithReadOnly.stream' since it is marked as readonly. Please change this field to not be readonly.", testHelper.Errors[0]); }