public async Task UpdateShouldSucceed() { // Arrange var id = Guid.NewGuid(); var name = "name"; var nameOnApplication = "nameOnApplication"; var description = "any"; var icon = Guid.NewGuid(); var information = RepositoryHelper.ForInformation.CreateInformation(id, name, nameOnApplication, description, icon); var tag = new Tag("tag"); information.AddTag(tag); // Act await _repository.UpdateAsync(information); // Assert var data = RepositoryHelper.ForInformation.GetInformations(); 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(UpdateInformationCommand request, CancellationToken cancellationToken) { Result result; try { var information = await _informationReadRepository.GetAsync(request.Id); if (information.Version != request.Version) { throw new CommandVersionException(); } var updatedInformation = new Information(request.Id, request.Name, request.NameOnApplication, request.Description, request.Icon); request.Tags.ToList().ForEach(x => updatedInformation.AddTag(new Tag(x))); updatedInformation.Version = _versionProvider.Generate(); await _informationWriteRepository.UpdateAsync(updatedInformation); result = Result.Ok(updatedInformation.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "Information"), 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.UpdateInformationFailure); } return(result); }