Exemplo n.º 1
0
 public void InitializeWithNullEqualityComparerThrows()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() => new DelegatingRecursionGuard(dummyBuilder, null));
     // Teardown
 }
Exemplo n.º 2
0
 public void SutIsNode()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     // Exercise system
     var sut = new DelegatingRecursionGuard(dummyBuilder);
     // Verify outcome
     Assert.IsAssignableFrom<ISpecimenBuilderNode>(sut);
     // Teardown
 }
 public void IndexOfReturnsCorrectResultWhenItemIsNotInNode()
 {
     // Fixture setup
     var item = new DelegatingSpecimenBuilder();
     // Exercise system
     var actual = this.sut.IndexOf(item);
     // Verify outcome
     Assert.Equal(-1, actual);
     // Teardown
 }
Exemplo n.º 4
0
 public void SutYieldsInjectedBuilder()
 {
     // Fixture setup
     var expected = new DelegatingSpecimenBuilder();
     var sut = new DelegatingRecursionGuard(expected);
     // Exercise system
     // Verify outcome
     Assert.Equal(expected, sut.Single());
     Assert.Equal(expected, ((System.Collections.IEnumerable)sut).Cast<object>().Single());
     // Teardown
 }
 public void AddAddsItemToEndOfNode()
 {
     // Fixture setup
     var item = new DelegatingSpecimenBuilder();
     var expected = this.FindMarkedNode().Concat(new[] { item });
     // Exercise system
     this.sut.Add(item);
     // Verify outcome
     Assert.True(expected.SequenceEqual(this.sut));
     // Teardown
 }
 public void TransformReturnsCorrectResult()
 {
     // Fixture setup
     var sut = new ThrowingRecursionBehavior();
     // Exercise system
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var result = sut.Transform(dummyBuilder);
     // Verify outcome
     Assert.IsAssignableFrom<ThrowingRecursionGuard>(result);
     // Teardown
 }
 public void InsertsCorrectlyInsertsItem(int expected)
 {
     // Fixture setup
     var item = new DelegatingSpecimenBuilder();
     // Exercise system
     this.sut.Insert(expected, item);
     // Verify outcome
     var actual = this.sut.IndexOf(item);
     Assert.Equal(expected, actual);
     // Teardown
 }
 public void TransformResultCorrectlyDecoratesInput()
 {
     // Fixture setup
     var sut = new OmitOnRecursionBehavior();
     var expectedBuilder = new DelegatingSpecimenBuilder();
     // Exercise system
     var result = sut.Transform(expectedBuilder);
     // Verify outcome
     var guard = Assert.IsAssignableFrom<RecursionGuard>(result);
     Assert.Equal(expectedBuilder, guard.Builder);
     // Teardown
 }
Exemplo n.º 9
0
 public void TransformReturnsCorrectResult()
 {
     // Fixture setup
     var sut = new TracingBehavior();
     var builder = new DelegatingSpecimenBuilder();
     // Exercise system
     var result = sut.Transform(builder);
     // Verify outcome
     var tw = Assert.IsAssignableFrom<TraceWriter>(result);
     Assert.Equal(builder, tw.Tracer.Builder);
     // Teardown
 }
Exemplo n.º 10
0
 public void ComparerIsCorrect()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var expected = new DelegatingEqualityComparer();
     var sut = new DelegatingRecursionGuard(dummyBuilder, expected);
     // Exercise system
     IEqualityComparer actual = sut.Comparer;
     // Verify outcome
     Assert.Equal(expected, actual);
     // Teardown
 }
 public void AddRaisesGraphChanged()
 {
     // Fixture setup
     var verified = false;
     this.sut.GraphChanged += (s, e) => verified = s != null && e != null;
     // Exercise system
     var dummyItem = new DelegatingSpecimenBuilder();
     this.sut.Add(dummyItem);
     // Verify outcome
     Assert.True(verified);
     // Teardown
 }
 public void TransformReturnsCorrectResultForDefaultRecursionDepth()
 {
     // Fixture setup
     var sut = new OmitOnRecursionBehavior();
     // Exercise system
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var result = sut.Transform(dummyBuilder);
     // Verify outcome
     var rg = Assert.IsAssignableFrom<RecursionGuard>(result);
     Assert.IsAssignableFrom<OmitOnRecursionHandler>(rg.RecursionHandler);
     Assert.Equal(1, rg.RecursionDepth);
     // Teardown
 }
