Esempio n. 1
0
        public void ConstructorWithRecursionDepthLowerThanOneThrows(int recursionDepth)
        {
            // Arrange
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();

            // Act & assert
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, recursionDepth));
        }
Esempio n. 2
0
        public void ConstructWithBuilderAndNullHandlerAndComparerAndRecursionDepthThrows()
        {
            // Arrange
            var dummyBuilder        = new DelegatingSpecimenBuilder();
            var dummyComparer       = new DelegatingEqualityComparer();
            var dummyRecursionDepth = 2;

            // Act & assert
            Assert.Throws <ArgumentNullException>(
                () => new RecursionGuard(dummyBuilder, null, dummyComparer, dummyRecursionDepth));
        }
Esempio n. 3
0
        public void ConstructorWithRecursionDepthLowerThanOneThrows(int recursionDepth)
        {
            // Fixture setup
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, recursionDepth));
            // Teardown
        }
Esempio n. 4
0
        public void ComparerIsCorrect()
        {
            // Arrange
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var expected     = new DelegatingEqualityComparer();
            var sut          = new DelegatingRecursionGuard(dummyBuilder, expected);
            // Act
            IEqualityComparer actual = sut.Comparer;

            // Assert
            Assert.Equal(expected, actual);
        }
Esempio n. 5
0
        public void ConstructWithBuilderAndNullHandlerAndComparerAndRecursionDepthThrows()
        {
            // Fixture setup
            var dummyBuilder        = new DelegatingSpecimenBuilder();
            var dummyComparer       = new DelegatingEqualityComparer();
            var dummyRecursionDepth = 2;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(
                () => new RecursionGuard(dummyBuilder, null, dummyComparer, dummyRecursionDepth));
            // Teardown
        }
Esempio n. 6
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
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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
        }
Esempio n. 11
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);
        }
Esempio n. 12
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
        }
Esempio n. 13
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
        }
Esempio n. 14
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
        }
Esempio n. 15
0
        public void ComposeReturnsCorrectResult()
        {
            // Arrange
            var       dummyBuilder        = new DelegatingSpecimenBuilder();
            var       dummyHandler        = new DelegatingRecursionHandler();
            var       dummyComparer       = new DelegatingEqualityComparer();
            const int dummyRecursionDepth = 2;
            var       sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, dummyRecursionDepth);
            // Act
            var expectedBuilders = new[]
            {
                new DelegatingSpecimenBuilder(),
                new DelegatingSpecimenBuilder(),
                new DelegatingSpecimenBuilder()
            };
            var actual = sut.Compose(expectedBuilders);
            // Assert
            var rg        = Assert.IsAssignableFrom <RecursionGuard>(actual);
            var composite = Assert.IsAssignableFrom <CompositeSpecimenBuilder>(rg.Builder);

            Assert.True(expectedBuilders.SequenceEqual(composite));
        }
Esempio n. 16
0
        public void CreateWillUseEqualityComparer()
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder();

            builder.OnCreate = (r, c) => c.Resolve(r);
            bool comparerUsed = false;
            var  comparer     = new DelegatingEqualityComparer {
                OnEquals = (x, y) => comparerUsed = true
            };
            var sut = new DelegatingRecursionGuard(builder, comparer);

            sut.OnHandleRecursiveRequest = (obj) => { return(null); };
            var container = new DelegatingSpecimenContext();

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

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

            // Verify outcome
            Assert.True(comparerUsed);
        }
Esempio n. 17
0
        public void CreateReturnsResultFromInjectedHandlerWhenRequestIsMatched()
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder()
            {
                OnCreate = (r, ctx) => ctx.Resolve(r)
            };

            var request     = new object();
            var expected    = new object();
            var handlerStub = new DelegatingRecursionHandler
            {
                OnHandleRecursiveRequest = (r, rs) =>
                {
                    Assert.Equal(request, r);
                    Assert.NotNull(rs);
                    return(expected);
                }
            };

            var comparer = new DelegatingEqualityComparer
            {
                OnEquals = (x, y) => true
            };

            var sut = new RecursionGuard(builder, handlerStub, comparer, 1);

            var context = new DelegatingSpecimenContext();

            context.OnResolve = r => sut.Create(r, context);
            // Exercise system
            var actual = sut.Create(request, context);

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }