Example #1
0
        public void TestGetDetailsReturnsView()
        {
            mockUnitOfWork.Setup(m => m.EmployeeRepository.GetByID(0)).Returns(employees[0]);
            var result = controller.Details(0) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Details", result.ViewName);
        }
Example #2
0
        public async Task DetailsGetAction_GetModelFromService()
        {
            // Arrange

            // Act
            var result = await validController.Details(entity.Id);

            // Assert
            mock.Verify(a => a.GetAsync(entity.Id, false));
        }
        public async Task Details_IfIdIsNullOrNotExist_ReturnNotFound(int?id)
        {
            // Arrange
            repository.Setup(r => r.GetEmployeeAsync(1)).ReturnsAsync(employee);

            // Act
            var result = await controller.Details(id);

            // Assert
            Assert.That(result, Is.InstanceOf <NotFoundResult>());
        }
Example #4
0
        public void Details_WhenCalled_ReturnView()
        {
            var result = controller.Details();

            Assert.That(result.ViewName, Is.EqualTo(string.Empty));
            Assert.That(result, Is.TypeOf(typeof(ViewResult)));
        }
        public void TestDetail_ShouldShowCurrentAndProjectedBonusesForEmployeeMakingMoreThan100K_FY18()
        {
            //AAA
            //Arrange
            EmployeesController controllerUnderTest = new EmployeesController(mockUnitOfWork.Object, mockBonusProjector.Object);
            string employeeTestName     = "Test Employee " + DateTime.Now.ToLongTimeString();
            var    employeeToUseForTest = mockUnitOfWork.Object.DbContext.Employees.Where(e => e.Salary >= 100000).FirstOrDefault();

            mockUnitOfWork.Object.DbContext.Employees.Add(employeeToUseForTest);
            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => { return(DateTime.Parse("07/02/2017")); };
            }
            var bonusCalculator = new FY18BonusCalculator();

            //Act
            var returnedResult = controllerUnderTest.Details(employeeToUseForTest.Id).Result;

            Assert.AreEqual(returnedResult.GetType(), typeof(ViewResult));
            var returnedView = returnedResult as ViewResult;

            //Assert
            Assert.AreEqual(typeof(FY18BonusCalculator), controllerUnderTest.bonusCalculator.GetType());
            Assert.AreEqual(returnedView.ViewBag.BonusAmount, bonusCalculator.GetBonusPercentage(employeeToUseForTest) * employeeToUseForTest.Salary / 100);
            Assert.AreEqual(returnedView.ViewBag.NextYearProjectBonus, mockBonusProjector.Object.GetExpectedBonus(employeeToUseForTest.Salary));
        }
        public void TestDetailsView()
        {
            var employeesCorntorller = new EmployeesController();
            var result = employeesCorntorller.Details(1) as ViewResult;

            Assert.AreEqual("Details", result.ViewName);
        }
Example #7
0
        public void ReturnHttpNotFoundResult_WhenEmployeeIsNull()
        {
            // Arrange
            var mockedMappService = new Mock <IMapService>();
            var employeeService   = new Mock <IEmployeeService>();
            EmployeesController emplController = new EmployeesController(mockedMappService.Object, employeeService.Object);
            var      employeeId = 5;
            Employee employee   = null;

            employeeService.Setup(x => x.GetById(employeeId)).Returns(employee);

            // Act
            emplController.Details(employeeId);

            // Assert
            Assert.IsInstanceOf <HttpNotFoundResult>(emplController.Details(employeeId));
        }
        public void DetailsTestLastName()
        {
            var controller = new EmployeesController();
            var result     = controller.Details(4) as ViewResult;
            var employee   = (Employee)result.ViewData.Model;

            Assert.AreEqual("Ortega", employee.LastName);
        }
        public void DetailsTestEmploymentDate()
        {
            var controller = new EmployeesController();
            var result     = controller.Details(4) as ViewResult;
            var employee   = (Employee)result.ViewData.Model;

            Assert.AreEqual("10/11/2018 12:00:00 AM", employee.EmploymentDate.ToString());
        }
        public void DetailsTestDepartment()
        {
            var controller = new EmployeesController();
            var result     = controller.Details(4) as ViewResult;
            var employee   = (Employee)result.ViewData.Model;

            Assert.AreEqual("College of Engineering", employee.Department.Name);
        }