Exemplo n.º 13
0
        public void ConstructWithBuilderAndHandlerAndComparerAndRecursionDepthHasCorrectRecursionDepth()
        {
            // Arrange
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();
            var expected      = 2;
            var sut           = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, expected);
            // Act
            var actual = sut.RecursionDepth;

            // Assert
            Assert.Equal(expected, actual);
        }
        public void TransformReturnsCorrectResultForSpecificRecursionDepth()
        {
            // Arrange
            const int explicitRecursionDepth = 2;
            var       sut = new OmitOnRecursionBehavior(explicitRecursionDepth);
            // Act
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var result       = sut.Transform(dummyBuilder);
            // Assert
            var rg = Assert.IsAssignableFrom <RecursionGuard>(result);

            Assert.IsAssignableFrom <OmitOnRecursionHandler>(rg.RecursionHandler);
            Assert.Equal(explicitRecursionDepth, rg.RecursionDepth);
        }
Exemplo n.º 15
0
        public void TransformReturnsPostprocessorWhichContainsAppropriateSpecification()
        {
            // Arrange
            var sut          = new ReadonlyCollectionPropertiesBehavior();
            var dummyBuilder = new DelegatingSpecimenBuilder();

            // Act
            var result = sut.Transform(dummyBuilder);

            // Assert
            var p = Assert.IsAssignableFrom <Postprocessor>(result);

            Assert.IsAssignableFrom <AndRequestSpecification>(p.Specification);
        }
Exemplo n.º 16
0
        public void InitializeWithEnableAutoPropertiesHasMatchingProperty()
        {
            // Fixture setup
            var dummyFactory         = new DelegatingSpecimenBuilder();
            var dummyPostprocessors  = Enumerable.Empty <ISpecifiedSpecimenCommand <HttpStyleUriParser> >();
            var enableAutoProperties = true;
            var sut = new Composer <HttpStyleUriParser>(dummyFactory, dummyPostprocessors, enableAutoProperties);
            // Exercise system
            var result = sut.EnableAutoProperties;

            // Verify outcome
            Assert.Equal(enableAutoProperties, result);
            // Teardown
        }
Exemplo n.º 17
0
 public void ComposeRetainsHandler()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var expected = new DelegatingRecursionHandler();
     var dummyComparer = new DelegatingEqualityComparer();
     var sut = new RecursionGuard(dummyBuilder, expected, dummyComparer);
     // Exercise system
     var actual = sut.Compose(new ISpecimenBuilder[0]);
     // Verify outcome
     var rg = Assert.IsAssignableFrom<RecursionGuard>(actual);
     Assert.Equal(expected, rg.RecursionHandler);
     // Teardown
 }
 public void TransformReturnsCorrectResultForSpecificRecursionDepth()
 {
     // Fixture setup
     const int explicitRecursionDepth = 2;
     var sut = new NullRecursionBehavior(explicitRecursionDepth);
     // Exercise system
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var result = sut.Transform(dummyBuilder);
     // Verify outcome
     var rg = Assert.IsAssignableFrom<RecursionGuard>(result);
     Assert.IsAssignableFrom<NullRecursionHandler>(rg.RecursionHandler);
     Assert.Equal(explicitRecursionDepth, rg.RecursionDepth);
     // Teardown
 }
Exemplo n.º 19
0
        public void TransformReturnsPostprocessorWhichDecoratesInput()
        {
            // Arrange
            var sut             = new ReadonlyCollectionPropertiesBehavior();
            var expectedBuilder = new DelegatingSpecimenBuilder();

            // Act
            var result = sut.Transform(expectedBuilder);

            // Assert
            var p = Assert.IsAssignableFrom <Postprocessor>(result);

            Assert.IsAssignableFrom <ISpecimenBuilder>(p.Builder);
        }
