当前位置: 首页>>代码示例>>C#>>正文


C# Kernel.DelegatingSpecimenContext类代码示例

本文整理汇总了C#中Ploeh.AutoFixtureUnitTest.Kernel.DelegatingSpecimenContext的典型用法代码示例。如果您正苦于以下问题:C# DelegatingSpecimenContext类的具体用法?C# DelegatingSpecimenContext怎么用?C# DelegatingSpecimenContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DelegatingSpecimenContext类属于Ploeh.AutoFixtureUnitTest.Kernel命名空间,在下文中一共展示了DelegatingSpecimenContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateWillReturnCorrectResult

        public void CreateWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedSpecimen = new object();

            var param1 = new { ExpectedRequest = typeof(decimal), Specimen = (object)1m };
            var param2 = new { ExpectedRequest = typeof(TimeSpan), Specimen = (object)TimeSpan.FromDays(1) };
            var subRequests = new[] { param1, param2 };

            var container = new DelegatingSpecimenContext();
            container.OnResolve = r => (from x in subRequests
                                        where x.ExpectedRequest.Equals(r)
#pragma warning disable 618
                                        select x.Specimen).DefaultIfEmpty(new NoSpecimen(r)).SingleOrDefault();
#pragma warning restore 618

            Func<decimal, TimeSpan, object> f = (d, ts) => param1.Specimen.Equals(d) && param2.Specimen.Equals(ts) ? expectedSpecimen : new NoSpecimen();
            var sut = new SpecimenFactory<decimal, TimeSpan, object>(f);
            // Exercise system
            var dummyRequest = new object();
            var result = sut.Create(dummyRequest, container);
            // Verify outcome
            Assert.Equal(expectedSpecimen, result);
            // Teardown
        }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:25,代码来源:SpecimenFactoryWithDoubleParameterFuncTest.cs

示例2: CreateWithEnumerableParameterReturnsCorrectResult

        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 OmitArrayParameterRequestRelay();

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

            Assert.Equal(expected, actual);
        }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:29,代码来源:OmitArrayParameterRequestRelayTests.cs

示例3: ExecutesEveryChildCommandWithCorrectSpecimen

        public void ExecutesEveryChildCommandWithCorrectSpecimen()
        {
            // Fixture setup
            var specimen = new object();
            var dummyContext = new DelegatingSpecimenContext();

            var command1Verified = false;
            var command1 = new DelegatingSpecimenCommand
                {
                    OnExecute = (req, ctx) =>
                        {
                            command1Verified = true;
                            Assert.Same(specimen, req);
                        }
                };

            var command2Verified = false;
            var command2 = new DelegatingSpecimenCommand
                {
                    OnExecute = (req, ctx) =>
                        {
                            command2Verified = true;
                            Assert.Same(specimen, req);
                        }
                };

            var sut = new CompositeSpecimenCommand(command1, command2);
            // Exercise system
            sut.Execute(specimen, dummyContext);
            // Verify outcome
            Assert.True(command1Verified);
            Assert.True(command2Verified);
            // Teardown
        }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:34,代码来源:CompositeSpecimenCommandTest.cs

示例4: CreateWithMailAddressRequestReturnsCorrectResultUsingLocalPartAndDomainNameFromContext

 public void CreateWithMailAddressRequestReturnsCorrectResultUsingLocalPartAndDomainNameFromContext()
 {
     // Fixture setup
     var request = typeof(MailAddress);
     var expectedLocalPart = new EmailAddressLocalPart(Guid.NewGuid().ToString());
     var expectedDomainName = new DomainName(Guid.NewGuid().ToString());
     var context = new DelegatingSpecimenContext()
     {
         OnResolve = r =>
        {
            Assert.True(typeof(EmailAddressLocalPart).Equals(r) || typeof(DomainName).Equals(r));
            if (typeof(EmailAddressLocalPart).Equals(r))
            {
                return expectedLocalPart;
            }
            else
            {
                return expectedDomainName;
            }
        }
     };
     var sut = new MailAddressGenerator();
     // Exercise system
     var result = (MailAddress)sut.Create(request, context);
     // Verify outcome
     Assert.Equal(expectedLocalPart.LocalPart, result.User);
     Assert.Equal(expectedDomainName.Domain, result.Host);
     // Teardown
 }
