예제 #1
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));
        }
        public void ReturnCreateLaborContractViewModel_WhenModelStateIsNotValid()
        {
            // 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>();

            nonLaborContractModel.SetupProperty(x => x.GrossSalary, 1000);

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

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

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

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

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

            // Assert
            Assert.IsInstanceOf <ViewResult>(result);
            Assert.AreEqual(nonLaborContractModel.Object, result.Model);
        }
예제 #3
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);
        }
예제 #4
0
        public void ReturnHttpNotFoundResult_WhenEmployeeIsNull()
        {
            // 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 = null;

            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 <HttpNotFoundResult>(nonLaborController.Delete(id, nonLaborContractModel));
        }
예제 #5
0
        public void ReturnRedirectToRouteResult_WhenPassedIdIsCorrect()
        {
            // 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>();

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

            var result = nonLaborController.DeleteConfirmed(id, nonLaborContractModel.Object);

            // Assert
            Assert.IsInstanceOf <RedirectToRouteResult>(result);
        }
        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);
        }
예제 #7
0
        public void HttpGet_ReturnHttpNotFoundResult_WhenPaycheckIsNull()
        {
            // 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>();

            RemunerationBill mockedBill = null;

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

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

            Assert.IsInstanceOf <HttpNotFoundResult>(nonLaborController.Edit(id, mockedBill));
        }
예제 #8
0
        public void HttpPost_ReturnPreviewRemunerationBillViewModel_WhenModelState_IsNotValid()
        {
            // Arrange
            var mapService          = new Mock <IMapService>();
            var employeeService     = new Mock <IEmployeeService>();
            var billService         = new Mock <IRemunerationBillService>();
            var payrollCalculations = new Mock <Payroll>();

            var nonLaborContractModel = new Mock <PreviewRemunerationBillViewModel>();

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

            nonLaborController.ModelState.AddModelError("Invalid", "Invalid");

            var result = nonLaborController.Edit(nonLaborContractModel.Object) as ViewResult;

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