public void ActionWithAccountIdParam_IfTradingEnabled_ShouldNotThrow() { //arrange var marginTradingSettingsService = Mock.Of <IMarginTradingSettingsCacheService>(s => s.IsMarginTradingEnabledByAccountId("id of account") == true); var sut = new MarginTradingEnabledFilter(marginTradingSettingsService, new DummyCacheProvider()); //act var context = new ActionExecutingContext(new ControllerContext { ActionDescriptor = new ControllerActionDescriptor { DisplayName = "action display name", Parameters = new List <ParameterDescriptor> { new ControllerParameterDescriptor { Name = "accountId", ParameterType = typeof(string), } }, MethodInfo = typeof(TestController).GetMethod("ActionWithAccountIdParam"), }, HttpContext = new DefaultHttpContext(), RouteData = new RouteData(), }, new List <IFilterMetadata>(), new Dictionary <string, object> { { "accountId", "id of account" } }, new TestController()); Func <Task> invocation = () => sut.OnActionExecutionAsync(context, NextFunc); //assert invocation.Should().NotThrow(); }
public void ActionWithClientIdParam_IfTradingDisabled_ShouldThrow() { //arrange var marginTradingSettingsService = Mock.Of <IMarginTradingSettingsCacheService>(s => s.IsMarginTradingEnabled("id of client", It.IsAny <bool>()) == Task.FromResult(false)); var sut = new MarginTradingEnabledFilter(new MarginSettings(), marginTradingSettingsService, new DummyCacheProvider(), new Mock <ILog>().Object); //act var context = new ActionExecutingContext(new ControllerContext { ActionDescriptor = new ControllerActionDescriptor { DisplayName = "action display name", Parameters = new List <ParameterDescriptor> { new ControllerParameterDescriptor { Name = "clientId", ParameterType = typeof(string), } }, MethodInfo = typeof(TestController).GetMethod("ActionWithClientIdParam"), }, HttpContext = new DefaultHttpContext(), RouteData = new RouteData(), }, new List <IFilterMetadata>(), new Dictionary <string, object> { { "clientId", "id of client" } }, new TestController()); Func <Task> invocation = () => sut.OnActionExecutionAsync(context, NextFunc); //assert invocation.ShouldThrow <InvalidOperationException>().WithMessage("Using this type of margin trading is restricted for client id of client"); }
public void ActionWithRequestParam_IfTradingEnabled_ShouldNotThrow() { //arrange var marginTradingSettingsService = Mock.Of <IMarginTradingSettingsCacheService>(s => s.IsMarginTradingEnabled("id of client", It.IsAny <bool>()) == Task.FromResult(true)); var sut = new MarginTradingEnabledFilter(new MarginSettings(), marginTradingSettingsService, new DummyCacheProvider(), new Mock <ILog>().Object); //act var context = new ActionExecutingContext(new ControllerContext { ActionDescriptor = new ControllerActionDescriptor { DisplayName = "action display name", Parameters = new List <ParameterDescriptor> { new ControllerParameterDescriptor { Name = "request", ParameterType = typeof(RequestWithClientId), } }, MethodInfo = typeof(TestController).GetMethod("ActionWithRequestParam"), }, HttpContext = new DefaultHttpContext(), RouteData = new RouteData(), }, new List <IFilterMetadata>(), new Dictionary <string, object> { { "request", new RequestWithClientId { ClientId = "id of client" } } }, new TestController()); Func <Task> invocation = () => sut.OnActionExecutionAsync(context, NextFunc); //assert invocation.ShouldNotThrow(); }
public void ActionWithRequestParam_IfTradingDisabled_ShouldThrow() { //arrange var marginTradingSettingsService = Mock.Of <IMarginTradingSettingsCacheService>(s => s.IsMarginTradingEnabledByAccountId("id of account") == false); var sut = new MarginTradingEnabledFilter(marginTradingSettingsService, new DummyCacheProvider()); //act var context = new ActionExecutingContext(new ControllerContext { ActionDescriptor = new ControllerActionDescriptor { DisplayName = "action display name", Parameters = new List <ParameterDescriptor> { new ControllerParameterDescriptor { Name = "request", ParameterType = typeof(RequestWithAccountId), } }, MethodInfo = typeof(TestController).GetMethod("ActionWithRequestParam"), }, HttpContext = new DefaultHttpContext(), RouteData = new RouteData(), }, new List <IFilterMetadata>(), new Dictionary <string, object> { { "request", new RequestWithAccountId { AccountId = "id of account" } } }, new TestController()); Func <Task> invocation = () => sut.OnActionExecutionAsync(context, NextFunc); //assert invocation.Should().Throw <InvalidOperationException>() .WithMessage("Using this type of margin trading is restricted for account id id of account"); }