Exemplo n.º 20
0
        public void SetItemRaisesGraphChanged()
        {
            // Arrange
            var verified = false;

            this.sut.GraphChanged += (s, e) => verified = s != null && e != null;
            // Act
            var dummyIndex = 1;
            var dummyItem  = new DelegatingSpecimenBuilder();

            this.sut[dummyIndex] = dummyItem;
            // Assert
            Assert.True(verified);
        }
        public void ToCustomization_ReturnedCustomizationShouldInsertAtTheBeginning()
        {
            // Arrange
            var builder = new DelegatingSpecimenBuilder();
            var fixture = new Fixture();

            // Act
            var sut = builder.ToCustomization();

            fixture.Customize(sut);

            // Assert
            Assert.Same(builder, fixture.Customizations[0]);
        }
Exemplo n.º 22
0
        public void ComposeSingleItemReturnsCorrectResult()
        {
            // Fixture setup
            var dummy    = new DelegatingSpecimenBuilder();
            var sut      = this.CreateSut(dummy);
            var expected = new DelegatingSpecimenBuilder();
            // Exercise system
            var actual = sut.Compose(new[] { expected });
            // Verify outcome
            var mn = Assert.IsAssignableFrom <T>(actual);

            Assert.Equal(expected, this.GetBuilder(mn));
            // Teardown
        }
Exemplo n.º 23
0
        public void TransformReturnsCorrectResultForDefaultRecursionDepth()
        {
            // Fixture setup
            var sut = new OmitOnRecursionBehavior();
            // Exercise system
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var result       = sut.Transform(dummyBuilder);
            // Verify outcome
            var rg = Assert.IsAssignableFrom <RecursionGuard>(result);

            Assert.IsAssignableFrom <OmitOnRecursionHandler>(rg.RecursionHandler);
            Assert.Equal(1, rg.RecursionDepth);
            // Teardown
        }
        public void TransformReturnsCorrectResultForSpecificRecursionDepth()
        {
            // Fixture setup
            const int explicitRecursionDepth = 2;
            var       sut = new NullRecursionBehavior(explicitRecursionDepth);
            // Exercise system
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var result       = sut.Transform(dummyBuilder);
            // Verify outcome
            var rg = Assert.IsAssignableFrom <RecursionGuard>(result);

            Assert.IsAssignableFrom <NullRecursionHandler>(rg.RecursionHandler);
            Assert.Equal(explicitRecursionDepth, rg.RecursionDepth);
            // Teardown
        }
Exemplo n.º 25
0
        public void ConstructWithBuilderAndHandlerAndComparerHasCorrectComparer()
        {
            // Arrange
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            var expected     = new DelegatingEqualityComparer();

#pragma warning disable 618
            var sut = new RecursionGuard(dummyBuilder, dummyHandler, expected);
#pragma warning restore 618
            // Act
            var actual = sut.Comparer;
            // Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 26
0
        public void ComposeRetainsRecursionDepth()
        {
            // Arrange
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();
            int expected      = 2;
            var sut           = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, expected);
            // Act
            var actual = sut.Compose(new ISpecimenBuilder[0]);
            // Assert
            var rg = Assert.IsAssignableFrom <RecursionGuard>(actual);

            Assert.Equal(expected, rg.RecursionDepth);
        }
Exemplo n.º 27
0
        public void FromSpecimenBuilderFactoryReturnsCorrectResult()
        {
            // Arrange
            var sut     = SpecimenBuilderNodeFactory.CreateComposer <Guid>();
            var builder = new DelegatingSpecimenBuilder();
            // Act
            var actual = sut.FromFactory(builder);
            // Assert
            var expected = new NodeComposer <Guid>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(Guid), builder));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
Exemplo n.º 28
0
        public void ConstructWithBuilderAndHandlerAndComparerAndRecursionDepthHasCorrectRecursionDepth()
        {
            // Fixture setup
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();
            var expected      = 2;
            var sut           = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, expected);
            // Exercise system
            var actual = sut.RecursionDepth;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
        public void SetItemRaisesGraphChanged()
        {
            // Fixture setup
            var verified = false;

            this.sut.GraphChanged += (s, e) => verified = s != null && e != null;
            // Exercise system
            var dummyIndex = 1;
            var dummyItem  = new DelegatingSpecimenBuilder();

            this.sut[dummyIndex] = dummyItem;
            // Verify outcome
            Assert.True(verified);
            // Teardown
        }
