public async Task GivenValidContractWhenAddingThenContractIsAdded()
        {
            var contract = new DtoContract { Name = "C1", Type = ContractType.Developer, Experience = 3, Salary = 5375 };
            var mock = new Mock<IRepository<Contract>>();
            IContractService service = new ContractService(mock.Object, new DefaultSalaryPolicy(), new DefaultSalaryCalculator());

            var expected = true;
            var actual = await service.CreateContractAsync(contract);

            mock.Verify(m => m.Add(It.IsAny<Contract>()), Times.Once());
            mock.Verify(m => m.SaveChangesAsync(), Times.Once());

            Assert.AreEqual(expected, actual);
        }
        public async Task GivenInvalidContractWhenAddingThenContractIsNotAdded()
        {
            var contract = new DtoContract { Experience = 1 };
            var mock = new Mock<IRepository<Contract>>();
            IContractService service = new ContractService(mock.Object, new DefaultSalaryPolicy(), new DefaultSalaryCalculator());

            var expected = false;
            var actual = await service.CreateContractAsync(contract);

            mock.Verify(m => m.Add(It.IsAny<Contract>()), Times.Never());
            mock.Verify(m => m.SaveChangesAsync(), Times.Never());

            Assert.AreEqual(expected, actual);
        }
        public async Task<bool> CreateContractAsync(DtoContract contract)
        {
            var validator = new ContractValidator(this.policy, this.calculator);
            var result = validator.Validate(contract);
            if (!result.IsValid)
            {
                return false;
            }

            var entity = Mapper.Map<Contract>(contract);
            this.contractRepository.Add(entity);
            await this.contractRepository.SaveChangesAsync();

            return true;
        }