public void SharedFund_InvalidRequired()
        {
            var sharedFund = new SharedFund();

            Assert.False(sharedFund.IsValid(out var validationErrors));
            Assert.NotNull(validationErrors);
            Assert.Equal(2, validationErrors.Count());
        }
        private Result Add(SharedFund sharedFund)
        {
            _sharedFundRepository.Setup(s => s.Insert(sharedFund));
            _sharedFundAppService =
                new SharedFundAppService(_sharedFundRepository.Object,
                                         _inflationAdjustService.Object, _employeeService.Object);

            return(_sharedFundAppService.Add(sharedFund));
        }
        public void SharedFund_Valid()
        {
            var sharedFund = new SharedFund
            {
                EmployeeId       = 1,
                ContributionDate = DateTime.Now
            };

            Assert.True(sharedFund.IsValid(out var validationErrors));
            Assert.NotNull(validationErrors);
        }
        public void SharedFundAppService_AddError()
        {
            var sharedFund = new SharedFund {
                EmployeeId = 1
            };
            var result = Add(sharedFund);

            Assert.NotNull(result);
            Assert.False(result.MessageErrors.Any());
            Assert.True(result.ValidationErrors.Any());
            Assert.Null(result.Return);
        }
        public async Task SharedFundController_Add()
        {
            var result     = new Result(1);
            var sharedFund = new SharedFund {
                EmployeeId = 1, Value = 200M, ContributionDate = DateTime.Now
            };

            _sharedFundAppService.Setup(s => s.Add(sharedFund)).Returns(result);
            _sharedFundController = new SharedFundController(_sharedFundAppService.Object);

            var objectResult = await _sharedFundController.Add(sharedFund);

            Assert.NotNull(objectResult);
            Assert.Equal((int)HttpStatusCode.OK, objectResult.StatusCode);
            Assert.Equal(result.Return, ((Result)objectResult.Value).Return);
        }
        public Result Add(SharedFund sharedFund)
        {
            if (!sharedFund.IsValid(out var validation))
            {
                return(new Result(validationErrors: validation));
            }

            sharedFund.Value = _employeeService.GetValueBySalary(sharedFund.EmployeeId, out var messagesErrors);
            if (messagesErrors != null && messagesErrors.Any())
            {
                return(new Result(messages: messagesErrors));
            }

            _sharedFundRepository.Insert(sharedFund);

            return(new Result(sharedFund.SharedFundId));
        }
        public void SharedFundAppService_AddOk()
        {
            var sharedFund = new SharedFund
            {
                SharedFundId     = 1,
                EmployeeId       = 1,
                ContributionDate = DateTime.Now
            };

            var result = Add(sharedFund);

            Assert.NotNull(result);
            Assert.NotNull(result.Return);
            Assert.False(result.MessageErrors.Any());
            Assert.False(result.ValidationErrors.Any());
            Assert.Equal(sharedFund.SharedFundId, result.Return.ToInt());
        }
Exemplo n.º 8
0
        private static List <ValidationError> Required(SharedFund sharedFund)
        {
            var validationErrors = new List <ValidationError>();

            if (!RequiredValidation.IsValid(sharedFund.EmployeeId))
            {
                validationErrors.Add(ValidationError.Create("EmployeeId", "EmployeeId is required"));
            }

            if (RequiredValidation.IsValid(sharedFund.Value))
            {
                validationErrors.Add(ValidationError.Create("Value", "Value will be created automatically"));
            }

            if (!RequiredValidation.IsValid(sharedFund.ContributionDate))
            {
                validationErrors.Add(ValidationError.Create("ContributionDate", "ContributionDate is required"));
            }

            return(validationErrors);
        }
        public Result Withdraw(int employeeId)
        {
            if (!_employeeService.CheckIfItBirthday(employeeId, out var messagesErrors))
            {
                return(new Result(messages: messagesErrors));
            }

            var balance = Balance(employeeId, out var releasedToCashOut);

            if (!releasedToCashOut)
            {
                return(new Result(messages: new List <string> {
                    "Cashout not available"
                }));
            }

            var toWithdraw = ToWithdraw(balance);
            var shareFund  = new SharedFund(employeeId, toWithdraw * -1, DateTime.Now);

            _sharedFundRepository.Insert(shareFund);

            return(new Result(toWithdraw));
        }
Exemplo n.º 10
0
 public void Insert(SharedFund sharedFund)
 {
     _context.Add(sharedFund);
     _context.SaveChanges();
 }
 public Task <ObjectResult> Add([FromBody] SharedFund sharedFund)
 {
     return(_sharedFundAppService.Add(sharedFund).TaskResult());
 }
Exemplo n.º 12
0
 public static bool IsValid(this SharedFund sharedFund, out List <ValidationError> validationErrors)
 {
     validationErrors = Required(sharedFund);
     return(!validationErrors.Any());
 }