/// <summary>
        /// Creates a new <see cref="TerminatingWithPathSpecimenBuilder"/> using the
        /// supplied <see cref="TracingBuilder"/> to track specimen requests.
        /// </summary>
        /// <param name="tracer"></param>
        public TerminatingWithPathSpecimenBuilder(TracingBuilder tracer)
        {
            if (tracer == null)
                throw new ArgumentNullException(nameof(tracer));

            this.Tracer = tracer;
            this.Tracer.SpecimenRequested += OnSpecimenRequested;
            this.Tracer.SpecimenCreated += OnSpecimenCreated;
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="TerminatingWithPathSpecimenBuilder"/> using the
        /// supplied <see cref="TracingBuilder"/> to track specimen requests.
        /// </summary>
        /// <param name="tracer"></param>
        public TerminatingWithPathSpecimenBuilder(TracingBuilder tracer)
        {
            if (tracer == null)
            {
                throw new ArgumentNullException("tracer");
            }

            this.tracer = tracer;
            this.tracer.SpecimenRequested += OnSpecimenRequested;
            this.tracer.SpecimenCreated   += OnSpecimenCreated;
        }
 public void BuilderIsCorrect()
 {
     // Fixture setup
     var expectedBuilder = new DelegatingSpecimenBuilder();
     var sut = new TracingBuilder(expectedBuilder);
     // Exercise system
     ISpecimenBuilder result = sut.Builder;
     // Verify outcome
     Assert.Equal(expectedBuilder, result);
     // Teardown
 }
        public void CreateWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedSpecimen = new object();
            var stubBuilder = new TracingBuilder(new DelegatingSpecimenBuilder { OnCreate = (r, c) => expectedSpecimen });

            var dummyWriter = TextWriter.Null;
            var sut = new TraceWriter(dummyWriter, stubBuilder);
            // Exercise system
            var dummyRequest = new object();
            var dummyContainer = new DelegatingSpecimenContext();
            var result = sut.Create(dummyRequest, dummyContainer);
            // Verify outcome
            Assert.Equal(expectedSpecimen, result);
            // 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 dummyWriter = TextWriter.Null;
            var sut = new TraceWriter(dummyWriter, mockBuilder);
            // Exercise system
            sut.Create(expectedRequest, expectedContainer);
            // Verify outcome
            Assert.True(verified, "Mock verified");
            // Teardown
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TraceWriter"/> class.
        /// </summary>
        /// <param name="writer">The output stream for the trace.</param>
        /// <param name="tracer">The <see cref="ISpecimenBuilder"/> to decorate.</param>
        public TraceWriter(TextWriter writer, TracingBuilder tracer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (tracer == null)
            {
                throw new ArgumentNullException("tracer");
            }

            this.tracer = tracer;
            this.tracer.SpecimenRequested += (sender, e) => this.writeRequest(writer, e.Request, e.Depth);
            this.tracer.SpecimenCreated   += (sender, e) => this.writeSpecimen(writer, e.Specimen, e.Depth);

            this.TraceRequestFormatter  = (tw, r, i) => tw.WriteLine(new string(' ', i * 2) + "Requested: " + r);
            this.TraceSpecimenFormatter = (tw, r, i) => tw.WriteLine(new string(' ', i * 2) + "Created: " + r);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TraceWriter"/> class.
        /// </summary>
        /// <param name="writer">The output stream for the trace.</param>
        /// <param name="tracer">The <see cref="ISpecimenBuilder"/> to decorate.</param>
        public TraceWriter(TextWriter writer, TracingBuilder tracer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (tracer == null)
            {
                throw new ArgumentNullException(nameof(tracer));
            }        

            this.Tracer = tracer;
            this.Tracer.SpecimenRequested += (sender, e) => this.writeRequest(writer, e.Request, e.Depth);
            this.Tracer.SpecimenCreated += (sender, e) => this.writeSpecimen(writer, e.Specimen, e.Depth);

            this.writer = writer;
            this.TraceRequestFormatter = (tw, r, i) => tw.WriteLine(new string(' ', i * 2) + "Requested: " + r);
            this.TraceSpecimenFormatter = (tw, r, i) => tw.WriteLine(new string(' ', i * 2) + "Created: " + r);
        }
        public void VerifyMethodUsesParameterInfoToCreateArguments()
        {
            var parameters = new List<ParameterInfo>();
            var fixture = new Fixture();
            var tracingBuilder = new TracingBuilder(fixture);
            tracingBuilder.SpecimenCreated += (sender, args) =>
            {
                var parameter = args.Request as ParameterInfo;
                    if (parameter != null)
                        parameters.Add(parameter);
            };

            var sut = new ObjectDisposalAssertion(tracingBuilder);
            var method = new Methods<ClassForDisposable>().Select(
                x => x.ThrowObjectDisposedException(null));

            sut.Verify(method);

            Assert.Equal(1, parameters.Count);
        }