public void ShouldCreateConstructorParametersIfFilterIsSatisfied(
            [Frozen] IRequestSpecification requestSpecification,
            ISpecimenContext specimenContext,
            RecordReplayConstructorSpecimensForTypeBuilder sut)
        {
            requestSpecification.IsSatisfiedBy(Arg.Any <object>()).Returns(true);

            sut.Create(typeof(SimpleType), specimenContext);

            specimenContext.Received(1).Resolve(Arg.Any <object>());
        }
コード例 #2
0
        /// <summary>
        /// Creates a new <see langword="struct"/>.
        /// </summary>
        /// <param name="request">The request that describes what to create.</param>
        /// <param name="context">A context that can be used to create other specimens. Not used</param>
        /// <returns>
        /// The requested struct if possible; otherwise a <see cref="NoSpecimen"/> instance.
        /// </returns>
        public object Create(object request, ISpecimenContext context)
        {
            Type type = request as Type;

            if (type == null || !valueTypeWithoutConstructorsSpecification.IsSatisfiedBy(type))
            {
                return(new NoSpecimen(request));
            }

            return(Activator.CreateInstance(type));
        }
        public void ShouldUseRecordedConstructorSpecimensInSubsequentCallsForTheSameRequest(
            [Frozen] IRequestSpecification requestSpecification,
            ISpecimenContext context,
            RecordReplayConstructorSpecimensForTypeBuilder sut)
        {
            requestSpecification.IsSatisfiedBy(Arg.Any <object>()).Returns(true);

            sut.Create(typeof(SimpleType), context);
            sut.Create(typeof(SimpleType), context);

            context.Received(1).Resolve(Arg.Any <object>());
        }
        public void ShouldDelegateToDecoratedBuilderIfFilterIsNotSatisfied(
            [Frozen] IRequestSpecification requestSpecification,
            [Substitute] ISpecimenBuilder builder)
        {
            requestSpecification.IsSatisfiedBy(Arg.Any <object>()).Returns(false);

            var sut = new RecordReplayConstructorSpecimensForTypeBuilder(builder, requestSpecification);

            sut.CreateInstanceOfType(typeof(object));

            builder.Received(1).Create(Arg.Any <object>(), Arg.Any <ISpecimenContext>());
        }
コード例 #5
0
            public object Create(object request, ISpecimenContext context)
            {
                if (!Specification.IsSatisfiedBy(request))
                {
                    return(new NoSpecimen());
                }

                var mockType = typeof(Mock <>).MakeGenericType((Type)request);
                var result   = context.Resolve(mockType) as Mock;

                // The order here is important to enable both fixture values and storing the value passed to a setter.
                result.DefaultValueProvider = new AutoFixtureValueProvider(context);
                result.GetType().GetMethod("SetupAllProperties").Invoke(result, new object[0]);

                return(result.Object);
            }
コード例 #6
0
        public object Create(object request, ISpecimenContext context)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (requestFilter.IsSatisfiedBy(request))
            {
                var constructor = GetConstructor(request);

                return(constructor.Invoke(GetConstructorParameters(constructor, context).ToArray()));
            }

            return(builder.Create(request, context));
        }
コード例 #7
0
 public bool IsSatisfiedBy(object request)
 {
     return(criteria.IsSatisfiedBy(request));
 }
コード例 #8
0
 public object Create(object request, ISpecimenContext context)
 {
     return(_filter.IsSatisfiedBy(request)
             ? context.Resolve(request)
             : new NoSpecimen(request));
 }
コード例 #9
0
 public bool IsSatisfiedBy(object request) =>
 _criteria.IsSatisfiedBy(request);