Exemplo n.º 30
0
        public void ComposeSingleItemReturnsCorrectResult()
        {
            // Arrange
            var dummyBuilder        = new DelegatingSpecimenBuilder();
            var dummyHandler        = new DelegatingRecursionHandler();
            var dummyComparer       = new DelegatingEqualityComparer();
            int dummyRecursionDepth = 2;
            var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, dummyRecursionDepth);
            // Act
            var expected = new DelegatingSpecimenBuilder();
            var actual   = sut.Compose(new[] { expected });
            // Assert
            var rg = Assert.IsAssignableFrom <RecursionGuard>(actual);

            Assert.Equal(expected, rg.Builder);
        }
Exemplo n.º 31
0
        public void IntializeWithPostprocessorsHasCorrectCommands()
        {
            // Fixture setup
            var dummyFactory     = new DelegatingSpecimenBuilder();
            var expectedCommands = Enumerable.Range(1, 3)
                                   .Select(i => new DelegatingSpecifiedSpecimenCommand <Version>())
                                   .Cast <ISpecifiedSpecimenCommand <Version> >()
                                   .ToList();
            var sut = new Composer <Version>(dummyFactory, expectedCommands, false);
            // Exercise system
            var result = sut.Postprocessors;

            // Verify outcome
            Assert.True(expectedCommands.SequenceEqual(result));
            // Teardown
        }
Exemplo n.º 32
0
        public void ComposeRetainsRecursionDepth()
        {
            // Fixture setup
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();
            int expected      = 2;
            var sut           = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, expected);
            // Exercise system
            var actual = sut.Compose(new ISpecimenBuilder[0]);
            // Verify outcome
            var rg = Assert.IsAssignableFrom <RecursionGuard>(actual);

            Assert.Equal(expected, rg.RecursionDepth);
            // Teardown
        }
Exemplo n.º 33
0
        public void PostprocessorEnumerationIsStable()
        {
            // Fixture setup
            var dummyFactory   = new DelegatingSpecimenBuilder();
            var postprocessors = Enumerable.Range(1, 3)
                                 .Select(i => new DelegatingSpecifiedSpecimenCommand <Uri>())
                                 .Cast <ISpecifiedSpecimenCommand <Uri> >();
            var sut      = new Composer <Uri>(dummyFactory, postprocessors, false);
            var expected = sut.Postprocessors;
            // Exercise system
            var result = sut.Postprocessors;

            // Verify outcome
            Assert.True(expected.SequenceEqual(result));
            // Teardown
        }
Exemplo n.º 34
0
        public void SingleParameterDoWillInvokeMethodWithCorrectParameter(
            int expected)
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder();
            builder.OnCreate = (r, c) => expected;

            var verified = false;
            var mock = new CommandMock<int>();
            mock.OnCommand = x => verified = expected == x;
            // Exercise system
            builder.Do((int i) => mock.Command(i));
            // Verify outcome
            Assert.True(verified, "Mock wasn't verified.");
            // Teardown
        }
Exemplo n.º 35
0
        public void ConstructWithBuilderAndHandlerAndComparerHasCorrectComparer()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            var expected     = new DelegatingEqualityComparer();

#pragma warning disable 618
            var sut = new RecursionGuard(dummyBuilder, dummyHandler, expected);
#pragma warning restore 618
            // Exercise system
            var actual = sut.Comparer;
            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Exemplo n.º 36
0
        public void FromSpecimenBuilderFactoryReturnsCorrectResult()
        {
            // Fixture setup
            var sut     = SpecimenBuilderNodeFactory.CreateComposer <Guid>();
            var builder = new DelegatingSpecimenBuilder();
            // Exercise system
            var actual = sut.FromFactory(builder);
            // Verify outcome
            var expected = new NodeComposer <Guid>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(Guid), builder));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
            // Teardown
        }
Exemplo n.º 37
0
        public void WithFactoryReturnsResultWithCorrectPostprocessors()
        {
            // Fixture setup
            var expectedPostprocessors = Enumerable.Range(1, 3)
                                         .Select(i => new DelegatingSpecifiedSpecimenCommand <Version>())
                                         .Cast <ISpecifiedSpecimenCommand <Version> >()
                                         .ToList();
            var sut = new SutBuilder <Version>().With(expectedPostprocessors).Create();
            // Exercise system
            var dummyFactory = new DelegatingSpecimenBuilder();
            var result       = sut.WithFactory(dummyFactory);

            // Verify outcome
            Assert.True(expectedPostprocessors.SequenceEqual(result.Postprocessors));
            // Teardown
        }
