public void Should_validate_command_and_update_page() { var command = new UpdatePageDetails { SiteId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "Name", Url = "url", Title = "Title", MetaDescription = "Meta Description", MetaKeywords = "Meta Keywords" }; var repositoryMock = new Mock <IPageRepository>(); repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(new Page()); var validatorMock = new Mock <IValidator <UpdatePageDetails> >(); validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult()); var createPageHandler = new UpdatePageDetailsHandler(repositoryMock.Object, validatorMock.Object); createPageHandler.Handle(command); validatorMock.Verify(x => x.Validate(command)); repositoryMock.Verify(x => x.Update(It.IsAny <Page>())); }
public void Should_throw_validation_exception_when_validation_fails() { var command = new UpdatePageDetails { SiteId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "Name", Url = string.Empty, Title = "Title", MetaDescription = "Meta Description", MetaKeywords = "Meta Keywords" }; var repositoryMock = new Mock <IPageRepository>(); repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(new Page()); var validatorMock = new Mock <IValidator <UpdatePageDetails> >(); validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> { new ValidationFailure("Url", "Url Error") })); var createPageHandler = new UpdatePageDetailsHandler(repositoryMock.Object, validatorMock.Object); Assert.Throws <ValidationException>(() => createPageHandler.Handle(command)); }