Ejemplo n.º 1
0
        public void GetTop_ShouldReturnInstanceOfIQueryable()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var paycheckService = new EmployeePaycheckService(mockedRepository.Object);

            var employee = new FakeEmployeePaycheck()
            {
                Id = 5
            };
            var employee2 = new FakeEmployeePaycheck()
            {
                Id = 6
            };
            var employee3 = new FakeEmployeePaycheck()
            {
                Id = 7
            };

            // Act
            paycheckService.Create(employee);
            paycheckService.Create(employee2);
            paycheckService.Create(employee3);

            var query = paycheckService.GetTop(3);

            // Assert
            Assert.IsInstanceOf <IQueryable <EmployeePaycheck> >(query);
        }
Ejemplo n.º 2
0
        public void GetTop_ShouldInvokeOnlyOnce()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var paycheckService = new EmployeePaycheckService(mockedRepository.Object);

            var employee = new FakeEmployeePaycheck()
            {
                Id = 1
            };
            var employee2 = new FakeEmployeePaycheck()
            {
                Id = 2
            };
            var employee3 = new FakeEmployeePaycheck()
            {
                Id = 3
            };

            // Act
            paycheckService.Create(employee);
            paycheckService.Create(employee2);
            paycheckService.Create(employee3);

            paycheckService.GetTop(3);

            // Assert
            mockedRepository.Verify(r => r.All, Times.Once);
        }
Ejemplo n.º 3
0
        public void Create_ShouldThrowArgumentNullException_WhenParameterIsNull()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var paycheckService = new EmployeePaycheckService(mockedRepository.Object);

            // Act & Assert
            Assert.That(() => paycheckService.Create(null), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains("The argument is null"));
        }
Ejemplo n.º 4
0
        public void Constructor_ShouldCreateInstance_WhenParameterIRepositoryIsPassedCorrectly()
        {
            // Arrange
            var repo = new Mock <IRepository <EmployeePaycheck> >();

            // Act
            var paycheckService = new EmployeePaycheckService(repo.Object);

            // Assert
            Assert.IsInstanceOf <IEmployeePaycheckService>(paycheckService);
        }
Ejemplo n.º 5
0
        public void Create_ShouldInvokeOnce_WhenParameterIsCorrect()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var paycheckService = new EmployeePaycheckService(mockedRepository.Object);

            var paycheck = new FakeEmployeePaycheck();

            // Act
            paycheckService.Create(paycheck);

            // Assert
            mockedRepository.Verify(r => r.Add(paycheck), Times.Once);
        }
Ejemplo n.º 6
0
        public void Delete_ShouldInvokeOnce_WhenValidId_IsPassedCorrectly()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var paycheckService = new EmployeePaycheckService(mockedRepository.Object);

            EmployeePaycheck employee = new FakeEmployeePaycheck();

            employee.Id = 2;

            // Act
            paycheckService.Create(employee);
            paycheckService.DeleteById(2);

            // Assert
            mockedRepository.Verify(r => r.Delete(It.IsAny <int>()), Times.Once);
        }
Ejemplo n.º 7
0
        public void Update_ShouldUpdateEmployeeCorrectly()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var emplPaycheckService = new EmployeePaycheckService(mockedRepository.Object);

            EmployeePaycheck paycheck = new FakeEmployeePaycheck();

            paycheck.Id = 2;

            // Act
            emplPaycheckService.Create(paycheck);

            emplPaycheckService.UpdateById(2, paycheck);

            // Assert
            mockedRepository.Verify(x => x.Update(paycheck), Times.Once);
        }
Ejemplo n.º 8
0
        public void GetById_ShouldInvokeOnlyOnce()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <EmployeePaycheck> >();

            var paycheckService = new EmployeePaycheckService(mockedRepository.Object);

            var paycheck = new FakeEmployeePaycheck();

            paycheck.Id = 2;

            // Act
            paycheckService.Create(paycheck);

            paycheckService.GetById(paycheck.Id);

            // Assert
            mockedRepository.Verify(r => r.GetById(paycheck.Id), Times.Once);
        }
Ejemplo n.º 9
0
        public void CreateInstance_WhenAllParametersArePassedCorrectly()
        {
            // Arrange
            ISalaryCalculatorDbContext dbContext = new SalaryCalculatorDbContext();

            IRepository <User>             userRepo     = new SalaryCalculatorRepository <User>(dbContext);
            IRepository <EmployeePaycheck> paycheckRepo = new SalaryCalculatorRepository <EmployeePaycheck>(dbContext);
            IRepository <RemunerationBill> billRepo     = new SalaryCalculatorRepository <RemunerationBill>(dbContext);
            IRepository <SelfEmployment>   selfRepo     = new SalaryCalculatorRepository <SelfEmployment>(dbContext);

            ICacheService            cacheService          = new HttpCacheService();
            IUserService             userService           = new UserService(userRepo);
            IEmployeePaycheckService paycheckService       = new EmployeePaycheckService(paycheckRepo);
            IRemunerationBillService billService           = new RemunerationBillService(billRepo);
            ISelfEmploymentService   selfEmploymentService = new SelfEmploymentService(selfRepo);

            // Act & Assert
            Assert.IsInstanceOf <HomeController>(new HomeController(cacheService, userService, paycheckService, billService, selfEmploymentService));
        }