public void DeactivateUserEndpointTests(UserEntityFactory entityFactory) { // Arrange var userEntity = entityFactory.Construct(); userEntity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); userEntity.CreateUser(true); var deactivateQuery = JsonConvert.SerializeObject(new { Username = userEntity.EmailAddress }); var clientxsrf = ClientXsrf.GetValidClientAndxsrfTokenPair(_configure); var client = clientxsrf.client; client.BaseUrl = new Uri(_configure.BaseUrl + $"/api/account/deactivate"); var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Json }; request.AddHeader("X-XSRF-TOKEN", clientxsrf.xsrfToken); request.AddHeader("Content-Type", "application/json"); request.AddParameter("query", deactivateQuery, ParameterType.RequestBody); // Act var response = client.Execute(request); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); var activatedInDatabase = UserHelper.GetUserFromDB(userEntity.Id).EmailConfirmed; Assert.False(activatedInDatabase); }
public void CreateValidRegisteredUserTests(UserEntityFactory entityFactory) { var userEntity = entityFactory.Construct(); userEntity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); userEntity.CreateUser(true); var loginResponse = AttemptLogin(userEntity.EmailAddress, userEntity.Password); Assert.Equal(HttpStatusCode.OK, loginResponse.StatusCode); }
public void RegistrationInvalidPasswordTests(UserEntityFactory userEntityFactory, string password, string expectedException) { var userEntity = userEntityFactory.Construct(); userEntity.Password = password; try { new Registration(userEntity, _output); } catch (AggregateException e) { var exceptionInList = e.InnerExceptions.Select(x => x.Message); Assert.Contains(expectedException, exceptionInList); return; } throw new Exception("User creation succeeded when it was expected to fail"); }
public void GetAllUsersEndpointTests(UserEntityFactory entityFactory) { // Arrange var userEntity = entityFactory.Construct(); userEntity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); userEntity.CreateUser(true); // Endpoint requires sorting and pagination options to be supplied. var sortOptions = new[] { new { Path = "id", Descending = false } }; var paginationOptions = new { PageNo = 1, PageSize = 10 }; // Search query for the user entity that we have created. var searchConditions = new[] { new[] { new { comparison = "Like", path = "Email", value = new string[] { $"%{userEntity.EmailAddress}%" } } } }; // Add required sorting and pagination options, and the search for our created entity to the body of the query. var query = JsonConvert.SerializeObject(new { PaginationOptions = paginationOptions, SearchConditions = searchConditions, SortConditions = sortOptions }); var clientxsrf = ClientXsrf.GetValidClientAndxsrfTokenPair(_configure); var client = clientxsrf.client; client.BaseUrl = new Uri(_configure.BaseUrl + $"/api/account/users"); var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Json }; request.AddHeader("X-XSRF-TOKEN", clientxsrf.xsrfToken); request.AddHeader("Content-Type", "application/json"); request.AddParameter("query", query, ParameterType.RequestBody); // Act var response = client.Execute(request); var returnedObject = JsonConvert.DeserializeObject <AccountController.UserListModel>(response.Content); // Assert Assert.Equal(userEntity.Id, returnedObject.Users.First().Id); }