public void CreateReturnsResultFromDecoratedBuilder()
        {
            // Fixture setup
            var request = new object();
            var ctx = new DelegatingSpecimenContext();
            var expectedResult = new object();

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

            var sut = new DisposableTracker(builder);
            // Exercise system
            var result = sut.Create(request, ctx);
            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
 public void DecoratedDisposableResultIsOnlyAddedToDisposablesOnce()
 {
     // Fixture setup
     var disposable = new DisposableSpy();
     var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => disposable };
     var sut = new DisposableTracker(builder);
     // Exercise system
     var dummyRequest = new object();
     var dummyContext = new DelegatingSpecimenContext();
     sut.Create(dummyRequest, dummyContext);
     sut.Create(dummyRequest, dummyContext);
     // Verify outcome
     Assert.Equal(1, sut.Disposables.Count(d => d == disposable));
     // Teardown
 }
        public void DisposeRemovesAllDisposables()
        {
            // Fixture setup
            var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => new DisposableSpy() };
            var sut = new DisposableTracker(builder);

            var dummyRequest = new object();
            var dummyContext = new DelegatingSpecimenContext();

            sut.Create(dummyRequest, dummyContext);
            sut.Create(dummyRequest, dummyContext);
            sut.Create(dummyRequest, dummyContext);
            // Exercise system
            sut.Dispose();
            // Verify outcome
            Assert.Empty(sut.Disposables);
            // Teardown
        }
        public void DisposeDisposesAllDisposables()
        {
            // Fixture setup
            var disposables = Enumerable.Repeat<Func<DisposableSpy>>(() => new DisposableSpy(), 3).Select(f => f()).ToList();
            var q = new Queue<DisposableSpy>(disposables);
            var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => q.Dequeue() };

            var sut = new DisposableTracker(builder);

            var dummyRequest = new object();
            var dummyContext = new DelegatingSpecimenContext();
            disposables.ForEach(d => sut.Create(dummyRequest, dummyContext));
            // Exercise system
            sut.Dispose();
            // Verify outcome
            Assert.True(sut.Disposables.Cast<DisposableSpy>().All(ds => ds.Disposed));
            // Teardown
        }