Example #11
0
        public void ReturnViewResult_WhenIdIsCorrect()
        {
            // Arrange
            var mockedMappService = new Mock <IMapService>();
            var employeeService   = new Mock <IEmployeeService>();
            EmployeesController emplController = new EmployeesController(mockedMappService.Object, employeeService.Object);
            var employeeId = 5;

            employeeService.Setup(x => x.GetById(employeeId)).Returns(new Employee()
            {
                Id = employeeId
            });
            // Act
            emplController.Details(employeeId);

            // Assert
            Assert.IsInstanceOf <ViewResult>(emplController.Details(employeeId));
        }
        public async void Details_IdIsNull_ReturnsNotFound()
        {
            var employeeRepositroy = new Mock <IEmpoyeeRepository>();
            var employeeController = new EmployeesController(employeeRepositroy.Object);

            var result = await employeeController.Details(null) as NotFoundResult;

            Assert.NotNull(result);

            employeeController.Dispose();
        }
        public void Details()
        {
            // Arrange
            EmployeesController controller = new EmployeesController();

            // Act
            ViewResult result = controller.Details(1) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void DetailsWhenEmailNotNull()
        {
            // ARRANGE
            var dummyUsers = new List <ApplicationUser>
            {
                new ApplicationUser
                {
                    UserName   = "******",
                    Email      = "*****@*****.**",
                    ProvinceId = 1
                }
            }.AsQueryable();

            var dummyProvinces = new List <Province>
            {
                new Province {
                    ProvinceId   = 1,
                    ProvinceName = "ON"
                }
            }.AsQueryable();

            _userSet     = MockingHelper.Create(dummyUsers);
            _provinceSet = MockingHelper.Create(dummyProvinces);

            _db.Setup(c => c.Users).Returns(_userSet.Object);
            _db.Setup(c => c.Provinces).Returns(_provinceSet.Object);

            // ACT
            var resultTask = _controller.Details(dummyUsers.FirstOrDefault().Email);

            // Type cast
            var result = (ViewResult)resultTask;

            // Type cast the ViewResult object to ApplicationUser to count Members
            var employee = (ApplicationUser)result.Model;

            // ASSERT
            Assert.AreNotEqual(null, result);
            Assert.AreEqual(dummyUsers.FirstOrDefault().Email, employee.Email);
            Assert.AreEqual(dummyUsers.FirstOrDefault().ProvinceId, employee.ProvinceId);
        }
Example #15
0
        public void testEmployeesControllerDetails()
        {
            //Arrange
            DbContextOptions <ProjectContext> context = new DbContextOptions <ProjectContext>();
            ProjectContext      projectContext        = new ProjectContext(context);
            EmployeesController controller            = new EmployeesController(projectContext);

            //Act
            var result = controller.Details(1);

            //Assert
            Assert.NotNull(result);
        }
Example #16
0
        public async void ShouldReturnNotFound()
        {
            //Arrange
            var dbContext = serviceProvider.GetRequiredService <EmployeeContext>();

            CreateTestData(dbContext);
            var controller = new EmployeesController(dbContext);

            //Act
            var actionRequest = await controller.Details(6);

            //Assert
            Assert.IsType <NotFoundResult>(actionRequest);
        }
Example #17
0
        public void Details()
        {
            // Arrange
            var controller = new EmployeesController(this.MockContext.Object);

            // Act
            var result = controller.Details(3) as ViewResult;

            var mockedModel = result.Model as Employee;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Worker 3", mockedModel.FullName);
        }
        public async Task DetailsAsync()
        {
            var employee = new Employee {
                EmployeeId = 1, FirstName = "Jack", LastName = "Robinson", HiredDate = DateTime.Parse("2012-12-12")
            };
            var employeeRepository = new Mock <IEmployeeRepository>();

            employeeRepository.Setup(e => e.GetEmployee(It.IsAny <Int16>())).ReturnsAsync(employee);
            var controller = new EmployeesController(employeeRepository.Object);
            var result     = await controller.Details(It.IsAny <Int16>()) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Model, employee);
        }
        public async void Details_GetEmployeeById_ResusltIsNull_ReturnsNotFound()
        {
            var employeeRepositroy = new Mock <IEmpoyeeRepository>();

            employeeRepositroy.Setup(mock => mock.GetEmployeeById(1)).Returns(Task.FromResult <Employee>(null));
            var employeeController = new EmployeesController(employeeRepositroy.Object);

            var result = await employeeController.Details(1) as NotFoundResult;

            employeeRepositroy.Verify(mock => mock.GetEmployeeById(1), Times.Once());
            Assert.NotNull(result);

            employeeController.Dispose();
        }
        public void Details_Test()
        {
            //Arrange
            var employee = new Employee()
            {
                Id = 1, FirstName = "Juan", LastName = "Perez"
            };

            _employeeService.Setup(x => x.GetById(It.IsAny <int>())).Returns(employee);

            //Act
            ViewResult result = _employeesController.Details(1) as ViewResult;

            //Assert
            Assert.AreEqual((result.Model as Employee).FirstName, employee.FirstName);
        }
        public async System.Threading.Tasks.Task EmployeesDetailsReturnsViewAsync()
        {
            //Arrange
            Employees employeeTest = new Employees()
            {
                LastName = "test", FirstName = "test"
            };
            await _EmployeesControllerUnderTest.Create(employeeTest);

            //Act
            var result = _EmployeesControllerUnderTest.Details(employeeTest.EmployeeID);

            //Assert
            Assert.IsNotNull(result);

            DeleteTestFromDb();
        }
        public void Details_Test()
        {
            //Arrange
            var employee = new Employee()
            {
                Id = 1, FirstName = "Juan", LastName = "Perez"
            };

            _employeeService.Setup(x => x.GetEmployeeByIdAsync(It.IsAny <int>())).Returns(Task.FromResult(employee));

            //Act
            var result      = _testClass.Details(1) as Task <ActionResult>;
            var resultValue = result.Result as ViewResult;

            //Assert
            Assert.Equal((resultValue.Model as EmployeeViewModel).FirstName, employee.FirstName);
        }
