public async Task <Result> Handle(CreateOperatorCommand command, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var operatorToCreate = new Operator(command.Id,
                                                    command.Login,
                                                    command.FirstName,
                                                    command.LastName);

                await _operatorWriteRepository.CreateAsync(operatorToCreate);

                return(Result.Ok());
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.ConflictOperator,
                        Target  = "login"
                    }
                });
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateOperatorFailure);
            }

            return(result);
        }
Beispiel #2
0
        public async Task CreateShouldSucceed()
        {
            // Arrange
            var operatorId  = Guid.NewGuid();
            var uniqueLogin = Guid.NewGuid().ToString();
            var newOperator = new Operator(operatorId, uniqueLogin, "anyFirstName", "anyLastName");

            // Act
            await _repository.CreateAsync(newOperator);

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

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


            result.Id.Should().Be(operatorId);
            result.Login.Should().Be(uniqueLogin);
            result.LastName.Should().Be("anyLastName");
            result.FirstName.Should().Be("anyFirstName");
        }