public async Task UpdateShouldSucceed() { // Arrange var id = Guid.NewGuid(); var name = "name"; var description = "description"; var icon = Guid.NewGuid(); var instruction = "instruction"; var input = RepositoryHelper.ForInput.CreateInput(id, name, description, icon, instruction); var tag = new Tag("tag"); input.AddTag(tag); // Act await _repository.UpdateAsync(input); // Assert var data = RepositoryHelper.ForInput.GetInputs(); data.Should().HaveCount(1); var result = data.First(); result.Should().NotBeNull(); result.Tags.Should().HaveCount(1); result.Tags.First().Should().Be(tag); }
public async Task <Result> Handle(UpdateInputCommand request, CancellationToken cancellationToken) { Result result; try { var input = await _inputReadRepository.GetAsync(request.Id); if (input.Version != request.Version) { throw new CommandVersionException(); } var updatedInput = new Input(request.Id, request.Name, request.Description, request.Icon, request.Instruction); foreach (var image in request.Images) { updatedInput.AddImage(new Image(image.Name, "some image url")); } foreach (var video in request.Videos) { updatedInput.AddVideo(new Video(video.Name, "some image url")); } foreach (var tag in request.Tags) { updatedInput.AddTag(new Tag(tag)); } updatedInput.Version = _versionProvider.Generate(); await _inputWriteRepository.UpdateAsync(updatedInput); result = Result.Ok(updatedInput.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "Input"), Target = "id" } } ); } catch (CommandVersionException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotMet.Name, Message = HandlerFailures.NotMet, Target = "version" } } ); } catch (UniqueKeyException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.Conflict, Target = "name" } } ); } catch { result = Result.Fail(CustomFailures.UpdateInputFailure); } return(result); }