public void CustomizeNullFixtureThrows()
 {
     // Fixture setup
     var sut = new AutoNSubstituteCustomization();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Customize(null));
     // Teardown
 }
        public void CustomizeNullFixtureThrows()
        {
            // Arrange
            var sut = new AutoNSubstituteCustomization();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Customize(null));
        }
        public void CustomizeNullFixtureThrows()
        {
            // Fixture setup
            var sut = new AutoNSubstituteCustomization();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Customize(null));
            // Teardown
        }
        public void CustomizeInsertsSubstituteAttributeRelayInCustomizationsToOverrideDefaultConstructionWhenAttributeIsPresent()
        {
            // Arrange
            var sut     = new AutoNSubstituteCustomization();
            var fixture = Substitute.For <IFixture>();

            // Act
            sut.Customize(fixture);
            // Assert
            fixture.Customizations.Received().Insert(0, Arg.Any <SubstituteAttributeRelay>());
        }
        public void CustomizeInsertsSubstituteAttributeRelayInCustomizationsToOverrideDefaultConstructionWhenAttributeIsPresent()
        {
            // Fixture setup
            var sut     = new AutoNSubstituteCustomization();
            var fixture = Substitute.For <IFixture>();

            // Exercise system
            sut.Customize(fixture);
            // Verify outcome
            fixture.Customizations.Received().Insert(0, Arg.Any <SubstituteAttributeRelay>());
            // Teardown
        }
        public void WithoutGenerateDelegates_ShouldNotAddRelayForDelegates()
        {
            // Arrange
            var fixtureStub = new FixtureStub();
            var sut         = new AutoNSubstituteCustomization {
                GenerateDelegates = false
            };

            // Act
            sut.Customize(fixtureStub);
            // Assert
            Assert.DoesNotContain(fixtureStub.Customizations, c => c is SubstituteRelay);
        }
        public void CustomizeInsertsProperlyConfiguredSubstituteRequestHandlerInCustomizationsToHandleSubstituteRequests()
        {
            // Arrange
            var sut         = new AutoNSubstituteCustomization();
            var fixtureStub = new FixtureStub();

            // Act
            sut.Customize(fixtureStub);
            // Assert
            var substituteRequestHandler = fixtureStub.Customizations.OfType <SubstituteRequestHandler>().Single();
            var substituteConstructor    = Assert.IsType <MethodInvoker>(substituteRequestHandler.SubstituteFactory);

            Assert.IsType <NSubstituteMethodQuery>(substituteConstructor.Query);
        }
        public void WithGenerateDelegates_CustomizeAddsRelayForDelegates()
        {
            // Arrange
            var fixtureStub = new FixtureStub();
            var sut         = new AutoNSubstituteCustomization {
                GenerateDelegates = true
            };

            // Act
            sut.Customize(fixtureStub);
            // Assert
            var substituteRelay = fixtureStub.Customizations.OfType <SubstituteRelay>().Single();

            Assert.IsType <DelegateSpecification>(substituteRelay.Specification);
        }
        public void CustomizeAddsAppropriateResidueCollector()
        {
            // Arrange
            var residueCollectors = new List <ISpecimenBuilder>();
            var fixtureStub       = Substitute.For <IFixture>();

            fixtureStub.ResidueCollectors.Returns(residueCollectors);

            var sut = new AutoNSubstituteCustomization();

            // Act
            sut.Customize(fixtureStub);
            // Assert
            Assert.Contains(sut.Relay, residueCollectors);
        }
        public void CustomizeAddsNoCustomizations()
        {
            // Fixture setup
            var customizations = new List <ISpecimenBuilder>();
            var fixtureStub    = Substitute.For <IFixture>();

            fixtureStub.Customizations.Returns(customizations);

            var sut = new AutoNSubstituteCustomization();

            // Exercise system
            sut.Customize(fixtureStub);
            // Verify outcome
            Assert.Empty(customizations);
            // Teardown
        }
        public void CustomizeAddsAppropriateResidueCollector()
        {
            // Fixture setup
            var residueCollectors = new List <ISpecimenBuilder>();
            var fixtureStub       = Substitute.For <IFixture>();

            fixtureStub.ResidueCollectors.Returns(residueCollectors);

            var sut = new AutoNSubstituteCustomization();

            // Exercise system
            sut.Customize(fixtureStub);
            // Verify outcome
            Assert.Contains(sut.Builder, residueCollectors);
            // Teardown
        }
        public void CustomizeInsertsProperlyConfiguredSubstituteRequestHandlerInCustomizationsToHandleSubstituteRequests()
        {
            // Arrange
            var sut = new AutoNSubstituteCustomization();
            SubstituteRequestHandler builder = null;
            var fixture = Substitute.For <IFixture>();

            fixture.Customizations.Insert(Arg.Any <int>(), Arg.Do <SubstituteRequestHandler>(b => builder = b));
            // Act
            sut.Customize(fixture);
            // Assert
            Assert.NotNull(builder);
            var substituteConstructor = Assert.IsType <MethodInvoker>(builder.SubstituteFactory);

            Assert.IsType <NSubstituteMethodQuery>(substituteConstructor.Query);
        }
        public void WithConfigureMembers_CustomizeAddsPostprocessorWithSubstituteRequestHandlerAndCommandsToCustomizations()
        {
            // Arrange
            var fixtureStub = new FixtureStub();
            var sut         = new AutoNSubstituteCustomization {
                ConfigureMembers = true
            };

            // Act
            sut.Customize(fixtureStub);
            // Assert
            var postprocessor            = fixtureStub.Customizations.OfType <Postprocessor>().Single();
            var substituteRequestHandler = Assert.IsAssignableFrom <SubstituteRequestHandler>(postprocessor.Builder);
            var substituteFactory        = Assert.IsType <MethodInvoker>(substituteRequestHandler.SubstituteFactory);

            Assert.IsType <NSubstituteMethodQuery>(substituteFactory.Query);
            var compositeCommand = Assert.IsAssignableFrom <CompositeSpecimenCommand>(postprocessor.Command);

            Assert.True(compositeCommand.Commands.OfType <NSubstituteRegisterCallHandlerCommand>().Any());
            Assert.True(compositeCommand.Commands.OfType <NSubstituteSealedPropertiesCommand>().Any());
        }
 public void CustomizeInsertsProperlyConfiguredSubstituteRequestHandlerInCustomizationsToHandleSubstituteRequests()
 {
     // Fixture setup
     var sut = new AutoNSubstituteCustomization();
     SubstituteRequestHandler builder = null;
     var fixture = Substitute.For<IFixture>();
     fixture.Customizations.Insert(Arg.Any<int>(), Arg.Do<SubstituteRequestHandler>(b => builder = b));
     // Exercise system
     sut.Customize(fixture);
     // Verify outcome
     Assert.NotNull(builder);
     var substituteConstructor = Assert.IsType<MethodInvoker>(builder.SubstituteFactory);
     Assert.IsType<NSubstituteMethodQuery>(substituteConstructor.Query);
     // Teardown
 }
 public void CustomizeInsertsSubstituteAttributeRelayInCustomizationsToOverrideDefaultConstructionWhenAttributeIsPresent()
 {
     // Fixture setup
     var sut = new AutoNSubstituteCustomization();
     var fixture = Substitute.For<IFixture>();
     // Exercise system
     sut.Customize(fixture);
     // Verify outcome
     fixture.Customizations.Received().Insert(0, Arg.Any<SubstituteAttributeRelay>());
     // Teardown
 }
        public void CustomizeAddsNoCustomizations()
        {
            // Fixture setup
            var customizations = new List<ISpecimenBuilder>();
            var fixtureStub = Substitute.For<IFixture>();
            fixtureStub.Customizations.Returns(customizations);

            var sut = new AutoNSubstituteCustomization();
            // Exercise system
            sut.Customize(fixtureStub);
            // Verify outcome
            Assert.Empty(customizations);
            // Teardown
        }
 public void CustomizeAddsAppropriateResidueCollector()
 {
     // Fixture setup
     var residueCollectors = new List<ISpecimenBuilder>();
     var fixtureStub = Substitute.For<IFixture>();
     fixtureStub.ResidueCollectors.Returns(residueCollectors);
     
     var sut = new AutoNSubstituteCustomization();
     // Exercise system
     sut.Customize(fixtureStub);
     // Verify outcome
     Assert.Contains(sut.Builder, residueCollectors);
     // Teardown
 }