Example #23
0
        public async void ShouldReturnCorrectEmployee()
        {
            //Arrange
            var dbContext = serviceProvider.GetRequiredService <EmployeeContext>();

            CreateTestData(dbContext);
            var controller = new EmployeesController(dbContext);

            //Act
            var result = await controller.Details(1);

            //Assert
            var view  = Assert.IsType <ViewResult>(result);
            var model = Assert.IsType <Employee>(view.ViewData.Model);

            Assert.Equal(1, model.ID);
        }
        public async void Details_GetEmployeeById_EmployeeFound_ReturnsViewDetailsModelEmployee()
        {
            // arange
            var employeeRepositroy = new Mock <IEmpoyeeRepository>();

            employeeRepositroy.Setup(mock => mock.GetEmployeeById(1)).ReturnsAsync(new Employee());
            var employeeController = new EmployeesController(employeeRepositroy.Object);

            // act
            var result = await employeeController.Details(1) as ViewResult;

            // assert
            Assert.Equal("Details", result.ViewName);
            employeeRepositroy.Verify(mock => mock.GetEmployeeById(1), Times.Once());
            Assert.NotNull(result);

            employeeController.Dispose();
        }
Example #25
0
        public void ShouldNot_ReturnNullAndShouldCallMethodGetOfIRepository_WhenRequestedDetails()
        {
            //arrange
            var employee = new Person
            {
                Id   = 1,
                Role = PersonRole.Employee
            };
            var repository = Substitute.For <IRepository>();

            repository.Get <Person>(1).Returns(employee);
            var employeeController = new EmployeesController(repository, appContext);


            //act
            var viewModel = employeeController.Details(1).Model as Person;

            //assert
            viewModel.Should().NotBeNull();
            repository.Received().Get <Person>(1);
        }
Example #26
0
        public async Task ShouldReturnUpdatedEmployee()
        {
            //Arrange
            var dbContext = serviceProvider.GetRequiredService <EmployeeContext>();

            CreateTestData(dbContext);
            var controller = new EmployeesController(dbContext);

            var detailResult = await controller.Details(5);

            var detailView = Assert.IsType <ViewResult>(detailResult);
            var model      = Assert.IsType <Employee>(detailView.ViewData.Model);

            model.LastName = "A";

            //Act
            var editResult = await controller.Edit(5);

            var editView  = Assert.IsType <ViewResult>(editResult);
            var editModel = Assert.IsType <Employee>(editView.ViewData.Model);

            //Assert
            Assert.Equal("A", editModel.LastName);
        }