示例#1
0
        public void GetTop_ShouldInvokeOnlyOnce()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <RemunerationBill> >();

            var billService = new RemunerationBillService(mockedRepository.Object);

            RemunerationBill mockedBill  = new FakeRemunerationBill();
            RemunerationBill mockedBill2 = new FakeRemunerationBill();
            RemunerationBill mockedBill3 = new FakeRemunerationBill();

            mockedBill.Id  = 2;
            mockedBill2.Id = 3;
            mockedBill3.Id = 4;

            // Act
            billService.Create(mockedBill);
            billService.Create(mockedBill2);
            billService.Create(mockedBill3);

            billService.GetTop(3);

            // Assert
            mockedRepository.Verify(r => r.All, Times.Once);
        }
示例#2
0
        public void GetTop_ShouldReturnInstanceOfIQueryable()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <RemunerationBill> >();

            var billService = new RemunerationBillService(mockedRepository.Object);

            RemunerationBill mockedBill  = new FakeRemunerationBill();
            RemunerationBill mockedBill2 = new FakeRemunerationBill();
            RemunerationBill mockedBill3 = new FakeRemunerationBill();

            mockedBill.Id  = 2;
            mockedBill2.Id = 3;
            mockedBill3.Id = 4;

            // Act
            billService.Create(mockedBill);
            billService.Create(mockedBill2);
            billService.Create(mockedBill3);

            var query = billService.GetTop(3);

            // Assert
            Assert.IsInstanceOf <IQueryable <RemunerationBill> >(query);
        }
示例#3
0
        public void ReturnViewResult_WhenIdIsCorrect()
        {
            // Arrange
            var mapService          = new Mock <IMapService>();
            var employeeService     = new Mock <IEmployeeService>();
            var billService         = new Mock <IRemunerationBillService>();
            var payrollCalculations = new Mock <Payroll>();

            var id = 5;
            RemunerationBill nonLaborContractModel = new FakeRemunerationBill()
            {
                Id                   = id,
                GrossSalary          = 1000,
                SocialSecurityIncome = 1110,
                PersonalInsurance    = 50,
            };

            billService.Setup(x => x.GetById(id)).Returns(nonLaborContractModel).Verifiable();

            // Act
            var nonLaborController = new NonLaborContractController(mapService.Object, employeeService.Object, billService.Object, payrollCalculations.Object);

            // Assert
            Assert.IsInstanceOf <ViewResult>(nonLaborController.Delete(id, nonLaborContractModel));
        }
示例#4
0
        public void Create_ShouldInvokeOnce_WhenParameterIsCorrect()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <RemunerationBill> >();

            var billService = new RemunerationBillService(mockedRepository.Object);

            var mockedBill = new FakeRemunerationBill();

            // Act
            billService.Create(mockedBill);

            // Assert
            mockedRepository.Verify(r => r.Add(mockedBill), Times.Once);
        }
示例#5
0
        public void HttpGet_ReturnPreviewRemunerationBillViewModel_WhenPaycheckIsNotNull()
        {
            // Arrange
            var mapService          = new Mock <IMapService>();
            var employeeService     = new Mock <IEmployeeService>();
            var billService         = new Mock <IRemunerationBillService>();
            var payrollCalculations = new Mock <Payroll>();

            var id = 5;
            var nonLaborContractModel = new Mock <PreviewRemunerationBillViewModel>();

            var      employeeId     = 10;
            Employee mockedEmployee = new FakeEmployee()
            {
                Id         = employeeId,
                FirstName  = "Georgi",
                MiddleName = "Georgiev",
                LastName   = "Georgiev",
                PersonalId = "8010104050"
            };

            RemunerationBill mockedBill = new FakeRemunerationBill()
            {
                Id                   = id,
                GrossSalary          = 1000,
                SocialSecurityIncome = 670,
                PersonalInsurance    = 125,
                IncomeTax            = 90,
                NetWage              = 750,
                Employee             = mockedEmployee,
                EmployeeId           = mockedEmployee.Id
            };

            employeeService.Setup(x => x.GetById(10)).Returns(mockedEmployee).Verifiable();
            billService.Setup(x => x.GetById(id)).Returns(mockedBill).Verifiable();
            mapService.Setup(x => x.Map <PreviewRemunerationBillViewModel>(mockedBill)).Returns(new PreviewRemunerationBillViewModel()
            {
                Id = id, EmployeeId = employeeId
            }).Verifiable();
            // Act
            var nonLaborController = new NonLaborContractController(mapService.Object, employeeService.Object, billService.Object, payrollCalculations.Object);
            var result             = nonLaborController.Edit(id, mockedBill) as ViewResult;

            // Assert
            Assert.IsInstanceOf <PreviewRemunerationBillViewModel>(result.Model);
        }
        public void Delete_ShouldInvokeOnce_WhenValidId_IsPassedCorrectly()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <RemunerationBill> >();

            var billService = new RemunerationBillService(mockedRepository.Object);

            RemunerationBill bill = new FakeRemunerationBill();

            bill.Id = 2;

            // Act
            billService.Create(bill);
            billService.DeleteById(2);

            // Assert
            mockedRepository.Verify(r => r.Delete(It.IsAny <int>()), Times.Once);
        }
        public void GetById_ShouldInvokeOnlyOnce()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <RemunerationBill> >();

            var billService = new RemunerationBillService(mockedRepository.Object);

            var mockedBill = new FakeRemunerationBill();

            mockedBill.Id = 2;

            // Act
            billService.Create(mockedBill);

            billService.GetById(mockedBill.Id);

            // Assert
            mockedRepository.Verify(r => r.GetById(mockedBill.Id), Times.Once);
        }
        public void ReturnCreateRemunerationBillViewModel_WhenActionIsCalled()
        {
            // Arrange
            var mapService          = new Mock <IMapService>();
            var employeeService     = new Mock <IEmployeeService>();
            var billService         = new Mock <IRemunerationBillService>();
            var payrollCalculations = new Mock <Payroll>();

            var id = 5;

            Employee mockedEmployee = new FakeEmployee()
            {
                Id         = id,
                FirstName  = "Alexander",
                MiddleName = "Petrov",
                LastName   = "Vasilev",
                PersonalId = "8010107070"
            };

            RemunerationBill mockedBill = new FakeRemunerationBill()
            {
                Id         = 1,
                EmployeeId = id,
                Employee   = mockedEmployee
            };

            employeeService.Setup(x => x.GetById(id)).Returns(mockedEmployee).Verifiable();

            var nonLaborContractModel = new CreateRemunerationBillViewModel();

            mapService.Setup(x => x.Map <CreateRemunerationBillViewModel>(mockedBill)).Returns(nonLaborContractModel).Verifiable();

            // Act
            NonLaborContractController laborController = new NonLaborContractController(mapService.Object, employeeService.Object, billService.Object, payrollCalculations.Object);

            laborController.ModelState.AddModelError("invalid", "Invalid");

            var result = laborController.CreateNonLaborContract(id, mockedBill) as ViewResult;

            // Assert
            Assert.IsInstanceOf <ViewResult>(result);
            Assert.AreEqual(nonLaborContractModel, result.Model);
        }