public void TestUniqueDepartments() { var controller = new EmployeesController(_mockRepo, _logger); var result = controller.List() as ViewResult; var employee = (List <Employee>)result.ViewData.Model; var c = employee.Select(e => e.Department).Distinct().Count(); Assert.AreEqual(3, c); }
public void TestSalaryGreaterThan60000() { var controller = new EmployeesController(_mockRepo, _logger); var result = controller.List() as ViewResult; var employee = (List <Employee>)result.ViewData.Model; var c = employee.Where(e => e.Salary > 60000).Count(); Assert.AreEqual(2, c); }
public void CreateViewTest() { var mock = new Mock <IManager <Employee> >(); var controller = new EmployeesController(mock.Object); var result = controller.Create() as ViewResult; Assert.IsNotNull(result); }
public async Task GetAllEmployeesAsyncShouldReturnAllEmployees() { var testEmployees = GetTestEmployees(); var employeesController = new EmployeesController(testEmployees); var result = await employeesController.GetAllEmployeesAsync() as List <EmployeeViewModel>; Assert.AreEqual(testEmployees.Count, result.Count); }
public void TestDeleteFound() { _repository.Setup(repo => repo.DeleteEmployee(It.IsAny <int>())).Returns(true); var employeeController = new EmployeesController(_repository.Object, _mapper); var result = employeeController.Delete(3); Assert.IsInstanceOfType(result, typeof(OkResult)); }
private async Task CreateEmployeesAsync() { var c = new EmployeesController(_context); foreach (var employee in employees) { var result = await c.Create(employee); } }
public EmployeeControllerTest() { _provider = new EmptyModelMetadataProvider(); _context = new Context(InMemoryContext.NewContext()); _mapper = new Mapper(new MapperConfiguration(mc => mc.AddProfile(new EmployeeProfile()))); InMemoryContext.SeedData(_context); _repositary = new EmployeeRepository(_context, _provider, _mapper); _employeeController = new EmployeesController(_repositary); }
public void TestGetEmployeesEmpty() { EmployeesController employeesController = CreateController(emptyEmployees: true); IActionResult actionResult = employeesController.Get(); // Checks if the result is NotFound 404 Assert.IsType <NotFoundResult>(actionResult); }
public void Setup() { scope = new TransactionScope(); employeesController = new EmployeesController() { Request = new System.Net.Http.HttpRequestMessage(), Configuration = new HttpConfiguration() }; }
public void GetEmployeesByManagerId_ShouldReturnAllEmployeesUnderTheGivenManager() { int expected = 3; var employeeController = new EmployeesController(); var result = employeeController.GetEmployeesByManagerId(2); Assert.Equal(expected, result); }
public async Task TestGetEmployeesNotFound() { _repository.Setup(repo => repo.GetEmployeesAsync()).ReturnsAsync(new List <Employee>()); var employeeController = new EmployeesController(_repository.Object, _mapper); var result = await employeeController.GetEmployees(); Assert.IsInstanceOfType(result.Result, typeof(NotFoundObjectResult)); }
public void ControllerGetEmployeeByValidId() { var controller = new EmployeesController(); var response = controller.GetById(1); var result = (OkNegotiatedContentResult <EmployeeModel>)response; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); }
public void GetAllEmployeesSuccess() { var controller = new EmployeesController(); var response = controller.Get(); var result = (OkNegotiatedContentResult <List <EmployeeModel> >)response; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); }
public void ControllerDeleteEmployeeWithInvalidID() { var controller = new EmployeesController(); var response = controller.Delete(1337); var result = (NotFoundResult)response; Assert.IsNotNull(result); }
public void GetAllEmployees() { var controller = new EmployeesController(context); var response = controller.Get() as ObjectResult; var value = response.Value as List <EmployeeModel>; Assert.AreEqual(200, response.StatusCode); Assert.AreEqual(6, value.Count); }
public void GetEmployeeById(int id) { var controller = new EmployeesController(context); var response = controller.Get(id) as ObjectResult; var value = response.Value as EmployeeModel; Assert.AreEqual(200, response.StatusCode); Assert.AreEqual(1, value.Id); }
public void ControllerGetEmployeeByInvalidId() { var controller = new EmployeesController(); var response = controller.GetById(1337); var result = (NotFoundResult)response; Assert.IsNotNull(result); }
private EmployeesController CreateEmployeeController(Mock <IEmployeeService> mockEmployeeService) { var controller = new EmployeesController(mockEmployeeService.Object); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); return(controller); }
public void GetAllEmployees_ShouldReturnAllEmployees() { int expected = EmployeeDb.employees.Count; var employeeController = new EmployeesController(); var result = employeeController.GetAllEmployees().Count(); Assert.Equal(expected, result); }
public void Setup() { _query = A.Fake <IEmployeeQueries>(); A.CallTo(() => _query.FindByIdAsync(A <string> .Ignored, A <CancellationToken> .Ignored)).Returns(Task.FromResult <Employee>(null)); A.CallTo(() => _query.FindByIdAsync("Test123", A <CancellationToken> .Ignored)).Returns(Task.FromResult(_expectedEmployee)); _controller = new EmployeesController(_query); }
public async Task EmployeesController_GetEmployeeForCompany_Should_ReturnNotFoundWhenEmployeeNotFound() { var companyId = Guid.NewGuid(); var employeeId = Guid.NewGuid(); var trackChanges = false; _mockedCompanyRepository.Setup( companyRepo => companyRepo.GetCompanyAsync(companyId, trackChanges) ) .Returns( Task.FromResult( new Entities.Models.Company { Id = companyId, Address = "test address", Country = "Test Country", Employees = null, Name = "Test company Name" } ) ); _mockedEmployeeRepository.Setup( employeeRepo => employeeRepo.GetEmployeeAsync(companyId, employeeId, trackChanges) ) .Returns( Task.FromResult <Entities.Models.Employee>( null ) ); EmployeesController employeesController = new EmployeesController( _mockedRepositoryManager.Object, _mockedLogger.Object, _mapper, null, null ); var notFoundObjectResult = await employeesController.GetEmployeeForCompany(companyId, employeeId) as NotFoundObjectResult; using var scope = new AssertionScope(); notFoundObjectResult .StatusCode .Should() .Be((int)HttpStatusCode.NotFound); var notFoundMessage = $"Employee with id: {employeeId} doesn't exist in the database."; notFoundObjectResult .Value .Should() .BeEquivalentTo(notFoundMessage, because: notFoundMessage); }
public void TestInitialize() { DependencyHelper.Initialize(); IUnityContainer container = DependencyHelper.Container; _mockDbContext = new Mock <DatabaseContext>(); container.RegisterInstance <DatabaseContext>(_mockDbContext.Object); _employeeController = container.Resolve <EmployeesController>(); _fakeEmployeeDbSet = new FakeEmployeeSet(); }
public void GetEmployeesOnEmptyList_ShouldReturn_NoData() { EmployeesController employeesController = new EmployeesController(); var employees = new Employee[] { }; ActionResult <IEnumerable <Employee> > result = employees; result.Should() .BeEquivalentTo(employeesController.Get()); }
public void TestMethod1() { //add unit test EmployeesController pc = new EmployeesController(); Employee emp = pc.Get(3); Assert.AreEqual("Ben", emp.FirstName); }
public async Task TestForDisplayEmployeeByIdFailure() { var context = CreateContextForSQLite(); var testEmployeeContext = await GetTestEmployees(context); var controller = new EmployeesController(testEmployeeContext); var result = await controller.GetEmployeeById(1); Assert.Equal(await testEmployeeContext.Employees.FindAsync(1), result.Value); }
public async Task DisplayAllEmployee() { var context = CreateContextForSQLite(); var getEmployees = await GetTestEmployees(context); var controller = new EmployeesController(getEmployees); var result = await controller.GetEmployees(); Assert.Equal(await getEmployees.Employees.ToListAsync(), result.Value); }
public void BasicResultTesting() { EmployeesController controller = new EmployeesController(); List <Employee> result = controller.GetEmployees(); Assert.IsNotNull(result); Assert.AreEqual("Sindhuja", result.ToArray()[0].FirstName); Assert.AreEqual("Steve", result.ToArray()[3].FirstName); }
public async Task TestGetEmployeeByIdFound() { _repository.Setup(repo => repo.GetEmployeeByIdAsync(It.IsAny <int>())).ReturnsAsync(GetTestEmployees().First()); var employeeController = new EmployeesController(_repository.Object, _mapper); var result = await employeeController.GetEmployee(2); Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult)); Assert.AreEqual("Rakshi N S", ((result.Result as OkObjectResult).Value as EmployeeToReturn).EmployeeName); }
public async Task GetEmployee() { var optionsBuilder = new DbContextOptionsBuilder <WebApplicationContext>(); optionsBuilder.UseSqlServer(ConnectionString); var controller = new EmployeesController(new WebApplicationContext(optionsBuilder.Options)); await controller.GetEmployee(1); }
public async void Get_Employee(long ssn) { using (var context = GetContextWithData()) using (var controller = new EmployeesController(context)) { var result = await controller.GetEmployee(ssn); Assert.IsType <OkObjectResult>(result); } }