public async Task SearchUserController_GetUsersByStateAndAgeRange_ValidParams_ThrowsNoException() { // Arrange A.CallTo(() => fakeUserRepository.GetFilteredUsers(fakeSearchDetail)).Returns(userList); A.CallTo(() => fakeUserRepository.GetAllStates()).Returns(stateList); // Act searchUserController = new SearchUserController(fakeUserRepository, mapper, fakeSearchDetail, fakeMemoryCache, fakeLogger); actionResult = await searchUserController.GetUsersByStateAndAgeRange("NJ", 15, 99); okResult = actionResult as OkObjectResult; //Assert Assert.IsNotNull(okResult); }
public async Task SearchUserController_GetUsersByStateAndAgeRange_ValidParams_ShouldHandleException() { // Arrange userList.Add(new User() { Age = 27, Email = "*****@*****.**", FirstName = "A3", LastName = "B3", ID = 3, StateCode = "NJ" }); A.CallTo(() => fakeUserRepository.GetFilteredUsers(fakeSearchDetail)).Throws(new Exception("Error occured")); A.CallTo(() => fakeUserRepository.GetAllStates()).Returns(stateList); // Act searchUserController = new SearchUserController(fakeUserRepository, mapper, fakeSearchDetail, fakeMemoryCache, fakeLogger); actionResult = await searchUserController.GetUsersByStateAndAgeRange("NJ", 15, 99); okResult = actionResult as OkObjectResult; // Assert Assert.IsNull(okResult); }
public async Task SearchUserController_GetUsersByStateAndAgeRange_ValidParams_ReturnsProperResults() { // Arrange userList.Add(new User() { Age = 25, Email = "*****@*****.**", FirstName = "A1", LastName = "B1", ID = 1, StateCode = "NJ" }); A.CallTo(() => fakeUserRepository.GetFilteredUsers(fakeSearchDetail)).Returns(userList); A.CallTo(() => fakeUserRepository.GetAllStates()).Returns(stateList); // Act searchUserController = new SearchUserController(fakeUserRepository, mapper, fakeSearchDetail, fakeMemoryCache, fakeLogger); actionResult = await searchUserController.GetUsersByStateAndAgeRange("NJ", 15, 99); okResult = actionResult as OkObjectResult; List <UserViewModel> userVM = okResult.Value as List <UserViewModel>; // Assert Assert.IsNotNull(okResult); Assert.IsNotNull(userVM[0].Name); Assert.AreEqual(userVM[0].Name, "A1 B1"); Assert.AreEqual(userVM[0].Age, 25); Assert.AreEqual(userVM[0].Email, "*****@*****.**"); }