public async Task <Authentication.OutModel> Authentication([FromBody] Authentication.InModel inModel) { AuthValidator validationRules = new AuthValidator(); await validationRules.ValidateAndThrowAsync(inModel); return(await _iAccessControlService.Authentication(inModel)); }
public void TestAuth(string userEmail, string userPassword) { var controller = new UserController(accessControlService, userService); Auth.InModel inModel = new Auth.InModel(); inModel.Email = userEmail; inModel.PasswordHash = Encoding.UTF8.GetString(Cryptor.CalculateHashOfPassword(userPassword)); Auth.OutModel outModel; try { outModel = controller.Authentication(inModel).Result; } catch (Exception e) { outModel = controller.Authentication(inModel).Result; } /*AppSettings appSettings = new AppSettings() { * ConnectionString = "" }; * IOptions<AppSettings> options = Options.Create(appSettings); * UserService userService = new UserService(null); * UserController controller = new UserController( * new AccessControlService(null, options, userService, null), * userService); * Auth.InModel inModel = new Auth.InModel(); * inModel.Email = userEmail; * inModel.PasswordHash = Encoding.UTF8.GetString(Cryptor.CalculateHashOfPassword(userPassword)); * Auth.OutModel outModel = controller.Authentication(inModel).Result;*/ Assert.AreNotEqual(outModel.IdUser, 0); //var password = Cryptor.CalculateHashOfPassword(userPassword); //Auth.InModel inModel = new Auth.InModel //{ // Email = userEmail, // PasswordHash = Encoding.UTF8.GetString(password, 0, password.Length) //}; //ValidationException validationException = new ValidationException(It.IsAny<string>()); //var mock = new Mock<IAccessControlService>(); //mock.Setup(a => a.Authentication(inModel, It.IsAny<CancellationToken>())).ThrowsAsync(validationException); //var controller = new UserController(mock.Object, null); //Assert.ThrowsAsync<ValidationException>(async () => await controller.Authentication(inModel)); }
public void Test1() { Auth.InModel inModel = new Auth.InModel(); inModel.Email = "asdasda"; inModel.PasswordHash = Encoding.UTF8.GetString(Cryptor.CalculateHashOfPassword("asdasda")); try { Auth.OutModel outModel = userController.Authentication(inModel).Result; } catch (AggregateException ae) { //HARDCOOOD ae.Handle((x) => { if (x is ValidationException) { Assert.True(true); return(true); } Assert.True(false); return(false); }); } }