public async Task SearchUserController_GetUsersByStateOrAgeRange_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.GetUsersByStateOrAgeRange("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, "*****@*****.**"); }
public async Task SearchUserController_GetByState_ValidState_ShouldHandleException() { // Arrange string stateCode = "NJ"; userList.Add(new User() { Age = 25, Email = "*****@*****.**", FirstName = "A1", LastName = "B1", ID = 1, StateCode = "NJ" }); userList.Add(new User() { Age = 26, Email = "*****@*****.**", FirstName = "A2", LastName = "B2", ID = 2, StateCode = "NJ" }); 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.GetByState(stateCode); okResult = actionResult as OkObjectResult; // Assert Assert.IsNull(okResult); }
public void CleanUp() { mapper = null; userList = null; fakeUserRepository = null; fakeSearchDetail = null; searchUserController = null; actionResult = null; okResult = null; fakeLogger = null; fakeMemoryCache = null; stateList = null; }
public async Task SearchUserController_GetUsersByStateOrAgeRange_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.GetUsersByStateOrAgeRange("NJ", 15, 99); okResult = actionResult as OkObjectResult; //Assert Assert.IsNotNull(okResult); }
public async Task SearchUserController_GetByState_InvalidState_ThrowsException() { // Arrange A.CallTo(() => fakeUserRepository.GetFilteredUsers(fakeSearchDetail)).Returns(userList); A.CallTo(() => fakeUserRepository.GetAllStates()).Returns(stateList); string stateCode = "AB"; // Act searchUserController = new SearchUserController(fakeUserRepository, mapper, fakeSearchDetail, fakeMemoryCache, fakeLogger); actionResult = await searchUserController.GetByState(stateCode); okResult = actionResult as OkObjectResult; //Assert Assert.IsNull(okResult); }
protected void Page_Load(object sender, EventArgs e) { userController = new SearchUserController(); itemCtrl = new ItemController(); if (Request.QueryString["userId"] != null) { singleUser = userController.getSingleUser(Request.QueryString["userId"]); if (singleUser != null) { LblUserName.Text = singleUser.FirstName + " " + singleUser.LastName; LblAddress.Text = singleUser.Address; LblCity.Text = singleUser.City; LblState.Text = singleUser.State; LblHomePhone.Text = singleUser.Phone; LblMobilePhone.Text = formatPhoneNum(singleUser.Phone); lblZip.Text = singleUser.Zip.ToString(); LblEmail.Text = singleUser.Email; if (!singleUser.Text) { BtnText.Visible = false; SMSMessage.Visible = false; } } } if (!Page.IsPostBack) { MessageSent.Visible = false; EmailSentMsg.Visible = false; } InvoiceView.DataBind(); InvoiceView.Rows[InvoiceView.Rows.Count - 1].Cells[6].Controls[0].Visible = false; InvoiceView.Rows[InvoiceView.Rows.Count - 2].Cells[6].Controls[0].Visible = false; InvoiceView.Rows[InvoiceView.Rows.Count - 3].Cells[6].Controls[0].Visible = false; }
public SearchUserControllerTests() { this.userService = Substitute.For <IUserService>(); this.searchUserController = new SearchUserController(this.userService); }