public async Task <UserDTO> RequestPermissions([FromBody] RequestUserPermissionsDTO input) { var command = new UserPermissionsRequestedCommand(input); var result = await _commandDispatcher.Execute(command); return(result); }
public void given_UserPermissionsRequestedCommand_handler_should_call_session_Get_and_Commit_for_unlisted_permission() { // Assemble var mockAgg = new UserPermissionsRequestedCommandHandlerMockAggregate(); mockAgg.setup_session_to_ensure_addAndCommit_are_called(); var testAgg = mockAgg.SetupAdminUser(); var testPermissionAgg = mockAgg.SetupTestPermission(); var handler = mockAgg.HandlerFactory(); var input = new RequestUserPermissionsDTO { ForId = testAgg.Id, ById = testAgg.Id, Requests = new Dictionary <Guid, PermissionDetails> { { testPermissionAgg.Id, new PermissionDetails { Reason = "testRequestReason" } } } }; var command = new UserPermissionsRequestedCommand(input); // Apply var result = handler.Handle(command); // Assert Assert.True(mockAgg.SessionGetWasCalled); Assert.True(mockAgg.SessionCommitWasCalled); }
public void given_GrantUserPermissionCommand_handler_should_call_session_Get_and_Commit_on_requested_permission() { // Assemble var mockAgg = new GrantUserPermissionCommandHandlerMockAggregate(); var requestHandler = mockAgg.UserPermissionsRequestedHandlerFactory(); var granthandler = mockAgg.GrantUserPermissionHandlerFactory(); var testAgg = mockAgg.SetupAdminUser(); var testPermissionAgg = mockAgg.SetupTestPermission(); mockAgg.setup_session_to_return_correct_aggregate(testAgg, testPermissionAgg); var grantInput = new GrantUserPermissionDTO { ForId = testAgg.Id, ById = testAgg.Id, PermissionsToGrant = new Dictionary <Guid, PermissionDetails> { { testPermissionAgg.Id, new PermissionDetails { Reason = "testGrantReason" } } } }; var grantCommand = new GrantUserPermissionCommand(grantInput); var requestInput = new RequestUserPermissionsDTO { ForId = testAgg.Id, ById = testAgg.Id, Requests = new Dictionary <Guid, PermissionDetails> { { testPermissionAgg.Id, new PermissionDetails { Reason = "testRequestReason" } } } }; var requestCommand = new UserPermissionsRequestedCommand(requestInput); var requestResult = requestHandler.Handle(requestCommand); // Apply var grantResult = granthandler.Handle(grantCommand); // Assert Assert.True(mockAgg.SessionGetWasCalled); Assert.True(mockAgg.SessionCommitWasCalled); Assert.True(mockAgg.SessionGetPermisisonWasCalled); }
public async void given_DenyUserPermissionRequestCommand_handler_should_call_session_Get_and_Commit_when_permission_was_requested() { // Assemble var mockAgg = new DenyUserPermissionRequestCommandHandlerMockAggregate(); var testAgg = mockAgg.SetupAdminUser(); var testPermissionAgg = mockAgg.SetupTestPermission(); var denyHandler = mockAgg.DenyUserPermissionRequestHandlerFactory(); var requestHandler = mockAgg.UserPermissionsRequestedHandlerFactory(); mockAgg.setup_session_to_return_correct_aggregate(testAgg, testPermissionAgg); var denyInput = new DenyUserPermissionRequestDTO { ForId = testAgg.Id, ById = testAgg.Id, PermissionsToDeny = new Dictionary <Guid, PermissionDetails> { { testPermissionAgg.Id, new PermissionDetails { Reason = "testDenyReason" } } } }; var requestInput = new RequestUserPermissionsDTO { ForId = testAgg.Id, ById = testAgg.Id, Requests = new Dictionary <Guid, PermissionDetails> { { testPermissionAgg.Id, new PermissionDetails { Reason = "testRequestReason" } } } }; var requestCommand = new UserPermissionsRequestedCommand(requestInput); var result = await requestHandler.Handle(requestCommand); var denyCommand = new DenyUserPermissionRequestCommand(denyInput); // Apply var denyResult = await denyHandler.Handle(denyCommand); // Assert Assert.True(mockAgg.SessionGetWasCalled); Assert.True(mockAgg.SessionCommitWasCalled); Assert.True(mockAgg.SessionGetPermisisonWasCalled); }
public async void given_requestuserpermissionscommand_command_dispatcher_should_get_same_command_created_in_controller() { //Assemble var mockAgg = new UserControllerMockAggregate(); var id = new Guid(); var userId = new Guid(); var requests = new Dictionary <Guid, PermissionDetails> { { new Guid(), new PermissionDetails { EventType = "testEvent", IsPending = true, Reason = "testReason", RequestedBy = id, RequestedFor = userId, RequestDate = new DateTime() } } }; var input = new RequestUserPermissionsDTO() { ById = id, ForId = userId, Requests = requests }; var command = new UserPermissionsRequestedCommand(input); mockAgg.setup_dispatcher_to_verify_userPermissionsRequestedCommands_are_the_same(command); var controller = mockAgg.CreateUserController(); //Apply var result = await controller.RequestPermissions(input); //Assert Assert.IsType <UserDTO>(result); Assert.Equal(result.Id, input.ForId); Assert.Equal(result.PermissionList, input.Requests); }
public async void handler_should_filter_already_requested_command_out_of_requests() { // Assemble var mockAgg = new UserPermissionsRequestedCommandHandlerMockAggregate(); mockAgg.setup_session_to_ensure_addAndCommit_are_called(); var testAgg = mockAgg.SetupAdminUser(); var testPermissionAgg = mockAgg.SetupTestPermission(); var handler = mockAgg.HandlerFactory(); var input = new RequestUserPermissionsDTO { ForId = testAgg.Id, ById = testAgg.Id, Requests = new Dictionary <Guid, PermissionDetails> { { testPermissionAgg.Id, new PermissionDetails { Reason = "testRequestReason" } } } }; var command = new UserPermissionsRequestedCommand(input); // Apply var result = await handler.Handle(command); Assert.True(mockAgg.SessionCommitWasCalled); mockAgg.setup_session_to_return_aggregate_with_requested_permission(testAgg, testPermissionAgg); var result2 = await handler.Handle(command); // Assert Assert.False(mockAgg.SessionCommitWasCalled); }
public void setup_dispatcher_to_verify_userPermissionsRequestedCommands_are_the_same(UserPermissionsRequestedCommand command) { CommandDispatcherMock.Setup(a => a.Execute(It.IsAny <UserPermissionsRequestedCommand>())) .Callback <ICommand <UserDTO> >((a) => { UserCommand = (UserPermissionsRequestedCommand)a; }) .ReturnsAsync(new UserDTO() { Id = command.Input.ForId, PermissionList = command.Input.Requests }); }