Exemple #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);
        }
Exemple #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);
        }
Exemple #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"));
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }