public async Task OnActionExecutionAsync_GivenIncorrectAction_ShouldNotCallSimulator() { // Arrange Mock <ILatencySimulator> mockLatencySimulator = new Mock <ILatencySimulator>(MockBehavior.Strict); ControllerActionDescriptor actionDescriptor = new ControllerActionDescriptor { ControllerName = "People", ActionName = "Invalid" }; var actionContext = new ActionContext( new Mock <HttpContext>().Object, new Mock <RouteData>().Object, actionDescriptor, new Mock <ModelStateDictionary>().Object ); var actionExecutingContext = new ActionExecutingContext( actionContext, new List <IFilterMetadata>(), new Dictionary <string, object>(), new Mock <Controller>().Object ); ActionExecutedContext actionExecutedContext = null; LatencySimulationFilter filter = new LatencySimulationFilter(mockLatencySimulator.Object); // Act await filter.OnActionExecutionAsync(actionExecutingContext, async() => await Task.FromResult(actionExecutedContext)); // Assert mockLatencySimulator.VerifyAll(); }
public async Task OnActionExecutionAsync_GivenNullContext_ShouldNotThrowException() { // Arrange ActionExecutingContext actionExecutingContext = null; ActionExecutedContext actionExecutedContext = null; LatencySimulationFilter filter = new LatencySimulationFilter(null); try { // Act await filter.OnActionExecutionAsync(actionExecutingContext, async() => await Task.FromResult(actionExecutedContext)); } catch { // Assert Assert.Fail(); } }
public async Task OnActionExecutionAsync_GivenCorrectControllerAndNullSimulator_ShouldNotThrowException() { // Arrange ControllerActionDescriptor actionDescriptor = new ControllerActionDescriptor { ControllerName = "People", ActionName = "GetAsync" }; var actionContext = new ActionContext( new Mock <HttpContext>().Object, new Mock <RouteData>().Object, actionDescriptor, new Mock <ModelStateDictionary>().Object ); var actionExecutingContext = new ActionExecutingContext( actionContext, new List <IFilterMetadata>(), new Dictionary <string, object>(), new Mock <Controller>().Object ); ActionExecutedContext actionExecutedContext = null; LatencySimulationFilter filter = new LatencySimulationFilter(null); try { // Act await filter.OnActionExecutionAsync(actionExecutingContext, async() => await Task.FromResult(actionExecutedContext)); } catch { // Assert Assert.Fail(); } }