Exemplo n.º 38
0
        public void SingleParameterDoWillInvokeMethodWithCorrectParameter(
            int expected)
        {
            // Arrange
            var builder = new DelegatingSpecimenBuilder();

            builder.OnCreate = (r, c) => expected;

            var verified = false;
            var mock     = new CommandMock <int>();

            mock.OnCommand = x => verified = expected == x;
            // Act
            builder.Do((int i) => mock.Command(i));
            // Assert
            Assert.True(verified, "Mock wasn't verified.");
        }
Exemplo n.º 39
0
        public void ComposeSingleItemReturnsCorrectResult()
        {
            // Fixture setup
            var dummyBuilder        = new DelegatingSpecimenBuilder();
            var dummyHandler        = new DelegatingRecursionHandler();
            var dummyComparer       = new DelegatingEqualityComparer();
            int dummyRecursionDepth = 2;
            var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, dummyRecursionDepth);
            // Exercise system
            var expected = new DelegatingSpecimenBuilder();
            var actual   = sut.Compose(new[] { expected });
            // Verify outcome
            var rg = Assert.IsAssignableFrom <RecursionGuard>(actual);

            Assert.Equal(expected, rg.Builder);
            // Teardown
        }
Exemplo n.º 40
0
        public void SingleParameterDoWillInvokeMethodWithCorrectParameter(
            int expected)
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder();

            builder.OnCreate = (r, c) => expected;

            var verified = false;
            var mock     = new CommandMock <int>();

            mock.OnCommand = x => verified = expected == x;
            // Exercise system
            builder.Do((int i) => mock.Command(i));
            // Verify outcome
            Assert.True(verified, "Mock wasn't verified.");
            // Teardown
        }
        public void ReturnsNoSpecimenWhenEnumGeneratorReturnsNoSpecimen(Type enumType)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request       = new FakeMemberInfo(providedAttribute);
            var enumGenerator = new DelegatingSpecimenBuilder
            {
                OnCreate = (_, _) => new NoSpecimen()
            };
            var sut = new EnumDataTypeAttributeRelay(enumGenerator);

            // Act
            var actual = sut.Create(request, null);

            // Assert
            Assert.IsType <NoSpecimen>(actual);
        }
Exemplo n.º 42
0
        public void CreateReturnsCorrectResult()
        {
            // Arrange
            var request  = new object();
            var context  = new DelegatingSpecimenContext();
            var expected = new object();
            var builder  = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) => r == request && c == context ?
                           expected :
                           new NoSpecimen()
            };
            var sut = new NodeComposer <object>(builder);
            // Act
            var actual = sut.Create(request, context);

            // Assert
            Assert.Equal(expected, actual);
        }
        public void CreateAnonymousOnSpecimenBuilderComposerReturnsCorrectResult()
        {
            // Fixture setup
            var expectedResult = new DateTime(2010, 5, 31, 14, 52, 19);
            var specimenBuilder = new DelegatingSpecimenBuilder();
            specimenBuilder.OnCreate = (r, c) =>
            {
                Assert.NotNull(c);
                Assert.Equal(new SeededRequest(typeof(DateTime), default(DateTime)), r);
                return expectedResult;
            };

            ISpecimenBuilder composer = new DelegatingComposer { OnCreate = specimenBuilder.OnCreate };
            // Exercise system
            var result = composer.Create<DateTime>();
            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
        public void ShouldDelegateCreateRequestToInnerBuilder()
        {
            // Arrange
            var request        = new object();
            var context        = new DelegatingSpecimenContext();
            var expectedResult = new object();

            var builder = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, ctx) => r == request ? expectedResult : new NoSpecimen()
            };

            var sut = new DataAnnotationsSupportNode(builder);
            // Act
            var actualResult = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
        public void FromBuilderFactoryReturnsCorrectResult()
        {
            // Fixture setup
            var expectedFactory   = new DelegatingSpecimenBuilder();
            var expectedComposers = Enumerable.Range(1, 3).Select(i => new DelegatingComposer <Version>()).ToArray();
            var initialComposers  = (from c in expectedComposers
                                     select new DelegatingComposer <Version>
            {
                OnFromBuilder = f => f == expectedFactory ? c : new DelegatingComposer <Version>()
            }).ToArray();
            var sut = new CompositeComposer <Version>(initialComposers);
            // Exercise system
            var result = sut.FromFactory(expectedFactory);
            // Verify outcome
            var composite = Assert.IsAssignableFrom <CompositePostprocessComposer <Version> >(result);

            Assert.True(expectedComposers.SequenceEqual(composite.Composers));
            // Teardown
        }
