public async Task GetByIdShouldSucceed() { // Arrange var id = Guid.NewGuid(); var name = "name"; RepositoryHelper.ForOperation.CreateOperation(id, name); // Act var result = await _repository.GetAsync(id); // Assert result.Should().NotBeNull(); }
public async Task <Result> Handle(GetOperationQuery request, CancellationToken cancellationToken) { Result result; try { var operation = await _operationReadRepository.GetAsync(request.Id); var operationModel = _mapper.Map <OperationModel>(operation); if (operation.Icon != null) { var icon = await _iconReadRepository.GetAsync(operation.Icon.IconId); if (icon != null) { operationModel.Icon.DataPath = icon.DataPath; } } result = Result.Ok(operationModel, operation.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "Operation"), Target = "id" } } ); } catch { result = Result.Fail(CustomFailures.GetOperationFailure); } return(result); }
public async Task <Result> Handle(UpdateOperationCommand request, CancellationToken cancellationToken) { Result result; try { var operation = await _operationReadRepository.GetAsync(request.Id); if (operation.Version != request.Version) { throw new CommandVersionException(); } //var coloredIcon = new ColoredIcon(command.Icon.IconId, command.Icon.FillColor); if (request.Name.HasValue) { operation.ChangeName(request.Name.Value); } if (request.Description.HasValue) { operation.SetDescription(request.Description.Value); } if (request.Tags.HasValue) { var tags = request.Tags.Value ?? new List <string>(); operation.ClearTags(); foreach (var tag in tags) { operation.AddTag(new Tag(tag)); } } operation.Version = _versionProvider.Generate(); await _operationWriteRepository.UpdateAsync(operation); result = Result.Ok(operation.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new System.Collections.Generic.List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "Operation"), 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.UpdateOperationFailure); } return(result); }