本文整理汇总了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
}
示例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);
}
示例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
}
示例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
}
示例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
}
示例6: ExecuteNullSpecimenThrows
public void ExecuteNullSpecimenThrows()
{
var sut = new DictionaryFiller();
var dummyContext = new DelegatingSpecimenContext();
Assert.Throws<ArgumentNullException>(() =>
sut.Execute(null, dummyContext));
}
示例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
}
示例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);
}));
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}