public void Init() { // orig - working _userMgr = new UserManager<ApplicationUser>( new NHibernate.AspNet.Identity.UserStore<ApplicationUser>(NHibernateConfiguration.CreateSessionFactory(ConnString).OpenSession())); // Min length for password = 6. _login = new LoginModel { UserName = "******", Password = "******" }; }
// ReSharper disable once InconsistentNaming public async void Middleware_will_not_return_an_accessToken_via_an_unsuccessful_login() { using (var client = new HttpClient()) { // Arrange _login = new LoginModel { UserName = "******", Password = "******" }; client.BaseAddress = new Uri(UrlBase); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var settings = new JsonSerializerSettings(); var ser = JsonSerializer.Create(settings); var j = JObject.FromObject(_login, ser); HttpContent content = new StringContent(j.ToString()); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // Act var loginResponse = await client.PostAsync(client.BaseAddress + "/LoginAsync", content); var accessToken = loginResponse.Content.ReadAsStringAsync().Result; // Assert Assert.IsTrue(loginResponse.StatusCode == HttpStatusCode.InternalServerError); Assert.IsTrue(accessToken.IndexOf("exceptionMessage", StringComparison.Ordinal) >= 1); } }
// ReSharper disable once InconsistentNaming public async void Middleware_will_not_allow_invalid_password_login() { using (var client = new HttpClient()) { // Arrange _login = new LoginModel { UserName = "******", Password = "******" }; client.BaseAddress = new Uri(UrlBase); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var settings = new JsonSerializerSettings(); var ser = JsonSerializer.Create(settings); var j = JObject.FromObject(_login, ser); HttpContent content = new StringContent(j.ToString()); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // Act var loginResponse = await client.PostAsync(client.BaseAddress + "/LoginAsync", content); // Assert Assert.IsTrue(loginResponse.StatusCode == HttpStatusCode.InternalServerError); } }