public async Task GetByIdShouldSucceed()
        {
            // Arrange
            var                  id   = Guid.NewGuid();
            var                  name = "name";
            var                  nameOnApplication = "nameOnApplication";
            string               description       = "description";
            RemarkIcon           icon           = new RemarkIcon(Guid.NewGuid());
            List <DefaultRemark> defaultRemarks = new List <DefaultRemark>()
            {
                new DefaultRemark("defaultRemark1"), new DefaultRemark("defaultRemark2")
            };
            List <Tag> tags = new List <Tag>()
            {
                new Tag("tag1"), new Tag("tag2")
            };

            RepositoryHelper.ForRemark.CreateRemark(id, name, nameOnApplication, description, icon, defaultRemarks, tags);

            // Act
            var result = await _repository.GetAsync(id);

            // Assert
            result.Should().NotBeNull();
            result.Name.Should().Be(name);
            result.Description.Should().Be(description);
            result.Icon.Should().Be(icon);
            result.Tags.Should().AllBeOfType <Tag>();
            result.DefaultRemarks.Should().AllBeOfType <DefaultRemark>();
        }
        public async Task <Result> Handle(GetRemarkQuery request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var remark = await _remarkReadRepository.GetAsync(request.Id);

                var remarkModel = _mapper.Map <RemarkModel>(remark);

                result = Result.Ok(remarkModel, remark.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Remark"),
                        Target  = "id"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.GetRemarkFailure);
            }

            return(result);
        }
Beispiel #3
0
        public async Task <Result> Handle(UpdateRemarkCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var icon = await _remarkReadRepository.GetAsync(request.Id);

                if (icon.Version != request.Version)
                {
                    throw new CommandVersionException();
                }

                var updatedRemark = new Remark(request.Id, request.Name, request.NameOnApplication, request.Description, new RemarkIcon(request.Icon));
                request.Tags.ToList().ForEach(x => updatedRemark.AddTag(new Tag(x)));
                request.DefaultRemarks.ToList().ForEach(x => updatedRemark.AddDefaultRemark(new DefaultRemark(x)));

                updatedRemark.Version = _versionProvider.Generate();
                await _remarkWriteRepository.UpdateAsync(updatedRemark);

                result = Result.Ok(updatedRemark.Version);
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = string.Format(HandlerFailures.NotFound, "Remark"),
                        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.UpdateRemarkFailure);
            }

            return(result);
        }