public void CreateWithEnumerableParameterReturnsCorrectResult(
            Type argumentType)
        {
            var parameterInfo =
                typeof(SingleParameterType<>)
                    .MakeGenericType(new[] { argumentType })
                    .GetConstructors()
                    .First()
                    .GetParameters()
                    .First();
            var expected = new object();
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    Assert.Equal(
                        new SeededRequest(
                            parameterInfo.ParameterType,
                            parameterInfo.Name),
                        r);
                    return expected;
                }
            };
            var sut = new OmitEnumerableParameterRequestRelay();

            var actual = sut.Create(parameterInfo, context);

            Assert.Equal(expected, actual);
        }
コード例 #2
0
 public void CreateReturnsCorrectResultForNonParameterRequest(
     object request)
 {
     var sut = new OmitEnumerableParameterRequestRelay();
     var actual = sut.Create(request, new DelegatingSpecimenContext());
     Assert.Equal(new NoSpecimen(request), actual);
 }
        public void CreateWithNonEnumerableParameterRequestReturnsCorrectResult(
            Type argumentType)
        {
            var parameterInfo =
                typeof(SingleParameterType<>)
                    .MakeGenericType(new[] { argumentType })
                    .GetConstructors()
                    .First()
                    .GetParameters()
                    .First();
            var sut = new OmitEnumerableParameterRequestRelay();

            var dummyContext = new DelegatingSpecimenContext();
            var actual = sut.Create(parameterInfo, dummyContext);

#pragma warning disable 618
            var expected = new NoSpecimen(parameterInfo);
#pragma warning restore 618
            Assert.Equal(expected, actual);
        }
 public void SutIsSpecimenBuilder()
 {
     var sut = new OmitEnumerableParameterRequestRelay();
     Assert.IsAssignableFrom<ISpecimenBuilder>(sut);
 }
 public void CreateWithNullContextThrows()
 {
     var sut = new OmitEnumerableParameterRequestRelay();
     Assert.Throws<ArgumentNullException>(
         () => sut.Create(new object(), null));
 }
        public void CreateReturnsCorrectResultWhenContextReturnsOmitSpecimen(
            Type argumentType)
        {
            var parameterInfo =
                typeof(SingleParameterType<>)
                    .MakeGenericType(new[] { argumentType })
                    .GetConstructors()
                    .First()
                    .GetParameters()
                    .First();
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r => new OmitSpecimen()
            };
            var sut = new OmitEnumerableParameterRequestRelay();

            var actual = sut.Create(parameterInfo, context);

            var expected = Array.CreateInstance(
                argumentType.GetGenericArguments().Single(),
                0);
            Assert.Equal(expected, actual);
        }