public async Task WhenTheIMSUserPostsNewRelationshipSBetweenTheEntitiesWhereIsUsingVInTheERCollectionTimeS(int numOfRelationships, string asyncHeader, string asyncValue, string version, int numOfTimes) { restClientUser = "******"; for (int i = 0; i < numOfRelationships; i++) { int index = i; var NewEntities = scenarioContext.CreatedEntities().ToList(); while (NewEntities.Count <= index + 1) { index = index + 1 - NewEntities.Count; } var sourceEntityId = NewEntities[index].Id; var destinationEntityId = NewEntities[index + 1].Id; var newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: RelationshipTypes.BrickRelationshipHasPartType, relationshipName: "test relationship", sourceEntityId: sourceEntityId, destinationEntityId: destinationEntityId); scenarioContext.AddRelationship(newRelationship); } var erCollectionIdList = scenarioContext.CreatedERCollections().ToList(); for (int k = 0; k < erCollectionIdList.Count; k++) { var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[k]), new KeyValuePair <string, string>(asyncHeader, asyncValue) }; var getRelationships = scenarioContext.CreatedRelationships().ToList(); Log.Information($"Attempting to post new Relationship/Relationships between Entities synchronously in ER collection {erCollectionIdList[k]}"); for (int j = 0; j < numOfTimes; j++) { var postRelationshipResponseMsg = await ERService.PostRelationship(version, getRelationships, 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[k]}"); Thread.Sleep(50000); } else { 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[k]}"); var response = postRelationshipResponseMsg.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); JObject jObjResponse = JObject.Parse(response); var successRelationshipIDList = from relationship in jObjResponse["data"]["responses"]["success"] select(string) relationship["id"]; var getRelationshipIDList = from relationship in getRelationships select relationship.Id; getRelationshipIDList.Should().BeEquivalentTo(successRelationshipIDList); getRelationshipIDList.Count().Should().Be(successRelationshipIDList.Count()); } } } }
public async Task WhenTheIMSUserPostsNewRelationshipSBetweenTheEntitiesWhereIsWithoutPropertyUsingVInTheERCollectionTimeS(int numOfRelationship, string asyncHeader, string asyncValue, string missingField, string version) { restClientUser = "******"; for (int i = 0; i < numOfRelationship; i++) { int index = i; var newEntities = scenarioContext.CreatedEntities().ToList(); while (newEntities.Count <= index + 1) { index = index + 1 - newEntities.Count; } var sourceEntityId = newEntities[index].Id; var destinationEntityId = newEntities[index + 1].Id; Relationship newRelationship = null; { if (missingField.Equals("relationshipType")) { newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: null, relationshipName: "test relationship", sourceEntityId: sourceEntityId, destinationEntityId: destinationEntityId); } if (missingField.Equals("sourceEntityId")) { newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: BrickRelationshipTypes.BrickEquipmentIsLocatedInLocation, relationshipName: "test relationship", sourceEntityId: null, destinationEntityId: destinationEntityId); } if (missingField.Equals("destinationEntityId")) { newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: BrickRelationshipTypes.BrickEquipmentIsLocatedInLocation, relationshipName: "test relationship", sourceEntityId: sourceEntityId, destinationEntityId: null); } if (missingField.Equals("relationshipName")) { newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: BrickRelationshipTypes.BrickEquipmentIsLocatedInLocation, relationshipName: null, sourceEntityId: sourceEntityId, destinationEntityId: destinationEntityId); } if (missingField.Equals("relationshipId")) { newRelationship = new Relationship(id: null, relationshipType: BrickRelationshipTypes.BrickEquipmentIsLocatedInLocation, relationshipName: "test relationship", sourceEntityId: sourceEntityId, destinationEntityId: destinationEntityId); } } scenarioContext.AddRelationship(newRelationship); } //var erCollectionIdList = scenarioContext.CreatedERCollections().ToList(); string erCollectionId = this.scenarioContext.Get <dynamic>("CollectionsResponse"); scenarioContext.AddERCollections(erCollectionId); var headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionId), new KeyValuePair <string, string>(asyncHeader, asyncValue) }; var getRelationships = scenarioContext.CreatedRelationships().ToList(); Log.Information($"Attempting to post new Relationship/Relationships between Entities synchronously in ER collection {erCollectionId}"); { RestClientResponse <PlatformItemResponse> postRelationshipResponseMsg = null; //try //{ postRelationshipResponseMsg = await ERService.PostRelationship(version, getRelationships, headers); if (asyncValue == "true") { postRelationshipResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Accepted, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to partial update relationship in er collection {erCollectionId}"); } else { scenarioContext.AddPartialUpdateResponses(postRelationshipResponseMsg); } } //} //catch (RestClientException ex) //{ // scenarioContext.AddRestClientExceptionErrors(ex); //} }
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]}"); } } } } }