开发者ID:jspengine,项目名称:AutoFixture,代码行数:29,代码来源:MailAddressGeneratorTests.cs

示例5: CreateWillReturnCorrectResult

        public void CreateWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedSpecimen = new object();

            var param1 = new { ExpectedRequest = typeof(decimal), Specimen = (object)1m };
            var param2 = new { ExpectedRequest = typeof(TimeSpan), Specimen = (object)TimeSpan.FromDays(1) };
            var param3 = new { ExpectedRequest = typeof(string), Specimen = (object)"Anonymous value - with Foo!" };
            var param4 = new { ExpectedRequest = typeof(int), Specimen = (object)7 };
            var subRequests = new[] { param1, param2, param3, param4 };

            var container = new DelegatingSpecimenContext();
            container.OnResolve = r => (from x in subRequests
                                        where x.ExpectedRequest.Equals(r)
                                        select x.Specimen).DefaultIfEmpty(new NoSpecimen(r)).SingleOrDefault();

            Func<decimal, TimeSpan, string, int, object> f = (d, ts, s, i) =>
                param1.Specimen.Equals(d) && param2.Specimen.Equals(ts) && param3.Specimen.Equals(s) && param4.Specimen.Equals(i) ? expectedSpecimen : new NoSpecimen();
            var sut = new SpecimenFactory<decimal, TimeSpan, string, int, object>(f);
            // Exercise system
            var dummyRequest = new object();
            var result = sut.Create(dummyRequest, container);
            // Verify outcome
            Assert.Equal(expectedSpecimen, result);
            // Teardown
        }
开发者ID:nrjohnstone,项目名称:AutoFixture,代码行数:26,代码来源:SpecimenFactoryWithQuadrupleParameterFuncTest.cs

示例6: ExecuteNullSpecimenThrows

 public void ExecuteNullSpecimenThrows()
 {
     var sut = new DictionaryFiller();
     var dummyContext = new DelegatingSpecimenContext();
     Assert.Throws<ArgumentNullException>(() =>
         sut.Execute(null, dummyContext));
 }
开发者ID:jpierson,项目名称:AutoFixture,代码行数:7,代码来源:DictionaryFillerTest.cs

示例7: CreateFromMultipleRequestReturnsCorrectResult

 public void CreateFromMultipleRequestReturnsCorrectResult(
     Type itemType,
     int arrayLength)
 {
     // Fixture setup
     var sut = new MultipleToEnumerableRelay();
     var context = new DelegatingSpecimenContext
     {
         OnResolve = r =>
         {
             Assert.Equal(
                 typeof(IEnumerable<>).MakeGenericType(itemType),
                 r);
             return Array.CreateInstance((Type)itemType, arrayLength);
         }
     };
     // Exercise system
     var request = new MultipleRequest(itemType);
     var actual = sut.Create(request, context);
     // Verify outcome
     Assert.IsAssignableFrom(
         typeof(IEnumerable<>).MakeGenericType(itemType),
         actual);
     var enumerable =
         Assert.IsAssignableFrom<System.Collections.IEnumerable>(actual);
     Assert.Equal(arrayLength, enumerable.Cast<object>().Count());
     // Teardown
 }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:28,代码来源:MultipleToEnumerableRelayTests.cs

示例8: CreateWithInvalidRequestReturnsNoSpecimen

        public static IEnumerable<ITestCase> CreateWithInvalidRequestReturnsNoSpecimen()
        {
            var invalidRequests = new[]
            {
                null,
                new object(),
                string.Empty,
                123,
                typeof(int),
                typeof(object[]),
                typeof(string[][])
            };
            return invalidRequests.Select(r => new TestCase(() =>
            {
                var sut = new MultidimensionalArrayRelay();
                var dummyContext = new DelegatingSpecimenContext();
#pragma warning disable 618
                var expected = new NoSpecimen(r);
#pragma warning restore 618

                var actual = sut.Create(r, dummyContext);

                Assert.Equal(expected, actual);
            }));
        }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:25,代码来源:MultidimensionalArrayRelayTest.cs

