public async Task ThenValidateTheIMSUserGetsAllEntitiesIncludingUploadedFileEntitiesFromTheERCollection(int numOfFiles) { restClientUser = "******"; var getNewEntities = scenarioContext.CreatedEntities().ToList(); var erCollectionIdList = scenarioContext.CreatedERCollections().ToList(); for (int i = 0; i < erCollectionIdList.Count; i++) { var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[i]) }; Log.Information($"Attempting to get all entities from ER Collection {erCollectionIdList[i]}"); var getAllEntitiesResponseMsg = await ERService.GetAllEntities(headers); getAllEntitiesResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.OK, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to get all entities from er collection {erCollectionIdList[i]}"); var getAllEntities = getAllEntitiesResponseMsg.Result.Data.Select(s => s.ToObject <Entity>()); foreach (var entity in getNewEntities) { getAllEntities.Should().Contain(x => x.Id == entity.Id); } getAllEntities.Count().Should().Be(getNewEntities.Count() + numOfFiles); } }
public async Task ThenIMSUserDeletesTheEntitiesIncludingTheUploadedFileEntitiesFromTheERCollection() { restClientUser = "******"; var getNewEntities = scenarioContext.CreatedEntities().ToList(); var erCollectionIdList = scenarioContext.CreatedERCollections().ToList(); var fileEntityIdList = scenarioContext.Get <List <string> >("FileEntityIdList"); for (int i = 0; i < erCollectionIdList.Count; i++) { var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[i]) }; for (int j = 0; j < getNewEntities.Count; j++) { Log.Information($"Attempting to delete entities from ER Collection {erCollectionIdList[i]}"); var deleteAEntityResponseMsg = await ERService.DeleteEntity(getNewEntities[j].Id, headers); deleteAEntityResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.OK, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to delete entity {getNewEntities[j].Id} from er collection {erCollectionIdList[i]}"); } for (int k = 0; k < fileEntityIdList.Count; k++) { Log.Information($"Attempting to delete file entities from ER Collection {erCollectionIdList[i]}"); var deleteAEntityResponseMsg = await ERService.DeleteEntity(fileEntityIdList[k], headers); deleteAEntityResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.OK, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to delete entity {fileEntityIdList[k]} from er collection {erCollectionIdList[i]}"); } } }
public async Task WhenTheIMSUserPostsNewRelationshipSUsingImportFileWhereIsAndIsUsingVInAnERCollectionTimeS(int numOfRelationships, string fileNameHeader, string fileName, string asyncHeader, string asyncValue, string version) { restClientUser = "******"; var erCollectionIdList = scenarioContext.CreatedERCollections().ToList(); for (int i = 0; i < numOfRelationships; i++) { for (int j = 0; j < erCollectionIdList.Count; j++) { var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[j]), new KeyValuePair <string, string>(asyncHeader, asyncValue), new KeyValuePair <string, string>(fileNameHeader, fileName) }; List <Relationship> relationships = new List <Relationship>(); Log.Information($"Attempting to post new Relationship/Relationships between Entities synchronously in ER collection {erCollectionIdList[j]}"); var postRelationshipResponseMsg = await ERService.PostRelationship(version, relationships, headers); if (asyncValue.Equals("true")) { postRelationshipResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Accepted, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new Relationship in er collection {erCollectionIdList[j]}"); Thread.Sleep(50000); } else { if (version == "2.0") { postRelationshipResponseMsg.Response.StatusCode.ToString().Should().Be("OK", $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new relationship in er collection {erCollectionIdList[j]}"); var response = postRelationshipResponseMsg.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); JObject o = JObject.Parse(response); var relationshipId = (string)o.SelectToken("data.responses.success").First["id"]; //add relationships to scenario context var listOfRelationships = FileService.GetRelationshipsFromJsonFile(); foreach (var relationship in listOfRelationships) { scenarioContext.AddRelationship(relationship); } if (fileName.Contains("csv")) { List <string> relationshipValue = ReadCSVFile(fileName, 3, "id"); Assert.AreEqual(relationshipValue[0], relationshipId); } else if (fileName.Contains("json")) { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Files\" + fileName); string filesContent = File.ReadAllText(path); var relationshipList = JsonConvert.DeserializeObject <IEnumerable <RelationshipBase> >(filesContent); var expectedRelationshipId = relationshipList.First().Id; Assert.AreEqual(expectedRelationshipId, relationshipId); } } else { postRelationshipResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Created, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new Relationship in er collection {erCollectionIdList[j]}"); } } } } }
public async Task WhenTheIMSUserPostsNewEntitiesImportingFromCSVFileWhereIsAndIsUsingVInAnERCollection(int noOfEntities, string fileNameHeader, string fileName, string asyncHeader, string asyncValue, string version) { restClientUser = "******"; var erCollectionIdList = scenarioContext.CreatedERCollections().ToList(); for (int j = 0; j < erCollectionIdList.Count; j++) { var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[j]), new KeyValuePair <string, string>(asyncHeader, asyncValue), new KeyValuePair <string, string>(fileNameHeader, fileName) }; List <Entity> entities = new List <Entity>(); Log.Information($"Attempting to post new entity/entities importing from file in ER collection {erCollectionIdList[j]}"); var postEntitiesResponseMsg = await ERService.PostEntities(version, entities, headers); if (asyncValue == "true") { postEntitiesResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Accepted, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection {erCollectionIdList[j]}"); } else { if (version == "2.0") { postEntitiesResponseMsg.Response.StatusCode.ToString().Should().Be("OK", $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection {erCollectionIdList[j]}"); var response = postEntitiesResponseMsg.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); JObject o = JObject.Parse(response); var entityId = (string)o.SelectToken("data.responses.success").First["id"]; var entityId1 = (string)o.SelectToken("data.responses.success").Last["id"]; //add entities to scenario context var entityList = FileService.GetEntitiesFromJsonFile(); foreach (var entity in entityList) { scenarioContext.AddEntity(entity); } if (fileName.Contains("csv")) { List <string> entityValue = ReadCSVFile(fileName, 3, "id"); //Assert.AreEqual(entityValue[0], entityId); //Assert.AreEqual(entityValue[1], entityId1); Assert.IsTrue(entityValue.Contains(entityId)); Assert.IsTrue(entityValue.Contains(entityId1)); } else if (fileName.Contains("json")) { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Files\" + fileName); string filesContent = File.ReadAllText(path); //var listOfEntities = JsonConvert.DeserializeObject<IEnumerable<EntityBase>>(filesContent); //var expectedEntityId1 = listOfEntities.First().Id; //var expectedEntityId2 = listOfEntities.Last().Id; //Assert.AreEqual(expectedEntityId1, entityId); //Assert.AreEqual(expectedEntityId2, entityId1); Assert.IsTrue(filesContent.Contains(entityId)); Assert.IsTrue(filesContent.Contains(entityId1)); } } else { postEntitiesResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Created, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection {erCollectionIdList[j]}"); } } } }