public async Task Update_language() { var mockService = new Mock <ISimpleDomainService <Language, LanguageId> >(); var lookupServiceMock = new Mock <ILanguageLookupDataService>(); var cmd = new Commands.Update { Id = Guid.NewGuid(), Name = "Gibberish" }; var languageController = new LanguageController(mockService.Object, lookupServiceMock.Object); var result = await languageController.Put(cmd); mockService.Verify(x => x.Handle(cmd), Times.Once()); ((OkResult)result).StatusCode.Should().Be(200); }
public async Task Update_Language_Fails() { var mockService = new Mock <ISimpleDomainService <Language, LanguageId> >(); var lookupServiceMock = new Mock <ILanguageLookupDataService>(); var cmd = new Commands.Update { Id = Guid.NewGuid(), Name = "Gibberish" }; mockService.Setup(s => s.Handle(cmd)) .Returns(() => Task.FromException(new Exception())); var languageController = new LanguageController(mockService.Object, lookupServiceMock.Object); Func <Task> action = async() => await languageController.Put(cmd); action.Should().Throw <Exception>(); mockService.Verify(x => x.Handle(cmd), Times.Once()); }
public async Task <IActionResult> Put(Commands.Update request) => await RequestHandler.HandleCommand(request, _service.Handle);