public async Task UpdateShouldSucceed()
        {
            // Arrange
            var id   = Guid.NewGuid();
            var name = "name";

            var businessUnit = RepositoryHelper.ForBusinessUnit.CreateBusinessUnit(id, name);

            var otherName = "nameUpdated";

            businessUnit.ChangeName(otherName);

            // Act
            await _repository.UpdateAsync(businessUnit);

            // Assert
            var data = RepositoryHelper.ForBusinessUnit.GetBusinessUnits();

            data.Should().HaveCount(1);
            var result = data.First();

            result.Should().NotBeNull();
            result.Id.Should().Be(id);
            result.Name.Should().Be(otherName);
        }
        public async Task <Result> Handle(UpdateBusinessUnitCommand request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var businessUnit = await _businessUnitReadRepository.GetAsync(request.Id);

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

                if (request.Name.HasValue)
                {
                    businessUnit.ChangeName(request.Name.Value);
                }

                businessUnit.Version = _versionProvider.Generate();
                await _businessUnitWriteRepository.UpdateAsync(businessUnit);

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

            return(result);
        }