public void ApiDeleteEntities(EntityFactory entityFactory) { // create some test entities over the api to run the delete tests against var entityList = entityFactory.ConstructAndSave(_output, 1); foreach (var entityObject in entityList) { // instantiate a list of entity names and guids to be deleted var entityKeysGuids = new List <KeyValuePair <string, Guid> >(); entityKeysGuids.Add(new KeyValuePair <string, Guid>(entityObject.EntityName, entityObject.Id)); // populate the list using information returned from create entities. GetParentKeysGuids(entityObject).ForEach(x => entityKeysGuids.Add(x)); foreach (var entityKeyGuid in entityKeysGuids) { // instantiate a new rest client, and configure the Uri var endPoint = $"/api/entity/{entityKeyGuid.Key}/{entityKeyGuid.Value}"; var api = new WebApi(_configure, _output); api.ConfigureAuthenticationHeaders(); Assert.Equal(HttpStatusCode.OK, api.Get(endPoint).StatusCode); Assert.Equal(HttpStatusCode.OK, api.Delete(endPoint).StatusCode); Assert.Equal(HttpStatusCode.NoContent, api.Get(endPoint).StatusCode); Assert.Equal(HttpStatusCode.OK, api.Delete(endPoint).StatusCode); } } }
public void ExportEntity(EntityFactory entityFactory, int numEntities) { var entityList = entityFactory.ConstructAndSave(_output, numEntities); var entityName = entityList[0].EntityName; var api = new WebApi(_configure, _output); var query = QueryBuilder.CreateExportQuery(entityList); var queryList = new JsonArray { new JsonArray { query } }; api.ConfigureAuthenticationHeaders(); var response = api.Post($"/api/entity/{entityName}/export", queryList); var responseDictionary = CsvToDictionary(response.Content) .ToDictionary(pair => pair.Key.ToLowerInvariant(), pair => pair.Value); foreach (var entity in entityList) { var entityDict = entity.ToDictionary() .ToDictionary(pair => pair.Key.ToLowerInvariant(), pair => pair.Value); if (entity is UserBaseEntity) { // export will not contain password entityDict.Remove("password"); } if (entity is IFileContainingEntity) { // file ids are generated server-side foreach (var fileAttributeKey in GetFileEntityFilterKeys(entity)) { entityDict.Remove(fileAttributeKey); } } foreach (var attributeKey in entityDict.Keys.Select(x => x.ToLowerInvariant())) { responseDictionary.Should().ContainKey(attributeKey); responseDictionary[attributeKey] .Should() .Contain(entityDict[attributeKey]) .And .HaveCount(numEntities); } } }
public void IInsertAValidEntityAndSearchForIt(string entityName) { // Insert the row var entityFactory = new EntityFactory(entityName); var entity = entityFactory.ConstructAndSave(_testOutputHelper); // Search for it using GUID _genericEntityPage.SearchInput.SendKeys(entity.Id.ToString()); _genericEntityPage.SearchButton.Click(); _driverWait.Until(_ => _genericEntityPage.TotalEntities() == 1); Assert.Equal(1, _genericEntityPage.TotalEntities()); // Delete it _genericEntityPage.DeleteTopEntity(); _driverWait.Until(_ => _genericEntityPage.TotalEntities() == 0); Assert.Equal(0, _genericEntityPage.TotalEntities()); }
public void GraphqlBatchUpdateEntities(EntityFactory entityFactory, int numEntities) { var entity = entityFactory.Construct(); var entityProperties = entity.GetType().GetProperties(); if (entityProperties.Any(x => x.PropertyType.IsEnum) || entity.HasFile) { throw new SkipException("Batch update is currently not supported on entities with enum or file"); } var entityList = entityFactory.ConstructAndSave(_output, numEntities); //setup the rest client var client = new RestClient { BaseUrl = new Uri($"{_configure.BaseUrl}/api/graphql") }; //setup the request var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Json }; //get the authorization token and adds the token to the request var loginToken = new LoginToken(_configure.BaseUrl, _configure.SuperUsername, _configure.SuperPassword); var authorizationToken = $"{loginToken.TokenType} {loginToken.AccessToken}"; request.AddHeader("Authorization", authorizationToken); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "*\\*"); // form the query to update the entity var updateQuery = QueryBuilder.BatchUpdateEntityQueryBuilder(entityList); request.AddParameter("text/json", updateQuery, ParameterType.RequestBody); // mass update all entities in the list in a single request and check status code is ok RequestHelpers.ValidateResponse(client, Method.POST, request, HttpStatusCode.OK); }
public void GraphqlDeleteEntities(EntityFactory entityFactory, int numEntities) { var entityList = entityFactory.ConstructAndSave(_output, numEntities); GraphQlDelete(entityList); }
public void IHaveValidEntitiesWithFixedStrValues(string entityName, string fixedValues) { _entityFactory = new EntityFactory(entityName, fixedValues); _createdEntityForTestFiltering = _entityFactory.ConstructAndSave(_testOutputHelper, 1)[0]; }
public void InsertEntityToDatabase(string entityName) { var entityFactory = new EntityFactory(entityName); entityFactory.ConstructAndSave(_testOutputHelper); }
public void IHaveValidEntities(int numEntities, string entityName) { var entityFactory = new EntityFactory(entityName); entityFactory.ConstructAndSave(_testOutputHelper, numEntities); }