Exemplo n.º 46
0
        public void CreateWillTriggerHandlingOnRecursiveRequests()
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder();

            builder.OnCreate = (r, c) => c.Resolve(r);
            var  sut = new DelegatingRecursionGuard(builder);
            bool handlingTriggered = false;

            sut.OnHandleRecursiveRequest = obj => handlingTriggered = true;
            var container = new DelegatingSpecimenContext();

            container.OnResolve = (r) => sut.Create(r, container);

            // Exercise system
            sut.Create(Guid.NewGuid(), container);

            // Verify outcome
            Assert.True(handlingTriggered);
        }
Exemplo n.º 47
0
 public void ComposeReturnsCorrectResult()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var dummyHandler = new DelegatingRecursionHandler();
     var dummyComparer = new DelegatingEqualityComparer();
     var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer);
     // Exercise system
     var expectedBuilders = new[]
     {
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder()
     };
     var actual = sut.Compose(expectedBuilders);
     // Verify outcome
     var rg = Assert.IsAssignableFrom<RecursionGuard>(actual);
     var composite = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(rg.Builder);
     Assert.True(expectedBuilders.SequenceEqual(composite));
     // Teardown
 }
Exemplo n.º 48
0
 public void BuildAbstractTypeUsingBuilderIsPossibleObsolete()
 {
     // Fixture setup
     var sut = new Fixture();
     var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => new ConcreteType() };
     // Exercise system
     var result = sut.Build<AbstractType>().FromFactory(builder).CreateAnonymous();
     // Verify outcome
     Assert.IsAssignableFrom<ConcreteType>(result);
     // Teardown
 }
Exemplo n.º 49
0
 public void CustomizationsIsStable()
 {
     // Fixture setup
     var sut = new Fixture();
     var builder = new DelegatingSpecimenBuilder();
     // Exercise system
     sut.Customizations.Add(builder);
     // Verify outcome
     Assert.Contains(builder, sut.Customizations);
     // Teardown
 }
Exemplo n.º 50
0
 public void InitializedWithEngineSutHasCorrectEngine()
 {
     // Fixture setup
     var expectedEngine = new DelegatingSpecimenBuilder();
     var dummyMany = new MultipleRelay();
     var sut = new Fixture(expectedEngine, dummyMany);
     // Exercise system
     var result = sut.Engine;
     // Verify outcome
     Assert.Equal(expectedEngine, result);
     // Teardown
 }
Exemplo n.º 51
0
        public void BuildAndComposeWillCarryBehaviorsForward()
        {
            // Fixture setup
            var sut = new Fixture();
            sut.Behaviors.Clear();

            var expectedBuilder = new DelegatingSpecimenBuilder();
            sut.Behaviors.Add(new DelegatingSpecimenBuilderTransformation { OnTransform = b => new TaggedNode(1, b) });
            // Exercise system
            var result = sut.Build<object>();
            // Verify outcome
            var comparer = new TaggedNodeComparer(new TrueComparer<ISpecimenBuilder>());
            var composite = Assert.IsAssignableFrom<CompositeNodeComposer<object>>(result);
            Assert.Equal(new TaggedNode(1), composite.Node.First(), comparer);
            // Teardown
        }
Exemplo n.º 52
0
 public void DoubleParameterDoWithNullActionThrows()
 {
     var builder = new DelegatingSpecimenBuilder();
     Assert.Throws<ArgumentNullException>(() =>
         builder.Do<double, decimal>(null));
 }
Exemplo n.º 53
0
 public void InitializedWithManySutHasCorrectRepeatCount()
 {
     // Fixture setup
     var expectedRepeatCount = 187;
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var many = new MultipleRelay { Count = expectedRepeatCount };
     var sut = new Fixture(dummyBuilder, many);
     // Exercise system
     var result = sut.RepeatCount;
     // Verify outcome
     Assert.Equal(expectedRepeatCount, result);
     // Teardown
 }
