public JsonResult Create(BonusDto bonusDto)
        {
            BonusAggregate bonus;

            if (bonusDto.Amount <= 0)
                throw new ArgumentOutOfRangeException("Amount should be more than 0");

            if (bonusDto.EmployeeId <= 0)
                throw new ArgumentNullException("You should specify an existing employee");

            using (var dbContext = new DatabaseContext())
            {
                BonusesRepository = new BonusesRepository(dbContext);
                var employeeRepository = new EmployeesRepository(dbContext);
                bonus = new BonusFactory(employeeRepository).Create(bonusDto);

                BonusesRepository.Save(bonus);
            }

            return Json(bonus);
        }
Пример #2
0
        /// <summary>
        /// Creates the bonuses mock.
        /// </summary>
        private PagedResponse<BonusAggregate> CreateMockBonuses()
        {
            var factory = new BonusFactory(EmployeeRepositoryMock.Object);
            var bonuses = new List<BonusAggregate>
                                    {
                                        factory.Create(new Employee("name1", "lastname1", "ukr1"), DateTime.Now, 100),
                                        factory.Create(new Employee("name2", "lastname2", "ukr2"), DateTime.Now, 200)
                                    };

            return new PagedResponse<BonusAggregate>(bonuses, 2);
        }
        public void Save_BonusesList_2BonusesAdded()
        {
            int numberOfItemsBeforSave;

            int numberOfCurrentBonuses;
            using (var dbContext = new DatabaseContext(TestUser, TestPass))
            {
                bonusFactory = new BonusFactory(new EmployeesRepository(dbContext));
                var bonusesList = new List<BonusAggregate>
                                        {
                                          bonusFactory.Create(GetEmployeeById(4), DateTime.Now, 100),
                                          bonusFactory.Create(GetEmployeeById(5), DateTime.Now, 90)
                                        };

                bonusRepository = new BonusesRepository(dbContext);
                numberOfItemsBeforSave = bonusRepository.FindAll().Count();
                bonusRepository.Save(bonusesList);
                numberOfCurrentBonuses = bonusRepository.FindAll().Count();
            }

            Assert.AreEqual(numberOfCurrentBonuses - 2, numberOfItemsBeforSave);
        }