Пример #1
0
        public void ConstructWithBuilderAndNullHandlerAndComparerThrows()
        {
            // Fixture setup
            var dummyBuilder  = new DelegatingSpecimenBuilder();
            var dummyComparer = new DelegatingEqualityComparer();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(
                () => new RecursionGuard(dummyBuilder, null, dummyComparer));
            // Teardown
        }
Пример #2
0
        public void ConstructWithNullBuilderAndHandlerAndComparerAndRecursionDepthThrows()
        {
            // Fixture setup
            var dummyHandler        = new DelegatingRecursionHandler();
            var dummyComparer       = new DelegatingEqualityComparer();
            var dummyRecursionDepth = 2;

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(
                () => new RecursionGuard(null, dummyHandler, dummyComparer, dummyRecursionDepth));
            // Teardown
        }
Пример #3
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
 }
Пример #4
0
        public void ConstructorWithRecusionDepthLowerThanOneThrows(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
        }
Пример #5
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
        }
Пример #6
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
 }
Пример #7
0
        public void ConstructWithBuilderAndHandlerAndComparerHasCorrectComparer()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            var expected     = new DelegatingEqualityComparer();
            var sut          = new RecursionGuard(dummyBuilder, dummyHandler, expected);
            // Exercise system
            var actual = sut.Comparer;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Пример #8
0
        public void ComposeRetainsComparer()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            var expected     = new DelegatingEqualityComparer();
            var sut          = new RecursionGuard(dummyBuilder, dummyHandler, expected);
            // Exercise system
            var actual = sut.Compose(new ISpecimenBuilder[0]);
            // Verify outcome
            var rg = Assert.IsAssignableFrom <RecursionGuard>(actual);

            Assert.Equal(expected, rg.Comparer);
            // Teardown
        }
Пример #9
0
        public void ConstructWithBuilderAndHandlerAndComparerHasCorrectBuilder()
        {
            // Fixture setup
            var expected      = new DelegatingSpecimenBuilder();
            var dummyHandler  = new DelegatingRecursionHandler();
            var dummyComparer = new DelegatingEqualityComparer();

#pragma warning disable 618
            var sut = new RecursionGuard(expected, dummyHandler, dummyComparer);
#pragma warning restore 618
            // Exercise system
            var actual = sut.Builder;
            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Пример #10
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
        }
Пример #11
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
 }
Пример #12
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
        }
Пример #13
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);
        }
Пример #14
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
        }
Пример #15
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);
        }
Пример #16
0
 public void ConstructorWithRecusionDepthLowerThanOneThrows(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
 }
Пример #17
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
 }
Пример #18
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
 }
Пример #19
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
        }
Пример #20
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
        }
Пример #21
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
 }
Пример #22
0
 public void ConstructWithNullBuilderAndHandlerAndComparerThrows()
 {
     // Fixture setup
     var dummyHandler = new DelegatingRecursionHandler();
     var dummyComparer = new DelegatingEqualityComparer();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(
         () => new RecursionGuard(null, dummyHandler, dummyComparer));
     // Teardown
 }