Exemplo n.º 54
0
 public void SettingRepeatCountWillCorrectlyUpdateMany()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var many = new MultipleRelay();
     var sut = new Fixture(dummyBuilder, many);
     // Exercise system
     sut.RepeatCount = 26;
     // Verify outcome
     Assert.Equal(sut.RepeatCount, many.Count);
     // Teardown
 }
Exemplo n.º 55
0
 public void ResidueCollectorsIsStable()
 {
     // Fixture setup
     var sut = new Fixture();
     var builder = new DelegatingSpecimenBuilder();
     // Exercise system
     sut.ResidueCollectors.Add(builder);
     // Verify outcome
     Assert.Contains(builder, sut.ResidueCollectors);
     // Teardown
 }
Exemplo n.º 56
0
        public void BuildAndCreateOnUnregisteredAbstractionWillInvokeResidueCollectorWithCorrectType()
        {
            // Fixture setup
            var residueCollector = new DelegatingSpecimenBuilder();
            residueCollector.OnCreate = (r, c) =>
            {
                Assert.Equal(typeof(AbstractType), r);
                return new ConcreteType();
            };

            var sut = new Fixture();
            sut.ResidueCollectors.Add(residueCollector);
            // Exercise system
            sut.Build<PropertyHolder<AbstractType>>().Create();
            // Verify outcome (done by callback)
            // Teardown
        }
 public void ComposeWithNoBehaviorsReturnsCorrectResult()
 {
     // Fixture setup
     var expectedBuilder = new DelegatingSpecimenBuilder();
     var composer = new DelegatingComposer<object> { OnCompose = () => expectedBuilder };
     var sut = new BehaviorPostprocessComposer<object>(composer);
     // Exercise system
     var result = sut.Compose();
     // Verify outcome
     Assert.Equal(expectedBuilder, result);
     // Teardown
 }
        public void ComposeReturnsCorrectResult()
        {
            // Fixture setup
            var builder1 = new DelegatingSpecimenBuilder();
            var builder2 = new DelegatingSpecimenBuilder();
            var builder3 = new DelegatingSpecimenBuilder();

            var composer = new DelegatingComposer<object> { OnCompose = () => builder1 };
            var behaviors = new[]
                {
                    new DelegatingSpecimenBuilderTransformation { OnTransform = b => b == builder1 ? builder2 : new DelegatingSpecimenBuilder() },
                    new DelegatingSpecimenBuilderTransformation { OnTransform = b => b == builder2 ? builder3 : new DelegatingSpecimenBuilder() }
                };

            var sut = new BehaviorPostprocessComposer<object>(composer, behaviors);
            // Exercise system
            var result = sut.Compose();
            // Verify outcome
            Assert.Equal(builder3, result);
            // Teardown
        }
Exemplo n.º 59
0
        public void BuildAndCreateWillInvokeResidueCollector()
        {
            // Fixture setup
            bool resolveWasInvoked = false;

            var residueCollector = new DelegatingSpecimenBuilder();
            residueCollector.OnCreate = (r, c) =>
            {
                resolveWasInvoked = true;
                return new ConcreteType();
            };

            var sut = new Fixture();
            sut.ResidueCollectors.Add(residueCollector);
            // Exercise system
            sut.Build<PropertyHolder<AbstractType>>().Create();
            // Verify outcome
            Assert.True(resolveWasInvoked, "Resolve");
            // Teardown
        }
Exemplo n.º 60
0
        public void BuildAndCreateOnUnregisteredAbstractionWillReturnInstanceFromResidueCollector()
        {
            // Fixture setup
            var expectedValue = new ConcreteType();

            var residueCollector = new DelegatingSpecimenBuilder();
            residueCollector.OnCreate = (r, c) => expectedValue;

            var sut = new Fixture();
            sut.ResidueCollectors.Add(residueCollector);
            // Exercise system
            var result = sut.Build<PropertyHolder<AbstractType>>().Create().Property;
            // Verify outcome
            Assert.Equal<AbstractType>(expectedValue, result);
            // Teardown
        }