Example #1
0
        public void IsValid_ShouldBeFalse_WhenRequiredFieldsAreNotSet()
        {
            var command = new UpdateGuestCommand();

            var validator = new UpdateGuestCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
Example #2
0
        public async Task <ActionResult> Update(long id, UpdateGuestCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Example #3
0
        public void Handle_GivenInvalidId_ThrowsException()
        {
            var command = new UpdateGuestCommand
            {
                Id        = 99,
                FirstName = "Test FirstName Update",
                LastName  = "Test LastName Update",
                Email     = "Test Email Update"
            };

            var handler = new UpdateGuestCommand.UpdateGuestCommandHandler(Context);

            Should.ThrowAsync <NotFoundException>(() =>
                                                  handler.Handle(command, CancellationToken.None));
        }
Example #4
0
        public void IsValid_ShouldBeTrue_WhenRequiredFieldsAreSet()
        {
            var command = new UpdateGuestCommand
            {
                Id        = 1,
                FirstName = "Test FirstName Update",
                LastName  = "Test LastName Update",
                Email     = "Test Email Update"
            };

            var validator = new UpdateGuestCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }
Example #5
0
        public async Task GivenValidUpdateGuestCommand_ReturnsSuccessCode()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new UpdateGuestCommand
            {
                Id        = 1,
                FirstName = "Test FirstName Update",
                LastName  = "Test LastName Update",
                Email     = "Test Email Update"
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PutAsync($"/api/Guest/{command.Id}", content);

            response.EnsureSuccessStatusCode();
        }
Example #6
0
        public async Task Handle_GivenValidId_ShouldUpdatePersistedGuest()
        {
            var command = new UpdateGuestCommand
            {
                Id        = 1,
                FirstName = "Test FirstName Update",
                LastName  = "Test LastName Update",
                Email     = "Test Email Update"
            };

            var handler = new UpdateGuestCommand.UpdateGuestCommandHandler(Context);

            await handler.Handle(command, CancellationToken.None);

            var entity = Context.Guests.Find(command.Id);

            entity.ShouldNotBeNull();
            entity.FirstName.ShouldBe(command.FirstName);
            entity.LastName.ShouldBe(command.LastName);
            entity.Email.ShouldBe(command.Email);
        }