public void RetrieveEmployeeInfoFail() { var testEmail = "*****@*****.**"; var empService = new Mock <IEmployeeService>(); EttEmployee mockRes = null; // Return a null response from service call empService.Setup(serv => serv.RetrieveEmployeeInfo(It.IsAny <string>())).Returns(mockRes); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "test"), new Claim(ClaimTypes.NameIdentifier, "1"), new Claim("email", testEmail), }, "mock")); var controller = new EmployeeController(empService.Object); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = controller.GetEmployeeInfo().Result; var notFoundResult = result as NotFoundResult; Assert.NotNull(notFoundResult); Assert.Equal(404, notFoundResult.StatusCode); empService.Verify(x => x.RetrieveEmployeeInfo(It.IsAny <string>()), Times.Once); }
public void RetrieveEmployeeInfoNoResults() { List <EttEmployee> dbRetVal = new List <EttEmployee>(); MockServiceProvider serviceProvider = new MockServiceProvider() .AddMockDBConnection(); serviceProvider.MockDBConnection .Setup(_ => _.ExecuteQuery <EttEmployee>(QueryGenerator.GetEmployeeInfo("*****@*****.**"))) .Returns(dbRetVal); EmployeeService employeeService = new EmployeeService(serviceProvider.Build()); EttEmployee response = employeeService.RetrieveEmployeeInfo("*****@*****.**"); Assert.Null(response); }
public void RetrieveEmployeeInfoSuccess() { List <EttEmployee> dbRetVal = new List <EttEmployee>() { new EttEmployee("test", "name", "Developer") }; MockServiceProvider serviceProvider = new MockServiceProvider() .AddMockDBConnection(); serviceProvider.MockDBConnection .Setup(_ => _.ExecuteQuery <EttEmployee>(QueryGenerator.GetEmployeeInfo("*****@*****.**"))) .Returns(dbRetVal); EmployeeService employeeService = new EmployeeService(serviceProvider.Build()); EttEmployee response = employeeService.RetrieveEmployeeInfo("*****@*****.**"); Assert.Equal("test", response.FirstName); Assert.Equal("name", response.LastName); Assert.Equal("Developer", response.Role); }
public void RetrieveEmployeeInfoSuccess() { var testEmail = "*****@*****.**"; var employeeInfo = new EttEmployee("test", "name", "Developer"); var empService = new Mock <IEmployeeService>(); empService.Setup(serv => serv.RetrieveEmployeeInfo(It.IsAny <string>())).Returns(employeeInfo); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "test"), new Claim(ClaimTypes.NameIdentifier, "1"), new Claim("email", testEmail), }, "mock")); var controller = new EmployeeController(empService.Object); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = controller.GetEmployeeInfo().Result; var okResult = result as ObjectResult; var objString = okResult.Value.ToString(); var resValue = JsonConvert.DeserializeObject <EttEmployee>(objString); Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); Assert.Equal("test", resValue.FirstName); Assert.Equal("name", resValue.LastName); Assert.Equal("Developer", resValue.Role); empService.Verify(x => x.RetrieveEmployeeInfo(It.IsAny <string>()), Times.Once); }