本文整理汇总了C#中Fixture.Customize方法的典型用法代码示例。如果您正苦于以下问题:C# Fixture.Customize方法的具体用法?C# Fixture.Customize怎么用?C# Fixture.Customize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fixture
的用法示例。
在下文中一共展示了Fixture.Customize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MessageShouldBeSameAfterSerializationAndDeserialization
public void MessageShouldBeSameAfterSerializationAndDeserialization()
{
var writer = new BinaryWriter(new MemoryStream());
IMessageFactory msgFactory = new MessageFactory(new Message[]
{
new ISomeServiceComplexRequest()
});
var fixture = new Fixture();
fixture.Customize<ISomeServiceComplexRequest>(ob =>
ob.With(x => x.datas,
fixture.CreateMany<SubData>().ToList()));
fixture.Customize<ComplexData>(ob => ob
.With(x => x.SomeArrString, fixture.CreateMany<string>().ToList())
.With(x => x.SomeArrRec, fixture.CreateMany<SubData>().ToList()));
var msg = fixture.CreateAnonymous<ISomeServiceComplexRequest>();
//serialize and deserialize msg1
msg.Serialize(writer);
writer.Seek(0, SeekOrigin.Begin);
var reader = new BinaryReader(writer.BaseStream);
Message retMsg = msgFactory.Deserialize(reader);
retMsg.Should().BeOfType<ISomeServiceComplexRequest>();
msg.ShouldBeEqualTo((ISomeServiceComplexRequest)retMsg);
}
示例2: ShouldProperlyInvokeRequestReplyMethod
public void ShouldProperlyInvokeRequestReplyMethod()
{
#region Arrange
var fixture = new Fixture();
fixture.Customize<ISomeServiceComplexRequest>(ob =>
ob.With(x => x.datas,
fixture.CreateMany<SubData>().ToList()));
fixture.Customize<ComplexData>(ob => ob
.With(x => x.SomeArrString, fixture.CreateMany<string>().ToList())
.With(x => x.SomeArrRec, fixture.CreateMany<SubData>().ToList()));
var inputMsg = fixture.CreateAnonymous<ISomeServiceComplexRequest>();
var output = inputMsg.data;
var tcs = new TaskCompletionSource<ComplexData>();
tcs.SetResult(output);
var service = Substitute.For<ISomeService>();
service.Complex(inputMsg.requestId, inputMsg.data, inputMsg.name, inputMsg.datas)
.Returns(x => tcs.Task);
#endregion
//Act
Task<Message> ret = _protocolDesc.Dispatch(service, inputMsg);
//Assert
service.Received(1).Complex(inputMsg.requestId, inputMsg.data, inputMsg.name, inputMsg.datas);
ret.Should().NotBeNull();
ret.Status.Should().Be(TaskStatus.RanToCompletion);
var replyMsg = ret.Result as ISomeServiceComplexReply;
replyMsg.Should().NotBeNull();
replyMsg.RetVal.Should().Be(output);
}
示例3: TestBase
public TestBase()
{
Fixture = new Fixture();
Fixture.Customize<Feature>(ctx => ctx.OmitAutoProperties());
Fixture.Customize<Scenario>(ctx => ctx.OmitAutoProperties());
Scenario = Fixture.Create<Scenario>();
}
示例4: Setup
public void Setup()
{
_fixture = new Fixture();
_fixture.Customize(new AutoMoqCustomization());
_fixture.Customize(new RandomNumericSequenceCustomization());
Expression<Func<ControllerSample, ModelSample, IEnumerable<ModelSample>>> lambda = (c, m)
=> c.ControllerQueryMethod(m.Id, m.Name, QueryParameter.Is<string>(), QueryParameter.Is<int>());
Expression<Func<ControllerSample, ModelSample, ModelSample>> lambda2 = (c, m)
=> c.ControllerMethodPut(m.Id, m);
var apiExplorerMoq = new Mock<IApiExplorer>();
apiExplorerMoq.Setup(_ => _.ApiDescriptions).Returns(new Collection<ApiDescription>()
{
new ApiDescription()
{
}
});
var actionConfiguration = new Mock<IActionConfiguration>();
actionConfiguration.Setup(_ => _.MappingRules).Returns(() => new List<MappingRule>
{
new MappingRule( (MethodCallExpression)lambda.Body, apiExplorerMoq.Object)
{
ApiDescriptions = new List<ApiDescription>()
{
new ApiDescription()
{
RelativePath = "/api/{id}?query={query}",
HttpMethod = HttpMethod.Get
}
},
Type = MappingRule.RuleType.Default
},
new MappingRule( (MethodCallExpression)lambda2.Body, apiExplorerMoq.Object)
{
ApiDescriptions = new List<ApiDescription>()
{
new ApiDescription()
{
RelativePath = "/api/prod/{id}",
HttpMethod = HttpMethod.Put
}
},
Type = MappingRule.RuleType.Default
}
});
_actionConfiguration = actionConfiguration.Object;
}
示例5: CanBeSerialized
public void CanBeSerialized()
{
var fixture = new Fixture();
fixture.Customize<TestSuite>(ob => ob.Without(tr => tr.SystemErrWrapped).Without(tc => tc.SystemOutWrapped));
fixture.Customize<TestCase>(ob => ob.Without(tr => tr.SystemErrWrapped).Without(tc => tc.SystemOutWrapped));
fixture.Customize<ErrorOrFailure>(ob => ob.Without(tr => tr.TextWrapped));
TestRun obj = fixture.Create(new TestRun());
var serializer = new XmlSerializer(typeof (TestRun));
//using (var stream = File.Create("abc.xml"))
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, obj);
}
}
示例6: GetPatientProcedures
public IEnumerable<PatientProcedure> GetPatientProcedures(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientProcedures)
{
fixture.Customize<PatientProcedure>(pp => pp.With(x => x.PatientId, demographic.PatientId)
.Without(x => x.CptHcpcs));
var procedures = fixture.CreateMany<PatientProcedure>(randomizer.Next(0, maxNumberOfPatientProcedures + 1)).ToList();
foreach (var procedure in procedures)
{
procedure.ProcedureDate = procedure.ProcedureDate.Date;
var hasFavoredProcedure = randomizer.NextPercent() <= ChanceOfHavingFavoredProcedure;
procedure.CptHcpcs = hasFavoredProcedure ? randomizer.NextListElement(_favoredProcedureCodes) : GetRandomProcedure(randomizer);
var isProcedureRecent = randomizer.NextPercent() <= ChanceOfHavingRecentProcedure;
if(isProcedureRecent)
{
var oldestRecentDateTime = DateTime.Today.AddMonths(-6);
if(procedure.ProcedureDate < oldestRecentDateTime)
{
var maximumNumberOfDaysForRecent = (int)(DateTime.Today - oldestRecentDateTime).TotalDays;
var daysAgo = randomizer.Next(1, maximumNumberOfDaysForRecent);
procedure.ProcedureDate = DateTime.Today.AddDays(-daysAgo);
}
}
}
return procedures.OrderBy(x => x.ProcedureDate);
}
示例7: SetUp
public void SetUp()
{
"Given a fixture"
.Given(() =>
{
Fixture = new Fixture();
Fixture.Customize(new AutoMoqCustomization());
});
"And some mock comparers"
.And(() =>
{
Inner = Fixture.Freeze<IEnumerable<IComparison>>()
.Select(Mock.Get)
.ToList();
Inner.ForEach(
m => m.Setup(c => c.CanCompare(It.IsAny<Type>(), It.IsAny<Type>()))
.Returns(false));
Inner.ForEach(
m => m.Setup(c => c.Compare(It.IsAny<IComparisonContext>(), It.IsAny<object>(), It.IsAny<object>()))
.Returns(ComparisonResult.Inconclusive));
});
"And a CompositeComparer"
.And(() => SUT = Fixture.Build<CompositeComparison>()
.With(x => x.Comparisons)
.Create());
}
示例8: UnitTestBase
public UnitTestBase()
{
AutoMapperConfiguration.Configure();
Fixture = new Fixture();
Fixture.Customize(new AutoFakeItEasyCustomization());
}
示例9: Initialize
public void Initialize()
{
fixture = new Fixture();
fixture.Customize<usr_CUSTOMERS>(
customer =>
customer.With(x => x.password, Tests.SAMPLE_PASSWORD).With(x => x.email, Tests.SAMPLE_EMAIL_ADDRESS));
}
示例10: Setup
public void Setup()
{
var fixture = new Fixture();
fixture.Customize(new WebModelCustomization());
_controller = fixture.Create<AccountController>();
}
示例11: GetPatientTherapies
public IEnumerable<PatientTherapy> GetPatientTherapies(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientTherapies)
{
fixture.Customize<PatientTherapy>(pt => pt.With(x => x.PatientId, demographic.PatientId)
.Without(x => x.DDID)
.Without(x => x.RXNorm)
.Without(x => x.StopDate));
var therapies = fixture.CreateMany<PatientTherapy>(randomizer.Next(0, maxNumberOfPatientTherapies + 1));
foreach (var therapy in therapies)
{
var daysOnTherapy = randomizer.Next(1, 365);
therapy.StopDate = new DateTime(Math.Min(therapy.StartDate.AddDays(daysOnTherapy).Ticks, DateTime.Now.Ticks));
var hasFavoredTherapy = randomizer.NextPercent() <= ChanceOfHavingFavoredCondition;
if (hasFavoredTherapy)
{
var pair = randomizer.NextDictionaryPair(_favoredTherapies);
therapy.NDC = pair.Key;
therapy.DrugName = pair.Value;
}
else
{
therapy.NDC = NDCGenerator.GetRandomNDC(randomizer);
}
}
return therapies.OrderBy(x => x.StartDate);
}
示例12: FreshenMailBoxTestWithException
public void FreshenMailBoxTestWithException()
{
_imapWorker.Setup(false);
var r = new ImapCommandResponse();
var fix = new Fixture();
fix.Customize(new AutoMoqCustomization());
var messages = fix.CreateMany<IMessageSummary>().ToList();
//first fetch throws exception - after closing and opening folders now messages are returned
//this mirrors how the client has been functioning in real world tests
inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(),
It.IsAny<CancellationToken>())).ThrowsAsync(new ImapCommandException(r ,"The IMAP server replied to the 'FETCH' command with a 'NO' response."))
.Callback(() =>
{
inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(),
It.IsAny<CancellationToken>())).ReturnsAsync(messages);
});
_imapWorker.FreshenMailBox();
inbox.Verify(x => x.CloseAsync(It.Is<bool>(y => y == false), It.IsAny<CancellationToken>()), Times.Exactly(1));
inbox.Verify(x => x.OpenAsync(It.IsAny<FolderAccess>(), It.IsAny<CancellationToken>()));
}
示例13: GetPatientUtilizations
public IEnumerable<PatientUtilization> GetPatientUtilizations(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientUtilizations)
{
fixture.Customize<PatientUtilization>(pu => pu.With(x => x.PatientId, demographic.PatientId));
var utilizations = fixture.CreateMany<PatientUtilization>(randomizer.Next(0, maxNumberOfPatientUtilizations + 1));
return utilizations.OrderBy(x => x.ActivityDate);
}
示例14: GetFixture
public static IFixture GetFixture()
{
var fixture = new Fixture();
fixture.Customizations.Add(new PropertyOmitter());
return fixture.Customize(
new CompositeCustomization(
new AutoNSubstituteCustomization()));
}
示例15: CreatesTemplateItem
public void CreatesTemplateItem()
{
var fixture = new Fixture();
fixture.Customize(new AutoContentCustomization());
var template = fixture.Create<TemplateItem>();
template.Database.GetTemplate(template.ID).Should().NotBeNull();
}