public void IsValid_ShouldBeFalse_WhenRequiredFieldsAreNotSet()
        {
            var command = new UpdateEmailLogCommand();

            var validator = new UpdateEmailLogCommandValidator(Context);

            var result = validator.Validate(command);

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

            await Mediator.Send(command);

            return(NoContent());
        }
        public void Handle_GivenInvalidId_ThrowsException()
        {
            var command = new UpdateEmailLogCommand
            {
                Id       = 99,
                EmailId  = 1,
                SentDate = DateTime.Now,
                SentBy   = "UnitTest"
            };

            var handler = new UpdateEmailLogCommand.UpdateEmailLogCommandHandler(Context);

            Should.ThrowAsync <NotFoundException>(() =>
                                                  handler.Handle(command, CancellationToken.None));
        }
        public void IsValid_ShouldBeTrue_WhenRequiredFieldsAreSet()
        {
            var command = new UpdateEmailLogCommand
            {
                Id       = 1,
                EmailId  = 1,
                SentDate = DateTime.Now,
                SentBy   = "UnitTest"
            };

            var validator = new UpdateEmailLogCommandValidator(Context);

            var result = validator.Validate(command);

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

            var command = new UpdateEmailLogCommand
            {
                Id       = 1,
                EmailId  = 1,
                SentDate = DateTime.Now,
                SentBy   = "Unit Test Update"
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

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

            response.EnsureSuccessStatusCode();
        }
        public async Task Handle_GivenValidId_ShouldUpdatePersistedEmailLog()
        {
            var command = new UpdateEmailLogCommand
            {
                Id       = 1,
                EmailId  = 1,
                SentDate = DateTime.Now,
                SentBy   = "UnitTest"
            };

            var handler = new UpdateEmailLogCommand.UpdateEmailLogCommandHandler(Context);

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

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

            entity.ShouldNotBeNull();
            entity.EmailId.ShouldBe(command.EmailId);
            entity.SentDate.ShouldBe(command.SentDate);
            entity.SentBy.ShouldBe(command.SentBy);
        }