/// <summary>
        /// Decorates the supplied builder with a <see cref="DisposableTracker"/>.
        /// </summary>
        /// <param name="builder">The builder to transform.</param>
        /// <returns>
        /// A new <see cref="DisposableTracker"/> that decorates <paramref name="builder"/>.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The returned <see cref="DisposableTracker"/> is also added to the
        /// <see cref="Trackers"/> property.
        /// </para>
        /// </remarks>
        public ISpecimenBuilder Transform(ISpecimenBuilder builder)
        {
            var tracker = new DisposableTracker(builder);

            this.trackers.Add(tracker);
            return(tracker);
        }
Пример #2
0
        /// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public virtual ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            var composedBuilder = CompositeSpecimenBuilder.ComposeIfMultiple(builders);
            var d = new DisposableTracker(composedBuilder);

            this.disposables.Add(d);
            return(d);
        }
 public void SutIsSpecimenBuilder()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     // Exercise system
     var sut = new DisposableTracker(dummyBuilder);
     // Verify outcome
     Assert.IsAssignableFrom<ISpecimenBuilder>(sut);
     // Teardown
 }
 public void DisposablesIsInstance()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var sut = new DisposableTracker(dummyBuilder);
     // Exercise system
     IEnumerable<IDisposable> result = sut.Disposables;
     // Verify outcome
     Assert.NotNull(result);
     // Teardown
 }
 public void BuilderIsCorrect()
 {
     // Fixture setup
     var expectedBuilder = new DelegatingSpecimenBuilder();
     var sut = new DisposableTracker(expectedBuilder);
     // Exercise system
     ISpecimenBuilder result = sut.Builder;
     // Verify outcome
     Assert.Equal(expectedBuilder, result);
     // Teardown
 }
 public void SutYieldsInjectedBuilder()
 {
     // Fixture setup
     var expected = new DelegatingSpecimenBuilder();
     var sut = new DisposableTracker(expected);
     // Exercise system
     // Verify outcome
     Assert.Equal(expected, sut.Single());
     Assert.Equal(expected, ((System.Collections.IEnumerable)sut).Cast<object>().Single());
     // Teardown
 }
 public void DecoratedDisposableResultIsAddedToDisposables()
 {
     // 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);
     // Verify outcome
     Assert.Contains(disposable, sut.Disposables);
     // Teardown
 }
        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 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
        }
Пример #11
0
 public void ComposeReturnsCorrectResult()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var sut = new DisposableTracker(dummyBuilder);
     // Exercise system
     var expectedBuilders = new[]
     {
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder()
     };
     var actual = sut.Compose(expectedBuilders);
     // Verify outcome
     var dt = Assert.IsAssignableFrom<DisposableTracker>(actual);
     var composite = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(dt.Builder);
     Assert.True(expectedBuilders.SequenceEqual(composite));
     // Teardown
 }
Пример #12
0
 public void ComposeAddsReturnedObjectToDisposables()
 {
     // Fixture setup
     var dummy = new DelegatingSpecimenBuilder();
     var sut = new DisposableTracker(dummy);
     // Exercise system
     var dummies = new ISpecimenBuilder[0];
     var actual = sut.Compose(dummies);
     // Verify outcome
     Assert.True(
         sut.Disposables.Any(actual.Equals),
         "Returned value not added to disposables.");
     // Teardown
 }
Пример #13
0
 public void ComposeSingleItemReturnsCorrectResult()
 {
     // Fixture setup
     var dummyBuilder = new DelegatingSpecimenBuilder();
     var sut = new DisposableTracker(dummyBuilder);
     // Exercise system
     var expected = new DelegatingSpecimenBuilder();
     var actual = sut.Compose(new[] { expected });
     // Verify outcome
     var dt = Assert.IsAssignableFrom<DisposableTracker>(actual);
     Assert.Equal(expected, dt.Builder);
     // Teardown
 }
Пример #14
0
 /// <summary>Composes the supplied builders.</summary>
 /// <param name="builders">The builders to compose.</param>
 /// <returns>
 /// A new <see cref="ISpecimenBuilderNode" /> instance containing
 /// <paramref name="builders" /> as child nodes.
 /// </returns>
 public virtual ISpecimenBuilderNode Compose(IEnumerable<ISpecimenBuilder> builders)
 {
     var composedBuilder = CompositeSpecimenBuilder.ComposeIfMultiple(builders);
     var d = new DisposableTracker(composedBuilder);
     this.disposables.Add(d);
     return d;
 }
 /// <summary>
 /// Decorates the supplied builder with a <see cref="DisposableTracker"/>.
 /// </summary>
 /// <param name="builder">The builder to transform.</param>
 /// <returns>
 /// A new <see cref="DisposableTracker"/> that decorates <paramref name="builder"/>.
 /// </returns>
 /// <remarks>
 /// <para>
 /// The returned <see cref="DisposableTracker"/> is also added to the
 /// <see cref="Trackers"/> property.
 /// </para>
 /// </remarks>
 public ISpecimenBuilder Transform(ISpecimenBuilder builder)
 {
     var tracker = new DisposableTracker(builder);
     this.trackers.Add(tracker);
     return tracker;
 }