public void LoginWithPassword_CancelWasPressed_ReturnNull( Mock<IDialogService> dialog, Mock<IZohoClient> zoho, LoginController target) { dialog.Setup(x => x.ShowLogin(It.IsAny<string>())).ReturnsAsync(null); var result = target.LoginWithPassword(); Assert.Null(result.Result); }
public void LoginWithPassword_ValidPasswordPassed_AuthDataReturned( [Frozen]Mock<IDialogService> dialog, [Frozen]Mock<IZohoClient> zoho, [Frozen]Mock<IProgressDialogController> progressDialog, LoginController target) { var userName = "******"; var password = "******"; var token = "token"; var id = "42"; dialog .Setup(x => x.ShowLogin(It.IsAny<string>())) .ReturnsAsync(new LoginData { Username = userName, Password = password}); dialog .Setup(x => x.ShowProgress(It.IsAny<string>(), It.IsAny<string>())) .ReturnsAsync(progressDialog.Object); zoho .Setup(x => x.LoginAsync(userName, password)) .ReturnsAsync(token); dynamic employee1 = new Dictionary<string, string>(); employee1["Email ID"] = userName; employee1["EmployeeID"] = id; dynamic employee2 = new Dictionary<string, string>(); employee2["Email ID"] = "random"; employee2["EmployeeID"] = "11"; zoho .Setup(x => x.FetchRecord.GetByViewAsync(It.IsAny<string>())) .ReturnsAsync(new List<dynamic> {employee1, employee2}); var result = target.LoginWithPassword().Result; progressDialog.Verify(x => x.SetIndeterminate()); zoho.Verify(x => x.LoginAsync(userName, password)); progressDialog.Verify(x => x.CloseAsync()); zoho.Verify(x => x.FetchRecord.GetByViewAsync("P_EmployeeView")); Assert.NotNull(result); Assert.Equal(userName, result.UserName); Assert.Equal(token, result.Token); Assert.Equal(id, result.Id); }
public void LoginWithPassword_WrongPasswordAndSecondTimeTry_SameLoginRamains( [Frozen]Mock<IDialogService> dialog, [Frozen]Mock<IZohoClient> zoho, [Frozen]Mock<IProgressDialogController> progressDialog, LoginController target) { var userName = "******"; var password = "******"; dialog .Setup(x => x.ShowLogin(null)) .ReturnsAsync(new LoginData { Username = userName, Password = password }); dialog .Setup(x => x.ShowProgress(It.IsAny<string>(), It.IsAny<string>())) .ReturnsAsync(progressDialog.Object); zoho .Setup(x => x.LoginAsync(userName, password)) .ThrowsAsync(new ApiLoginErrorException("")); target.LoginWithPassword().Wait(); target.LoginWithPassword().Wait(); dialog.Verify(x => x.ShowLogin(null), Times.Once); dialog.Verify(x => x.ShowLogin(userName), Times.Once); progressDialog.Verify(x => x.CloseAsync()); }