public async Task <List <Users> > ValidLogin([FromBody] Users obj) { try { List <Users> lstLogin = new List <Users>(); lstLogin = await this._usersBAL.ValidLogin(obj); if (lstLogin.Count > 0) { AuthorizeService auth = new AuthorizeService(); string _token = auth.Authenticate(Convert.ToString(lstLogin[0].UserID), _appSettings); lstLogin[0].Token = _token; // return lstLogin; } return(lstLogin); } catch (Exception ex) { ErrorLogger.Log($"Something went wrong inside UsersController ValidLogin action: {ex.Message}"); ErrorLogger.Log(ex.StackTrace); Logger.LogError($"Something went wrong inside UsersController ValidLogin action: {ex.Message}"); return(null); } }
public void AuthErrorTest() { //// Arrange var errors = new List <string>(); var mockRepository = new Mock <IAuthorizeRepository>(); var authService = new AuthorizeService(mockRepository.Object); //// Act authService.Authenticate(string.Empty, string.Empty, ref errors); //// Assert mockRepository.Verify(x => x.Authenticate(It.IsAny <string>(), It.IsAny <string>(), ref errors), Times.Never); }
public void AuthTestError() { //// Arrange var errors = new List <string>(); var logon = new Logon { Id = "1", Role = "TestRole" }; var mockRepository = new Mock <IAuthorizeRepository>(); mockRepository.Setup(x => x.Authenticate("testuser", "testpassword", ref errors)) .Returns(logon); var authService = new AuthorizeService(mockRepository.Object); //// Act var logonReturned = authService.Authenticate("testuser", "testpassword", ref errors); //// Assert Assert.AreEqual(1, errors.Count); }
public void AuthTest() { //// Arrange var errors = new List <string>(); var logon = new Logon { Id = "1", Role = "TestRole" }; var mockRepository = new Mock <IAuthorizeRepository>(); mockRepository.Setup(x => x.Authenticate("testuser", "testpassword", ref errors)) .Returns(logon); var authService = new AuthorizeService(mockRepository.Object); //// Act var logonReturned = authService.Authenticate("testuser", "testpassword", ref errors); //// Assert Assert.AreEqual(logon.ToString(), logonReturned.ToString()); Assert.AreEqual(0, errors.Count); mockRepository.Verify(x => x.Authenticate(It.IsAny <string>(), It.IsAny <string>(), ref errors), Times.Once); }