示例#1
0
        public async Task <UpdateUserInformationDTO> UpdateUser([FromBody] UpdateUserInformationDTO input)
        {
            var message = new UpdateSingleUserCommand(input.ForID, input);
            var result  = await _commandDispatcher.Execute(message);

            return(result);
        }
示例#2
0
        public async void given_update_user_command_command_dispatcher_should_get_same_command_created_in_controller()
        {
            //Assemble
            var mockAgg = new UserControllerMockAggregate();

            var id = new Guid();

            var input = new UpdateUserInformationDTO()
            {
                ForID     = id,
                FirstName = "testFName",
                LastName  = "testLName"
            };

            var command = new UpdateSingleUserCommand(input.ForID, input);

            mockAgg.setup_dispatcher_to_verify_updateUserInformationCommands_are_the_same(command);

            var controller = mockAgg.CreateUserController();

            //Apply
            var result = await controller.UpdateUser(input);

            //Assert
            Assert.IsType <UpdateUserInformationDTO>(result);
            Assert.Equal(result.FirstName, input.FirstName);
            Assert.Equal(result.LastName, input.LastName);
            Assert.Equal(result.ForID, input.ForID);
        }
示例#3
0
        public void given_UpdateSingleUserCommand_handler_should_call_session_get_and_commit()
        {
            // Assemble
            var mockAgg = new UpdateSingleUserCommandHandlerMockAggregate();

            mockAgg.setup_session_to_ensure_GetAndCommit_are_called();
            var handler = mockAgg.HandlerFactory();
            var testAgg = mockAgg.SetupAdminUser();

            var input = new UpdateUserInformationDTO
            {
                ForID      = testAgg.Id,
                FirstName  = "changed",
                LastName   = "changed",
                Email      = "changed",
                Position   = "changed",
                Department = "changed",
                IsAdmin    = false
            };
            var command = new UpdateSingleUserCommand(input.ForID, input);

            // Apply
            var result = handler.Handle(command);

            // Assert
            Assert.True(mockAgg.SessionGetWasCalled);
            Assert.True(mockAgg.SessionCommitWasCalled);
        }
示例#4
0
 public UserUpdatedEvent(UpdateUserInformationDTO dto)
 {
     FirstName  = dto.FirstName;
     LastName   = dto.LastName;
     Email      = dto.Email;
     Position   = dto.Position;
     Department = dto.Department;
     IsAdmin    = dto.IsAdmin;
 }
示例#5
0
        public void given_new_user_should_have_correct_values_after_UserUpdatedEvent()
        {
            // Assemble
            var agg = UserAggregateMockAggregate.SetupAdminUser();
            UpdateUserInformationDTO input = new UpdateUserInformationDTO
            {
                ForID      = agg.Id,
                FirstName  = "ChangedFName",
                LastName   = "ChangedLName",
                Email      = "ChangedEmail",
                Position   = "ChangedPosition",
                Department = "ChangedDepartment",
                IsAdmin    = false
            };


            // Apply
            agg.UpdateUserInfo(input);

            // Assert
            var changes = agg.FlushUncommitedChanges();

            Assert.Equal(2, changes.Length);
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <UserCreatedEvent>(e);
            },
                              (e) =>
            {
                Assert.IsType <UserUpdatedEvent>(e);
                var @event = (UserUpdatedEvent)e;
                Assert.Equal(2, @event.Version);
                Assert.NotEqual(Guid.Empty, @event.Id);

                Assert.Equal(@event.FirstName, agg.FirstName);
                Assert.Equal(@event.LastName, agg.LastName);
                Assert.Equal(@event.Email, agg.Email);
                Assert.Equal(@event.Position, agg.Position);
                Assert.Equal(@event.Department, agg.Department);
                Assert.Equal(@event.IsAdmin, agg.IsAdmin);
            });

            Assert.Equal(2, agg.Version);
            Assert.Equal(input.FirstName, agg.FirstName);
            Assert.Equal(input.LastName, agg.LastName);
            Assert.Equal(input.Email, agg.Email);
            Assert.Equal(input.Position, agg.Position);
            Assert.Equal(input.Department, agg.Department);
            Assert.Equal(input.IsAdmin, agg.IsAdmin);
        }
示例#6
0
 public void UpdateUserInfo(UpdateUserInformationDTO dto)
 {
     //business Logic here!
     ApplyChange(new UserUpdatedEvent(dto));
 }