コード例 #1
0
        public void CreateOnMultipleThreadsConcurrentlyWorks()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, ctx) => ctx.Resolve(r)
            };
            var dummyHandler = new DelegatingRecursionHandler();
            var sut          = new RecursionGuard(dummyBuilder, dummyHandler);
            var dummyContext = new DelegatingSpecimenContext()
            {
                OnResolve = (r) => 99
            };

            // Exercise system
            int[] specimens = Enumerable.Range(0, 1000)
                              .AsParallel()
                              .WithDegreeOfParallelism(8)
                              .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
                              .Select(x => (int)sut.Create(typeof(int), dummyContext))
                              .ToArray();
            // Verify outcome
            Assert.Equal(1000, specimens.Length);
            Assert.True(specimens.All(s => s == 99));
            // Teardown
        }
コード例 #2
0
        public void ConstructWithNullBuilderAndRecursionHandlerThrows()
        {
            // Fixture setup
            var dummyHandler = new DelegatingRecursionHandler();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(
                () => new RecursionGuard(null, dummyHandler));
            // Teardown
        }
コード例 #3
0
        public void ConstructWithBuilderAndHandlerSetsRecursionDepthCorrectly()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            // Exercise system
            var sut = new RecursionGuard(dummyBuilder, dummyHandler);

            // Verify outcome
            Assert.Equal(1, sut.RecursionDepth);
        }
コード例 #4
0
        public void ConstructWithBuilderAndHandlerAndNullComparerThrows()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(
                () => new RecursionGuard(dummyBuilder, dummyHandler, null));
            // Teardown
        }
コード例 #5
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
        }
コード例 #6
0
        public void ConstructWithBuilderAndRecursionHandlerHasCorrectComparer()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            var sut          = new RecursionGuard(dummyBuilder, dummyHandler);
            // Exercise system
            var actual = sut.Comparer;

            // Verify outcome
            Assert.Equal(EqualityComparer <object> .Default, actual);
            // Teardown
        }
コード例 #7
0
        public void ConstructWithBuilderAndRecursionHandlerHasCorrectBuilder()
        {
            // Fixture setup
            var expected     = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            var sut          = new RecursionGuard(expected, dummyHandler);
            // Exercise system
            var actual = sut.Builder;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
コード例 #8
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
 }
コード例 #9
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
        }
コード例 #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
        }
コード例 #11
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
        }
コード例 #12
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
        }
コード例 #13
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
 }
コード例 #14
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
        }
コード例 #15
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
        }
コード例 #16
0
 public void CreateOnMultipleThreadsConcurrentlyWorks()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder
     {
         OnCreate = (r, ctx) => ctx.Resolve(r)
     };
     var dummyHandler = new DelegatingRecursionHandler();
     var sut = new RecursionGuard(dummyBuilder, dummyHandler);
     var dummyContext = new DelegatingSpecimenContext()
     {
         OnResolve = (r) => 99
     };
     // Exercise system
     int[] specimens = Enumerable.Range(0, 1000)
         .AsParallel()
             .WithDegreeOfParallelism(8)
             .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
         .Select(x => (int)sut.Create(typeof(int), dummyContext))
         .ToArray();
     // Verify outcome
     Assert.Equal(1000, specimens.Length);
     Assert.True(specimens.All(s => s == 99));
     // 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 ConstructWithNullBuilderAndRecursionHandlerThrows()
 {
     // Fixture setup
     var dummyHandler = new DelegatingRecursionHandler();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(
         () => new RecursionGuard(null, dummyHandler));
     // Teardown
 }
コード例 #19
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
 }
コード例 #20
0
 public void ConstructWithBuilderAndHandlerAndNullComparerAndRecursionDepthThrows()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var dummyHandler = new DelegatingRecursionHandler();
     var dummyRecursionDepth = 2;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(
         () => new RecursionGuard(dummyBuilder, dummyHandler, null, dummyRecursionDepth));
     // Teardown
 }
コード例 #21
0
        public void ConstructWithBuilderSetsRecursionDepthCorrectly()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var dummyHandler = new DelegatingRecursionHandler();
            // Exercise system
#pragma warning disable 618
            var sut = new RecursionGuard(dummyBuilder);
#pragma warning restore 618
            // Verify outcome
            Assert.Equal(1, sut.RecursionDepth);
        }
コード例 #22
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
        }
コード例 #23
0
 public void ConstructWithBuilderAndHandlerAndRecursionDepthSetsRecursionDepthCorrectly()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var dummyHandler = new DelegatingRecursionHandler();
     const int explicitRecursionDepth = 2;
     // Exercise system
     var sut = new RecursionGuard(dummyBuilder, dummyHandler, explicitRecursionDepth);
     // Verify outcome
     Assert.Equal(explicitRecursionDepth, sut.RecursionDepth);
 }
コード例 #24
0
 public void ConstructWithBuilderAndRecursionHandlerHasCorrectComparer()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var dummyHandler = new DelegatingRecursionHandler();
     var sut = new RecursionGuard(dummyBuilder, dummyHandler);
     // Exercise system
     var actual = sut.Comparer;
     // Verify outcome
     Assert.Equal(EqualityComparer<object>.Default, actual);
     // Teardown
 }
コード例 #25
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
 }
コード例 #26
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
        }
コード例 #27
0
 public void ConstructWithBuilderAndRecursionHandlerHasCorrectBuilder()
 {
     // Fixture setup
     var expected = new DelegatingSpecimenBuilder();
     var dummyHandler = new DelegatingRecursionHandler();
     var sut = new RecursionGuard(expected, dummyHandler);
     // Exercise system
     var actual = sut.Builder;
     // Verify outcome
     Assert.Equal(expected, actual);
     // Teardown
 }