本文整理汇总了C#中Nancy.NancyContext.GetMockInteractions方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.GetMockInteractions方法的具体用法?C# NancyContext.GetMockInteractions怎么用?C# NancyContext.GetMockInteractions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.NancyContext
的用法示例。
在下文中一共展示了NancyContext.GetMockInteractions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleGetInteractionsVerificationRequest
private Response HandleGetInteractionsVerificationRequest(NancyContext context)
{
//Check all registered interactions have been used once and only once
var registeredInteractions = context.GetMockInteractions().ToList();
if (registeredInteractions.Any())
{
foreach (var registeredInteraction in registeredInteractions)
{
var interactionUsages = _mockProviderRepository.HandledRequests.Where(x => x.MatchedInteraction == registeredInteraction).ToList();
if (interactionUsages == null || !interactionUsages.Any())
{
_reporter.ReportError(String.Format("Registered mock interaction with description '{0}' and provider state '{1}', was not used by the test.", registeredInteraction.Description, registeredInteraction.ProviderState));
}
else if (interactionUsages.Count() > 1)
{
_reporter.ReportError(String.Format("Registered mock interaction with description '{0}' and provider state '{1}', was used {2} time/s by the test.", registeredInteraction.Description, registeredInteraction.ProviderState, interactionUsages.Count()));
}
}
}
else
{
if (_mockProviderRepository.HandledRequests != null && _mockProviderRepository.HandledRequests.Any())
{
_reporter.ReportError("No mock interactions were registered, however the mock provider service was called.");
}
}
//Check all handled requests actually match the registered interaction
if (_mockProviderRepository.HandledRequests != null &&
_mockProviderRepository.HandledRequests.Any())
{
foreach (var handledRequest in _mockProviderRepository.HandledRequests)
{
_requestComparer.Compare(handledRequest.MatchedInteraction.Request, handledRequest.ActualRequest);
}
}
try
{
_reporter.ThrowIfAnyErrors();
}
catch (Exception ex)
{
_reporter.ClearErrors();
return GenerateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
return GenerateResponse(HttpStatusCode.OK, "Successfully verified mock provider interactions.");
}
示例2: GetMockInteractions_WithNoRegisteredInteractions_ReturnsEmptyList
public void GetMockInteractions_WithNoRegisteredInteractions_ReturnsEmptyList()
{
var context = new NancyContext();
var result = context.GetMockInteractions();
Assert.Empty(result);
}
示例3: GetMockInteractions_WithRegisteredInteractions_ReturnsInteractions
public void GetMockInteractions_WithRegisteredInteractions_ReturnsInteractions()
{
var interactions = new List<ProviderServiceInteraction>
{
new ProviderServiceInteraction { Request = new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/events" }, Response = new ProviderServiceResponse()},
new ProviderServiceInteraction { Request = new ProviderServiceRequest { Method = HttpVerb.Post, Path = "/events" }, Response = new ProviderServiceResponse()},
};
var context = new NancyContext();
context.SetMockInteraction(interactions);
var result = context.GetMockInteractions().ToList();
Assert.Equal(2, result.Count());
Assert.Equal(interactions.First(), result.First());
Assert.Equal(interactions.Last(), result.Last());
}