public void SutIsISpecimenBuilderNode()
 {
     // Fixture setup
     // Exercise system
     var sut = new TerminatingWithPathSpecimenBuilder(new DelegatingTracingBuilder());
     // Verify outcome
     Assert.IsAssignableFrom<ISpecimenBuilderNode>(sut);
     // Teardown
 }
 public void TracerIsCorrect()
 {
     // Fixture setup
     var expected = new DelegatingTracingBuilder();
     // Exercise system
     var sut = new TerminatingWithPathSpecimenBuilder(expected);
     // Verify outcome
     Assert.Same(expected, sut.Tracer);
     // Teardown
 }
 public void SutYieldsCorrectSequence()
 {
     // Fixture setup
     var expected = new DelegatingSpecimenBuilder();
     var tracer = new DelegatingTracingBuilder(expected);
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     // Exercise system
     // Verify outcome
     Assert.Equal(expected, sut.Single());
     Assert.Equal(expected, sut.Cast<object>().Single());
     // Teardown
 }
 public void ComposeReturnsCorrectResult()
 {
     // Fixture setup
     var tracer = new DelegatingTracingBuilder();
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     // Exercise system
     var expectedBuilders = new[]
     {
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder()
     };
     var actual = sut.Compose(expectedBuilders);
     // Verify outcome
     var tw = Assert.IsAssignableFrom<TerminatingWithPathSpecimenBuilder>(actual);
     var composite = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(tw.Tracer.Builder);
     Assert.True(expectedBuilders.SequenceEqual(composite));
     // Teardown
 }
 public void ComposeSingleItemReturnsCorrectResult()
 {
     // Fixture setup
     var tracer = new DelegatingTracingBuilder();
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     // Exercise system
     var expected = new DelegatingSpecimenBuilder();
     var actual = sut.Compose(new[] { expected });
     // Verify outcome
     var tw = Assert.IsAssignableFrom<TerminatingWithPathSpecimenBuilder>(actual);
     Assert.Equal(expected, tw.Tracer.Builder);
     // Teardown
 }
 public void CreateOnMultipleThreadsConcurrentlyWorks()
 {
     // Fixture setup
     var tracer = new DelegatingTracingBuilder(new DelegatingSpecimenBuilder
     {
         OnCreate = (r, c) => 99
     });
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     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
 }
        public void CreateThrowsWithAutoMockingHintOnInterfaceOrAbcRequest(
            object request,
            string requestType)
        {
            var tracer =
                new DelegatingTracingBuilder(
                    new DelegatingSpecimenBuilder
                    {
                        OnCreate = (r, c) => new NoSpecimen(request)
                    });
            var sut = new TerminatingWithPathSpecimenBuilder(tracer);

            var context = new SpecimenContext(sut);
            var e = Assert.Throws<ObjectCreationException>(
                () => sut.Create(request, context));

            Assert.Contains(
                requestType,
                e.Message,
                StringComparison.CurrentCultureIgnoreCase);
            Assert.Contains(
                "auto-mocking",
                e.Message,
                StringComparison.CurrentCultureIgnoreCase);
            Assert.Contains(
                "request path",
                e.Message,
                StringComparison.CurrentCultureIgnoreCase);
        }
        public void SpecimenRequestsAreEmptyAfterThrowing()
        {
            // Fixture setup
            var requests = new[] {new object(), new object(), new object() };
            var requestQueue = new Queue<object>(requests);
            var firstRequest = requestQueue.Dequeue();
            var tracer = new DelegatingTracingBuilder(new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) => requestQueue.Count > 0
                    ? c.Resolve(requestQueue.Dequeue())
                    : new NoSpecimen()
            });
            var sut = new TerminatingWithPathSpecimenBuilder(tracer);
            var container = new SpecimenContext(sut);

            // Exercise system and verify outcome
            Assert.Throws<ObjectCreationException>(() =>
                sut.Create(firstRequest, container));

            Assert.Empty(sut.SpecimenRequests);
        }
        public void CreateThrowsWhenNoSpecimenIsReturnedFromTheDecoratedGraph()
        {
            // Fixture setup
            var requests = new[] {new object(), new object(), new object()};
            var tracer = new DelegatingTracingBuilder(new DelegatingSpecimenBuilder
            {
                // Returns NoSpecimen only on the last specimen request
                OnCreate = (r, c) => (r == requests[2]) ? new NoSpecimen() : new object(),
            });

            var sut = new TerminatingWithPathSpecimenBuilder(tracer);
            var container = new SpecimenContext(sut);
            // Exercise system and verify outcome
            Assert.DoesNotThrow(() => sut.Create(requests[0], container));
            Assert.DoesNotThrow(() => sut.Create(requests[1], container));
            Assert.Throws<ObjectCreationException>(() => sut.Create(requests[2], container));
            // Teardown
        }
 public void SpecimenRequestsAreEmptyWhenAllThatWereRequestedAreCreated()
 {
     // Fixture setup
     var tracer = new DelegatingTracingBuilder();
     var specimens = new[] { new object(), new object(), new object() };
     var requestEvents = specimens.Select(
         (o, i) => new RequestTraceEventArgs(o, i)).ToList();
     var createdEvents = specimens.Reverse().Select(
         (o, i) => new SpecimenCreatedEventArgs(o, null, i)).ToList();
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     // Exercise system
     requestEvents.ForEach(tracer.RaiseSpecimenRequested);
     createdEvents.ForEach(tracer.RaiseSpecimenCreated);
     // Verify outcome
     Assert.Empty(sut.SpecimenRequests);
     // Teardown
 }
 public void SpecimenRequestsRaisedFromTracerAreRecordedCorrectly()
 {
     // Fixture setup
     var tracer = new DelegatingTracingBuilder();
     var specimens = new[] { new object(), new object(), new object() };
     var requestEvents = specimens.Select((o, i) => new RequestTraceEventArgs(o, i)).ToList();
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     // Exercise system
     requestEvents.ForEach(tracer.RaiseSpecimenRequested);
     // Verify outcome
     Assert.True(specimens.SequenceEqual(sut.SpecimenRequests));
     // Teardown
 }
 public void SpecimenRequestsWillInitiallyBeEmpty()
 {
     // Fixture setup
     var tracer = new DelegatingTracingBuilder();
     var sut = new TerminatingWithPathSpecimenBuilder(tracer);
     // Exercise system and verify outcome
     Assert.Empty(sut.SpecimenRequests);
     // Teardown
 }
        public void CreateWillInvokeDecoratedBuilderWithCorrectParameters()
        {
            // Fixture setup
            var expectedRequest = new object();
            var expectedContainer = new DelegatingSpecimenContext();

            var verified = false;
            var mockBuilder = new TracingBuilder(new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) => verified = expectedRequest == r && expectedContainer == c
            });

            var sut = new TerminatingWithPathSpecimenBuilder(mockBuilder);
            // Exercise system
            sut.Create(expectedRequest, expectedContainer);
            // Verify outcome
            Assert.True(verified, "Mock verified");
            // Teardown
        }
        public void CreateWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedSpecimen = new object();
            var stubBuilder = new TracingBuilder(new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) => expectedSpecimen
            });

            var sut = new TerminatingWithPathSpecimenBuilder(stubBuilder);
            // Exercise system
            var dummyRequest = new object();
            var dummyContainer = new DelegatingSpecimenContext();
            var result = sut.Create(dummyRequest, dummyContainer);
            // Verify outcome
            Assert.Equal(expectedSpecimen, result);
            // Teardown
        }