Esempio n. 1
0
        public async Task <Result> Handle(DeleteOperatorCommand command, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                IEnumerable <Team> teams = await _teamReadRepository.ListAsync(string.Format("members/id eq '{0}'", command.Id), null, null);

                foreach (var item in teams)
                {
                    item.RemoveMember(command.Id);
                    await _teamWriteRepository.UpdateAsync(item);
                }

                await _operatorWriteRepository.DeleteAsync(command.Id, 0);

                return(Result.Ok());
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = HandlerFailures.OperatorNotFound,
                        Target  = "id"
                    }
                });
            }
            catch (EntityVersionDbException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                });
            }
            catch
            {
                result = Result.Fail(CustomFailures.DeleteOperatorFailure);
            }

            return(result);
        }
Esempio n. 2
0
        public async Task DeleteShouldSucceed()
        {
            // Arrange
            var operatorId  = Guid.NewGuid();
            var uniqueLogin = Guid.NewGuid().ToString();
            var firstName   = "anyFirstName";
            var lastName    = "anyLastName";

            var newOperator = RepositoryHelper.ForOperator.CreateOperator(operatorId, uniqueLogin, firstName, lastName);

            // Act
            await _repository.DeleteAsync(operatorId, 0);

            // Assert
            var data = RepositoryHelper.ForOperator.GetOperators();

            data.Should().HaveCount(0);
        }