Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }