public async Task <IActionResult> UpdateDetails([FromBody] UpdateLanguageDetails model) { model.SiteId = SiteId; await Task.Run(() => _commandSender.Send <UpdateLanguageDetails, Language>(model)); return(new NoContentResult()); }
public void Should_validate_command_and_save_new_language() { var command = new UpdateLanguageDetails { SiteId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "My Language", CultureName = "aa-bb", Url = "url" }; var languageRepositoryMock = new Mock <ILanguageRepository>(); languageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(new Language()); languageRepositoryMock.Setup(x => x.Update(It.IsAny <Language>())); var validatorMock = new Mock <IValidator <UpdateLanguageDetails> >(); validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult()); var createLanguageHandler = new UpdateLanguageDetailsHandler(languageRepositoryMock.Object, validatorMock.Object); createLanguageHandler.Handle(command); validatorMock.Verify(x => x.Validate(command)); languageRepositoryMock.Verify(x => x.Update(It.IsAny <Language>())); }
public void Should_throw_validation_exception_when_validation_fails() { var command = new UpdateLanguageDetails { SiteId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "My Language", CultureName = "aa-bb", Url = "url" }; var languageRepositoryMock = new Mock <ILanguageRepository>(); languageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(new Language()); var validatorMock = new Mock <IValidator <UpdateLanguageDetails> >(); validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> { new ValidationFailure("Name", "Name Error") })); var createLanguageHandler = new UpdateLanguageDetailsHandler(languageRepositoryMock.Object, validatorMock.Object); Assert.Throws <Exception>(() => createLanguageHandler.Handle(command)); }
public void UpdateDetails(UpdateLanguageDetails cmd, IValidator <UpdateLanguageDetails> validator) { validator.ValidateCommand(cmd); AddEvent(new LanguageDetailsUpdated { SiteId = SiteId, AggregateRootId = Id, Name = cmd.Name, CultureName = cmd.CultureName, Url = cmd.Url }); }
public void Setup() { _command = new UpdateLanguageDetails { SiteId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "My Language", CultureName = "aa-bb", Url = "url" }; _validatorMock = new Mock <IValidator <UpdateLanguageDetails> >(); _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult()); _language = new Language(); _language.UpdateDetails(_command, _validatorMock.Object); _event = _language.Events.OfType <LanguageDetailsUpdated>().SingleOrDefault(); }
public void Should_throw_exception_when_language_is_not_found() { var command = new UpdateLanguageDetails { SiteId = Guid.NewGuid(), Id = Guid.NewGuid(), Name = "My Language", CultureName = "aa-bb", Url = "url" }; var languageRepositoryMock = new Mock <ILanguageRepository>(); languageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns((Language)null); var validatorMock = new Mock <IValidator <UpdateLanguageDetails> >(); var createLanguageHandler = new UpdateLanguageDetailsHandler(languageRepositoryMock.Object, validatorMock.Object); Assert.Throws <Exception>(() => createLanguageHandler.Handle(command)); }
public IActionResult UpdateDetails([FromBody] UpdateLanguageDetails model) { model.SiteId = SiteId; _commandSender.Send <UpdateLanguageDetails, Language>(model); return(new NoContentResult()); }
public IActionResult UpdateDetails([FromBody] UpdateLanguageDetails model) { model.SiteId = SiteId; _dispatcher.SendAndPublish <UpdateLanguageDetails, Language>(model); return(new NoContentResult()); }