示例9: CreateFromTypeWhenParentCanGenerateBothParametersWillReturnCorrectResult

        public void CreateFromTypeWhenParentCanGenerateBothParametersWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedParameterValues = new object[] { 1, 2m };
            var parameterQueue = new Queue<object>(expectedParameterValues);

            var requestedType = typeof(DoubleParameterType<int, decimal>);
            var parameters = requestedType.GetConstructors().Single().GetParameters();

            var container = new DelegatingSpecimenContext();
            container.OnResolve = r =>
            {
                if (parameters.Any(r.Equals))
                {
                    return parameterQueue.Dequeue();
                }
                return null;
            };

            var sut = new MethodInvoker(new ModestConstructorQuery());
            // Exercise system
            var result = sut.Create(requestedType, container);
            // Verify outcome
            var actual = (DoubleParameterType<int, decimal>)result;
            Assert.Equal(expectedParameterValues[0], actual.Parameter1);
            Assert.Equal(expectedParameterValues[1], actual.Parameter2);
            // Teardown
        }
开发者ID:Tungsten78,项目名称:AutoFixture,代码行数:28,代码来源:MethodInvokerTest.cs

示例10: ExecuteWithNullSpecimenThrows

 public void ExecuteWithNullSpecimenThrows()
 {
     // Fixture setup
     var sut = new AutoPropertiesCommand<object>();
     var dummyContainer = new DelegatingSpecimenContext();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() => sut.Execute(null, dummyContainer));
     // Teardown
 }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:9,代码来源:AutoPropertiesCommandTest.cs

示例11: AddManyToNonDictionaryThrows

 public void AddManyToNonDictionaryThrows(object specimen)
 {
     // Fixture setup
     var dummyContext = new DelegatingSpecimenContext();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentException>(() =>
         DictionaryFiller.AddMany(specimen, dummyContext));
     // Teardown
 }
开发者ID:jpierson,项目名称:AutoFixture,代码行数:9,代码来源:DictionaryFillerTest.cs

示例12: CreateWithNullRequestThrows

 public void CreateWithNullRequestThrows()
 {
     // Fixture setup
     var sut = new Omitter();
     // Exercise system and verify outcome
     var dummyContext = new DelegatingSpecimenContext();
     Assert.Throws<ArgumentNullException>(() =>
         sut.Create(null, dummyContext));
     // Teardown
 }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:10,代码来源:OmitterTests.cs

示例13: CreateFromIntPtrRequestThrows

 public void CreateFromIntPtrRequestThrows()
 {
     // Fixture setup
     var sut = new IntPtrGuard();
     var dummyContext = new DelegatingSpecimenContext();
     // Exercise system and verify outcome
     Assert.Throws<IllegalRequestException>(() =>
         sut.Create(typeof(IntPtr), dummyContext));
     // Teardown
 }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:10,代码来源:IntPtrGuardTest.cs

示例14: CreateWithCorrectTypeRequestWillReturnCorrectTypeSpecimen

 public void CreateWithCorrectTypeRequestWillReturnCorrectTypeSpecimen()
 {
     // Fixture setup
     var dummyContext = new DelegatingSpecimenContext();
     var sut = new ElementsBuilder<int>(42);
     // Exercise system
     var result = sut.Create(typeof(int), dummyContext);
     // Verify outcome
     Assert.Equal(typeof(int), result.GetType());
     // Teardown
 }
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:11,代码来源:ElementsBuilderTest.cs

示例15: CreateWithNonTypeRequestReturnsNoSpecimen

 public void CreateWithNonTypeRequestReturnsNoSpecimen(object request)
 {
     // Fixture setup
     var sut = new RandomDateTimeSequenceGenerator();
     // Exercise system
     var dummyContainer = new DelegatingSpecimenContext();
     var result = sut.Create(request, dummyContainer);
     // Verify outcome
     Assert.Equal(new NoSpecimen(request), result);
     // Teardown
 }
开发者ID:jpierson,项目名称:AutoFixture,代码行数:11,代码来源:RandomDateTimeSequenceGeneratorTest.cs


注:本文中的Ploeh.AutoFixtureUnitTest.Kernel.DelegatingSpecimenContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。