private void ERCollectionToEntitiesPairsCleanUp()
        {
            var pairsToDelete = scenarioContext.AllERCollectionToEntitiesPairs().ToList();

            for (int i = 0; i < pairsToDelete.Count; i++)
            {
                Log.Information("Attempting to delete ER Collection to Entities pairs from scenario context");
                scenarioContext.RemoveERCollectionToEntitiesPair(pairsToDelete[i]);
            }
        }
Пример #2
0
        public async Task ThenIMSUserDeletesTheEntitiesAcrossAllTheERCollections()
        {
            restClientUser = "******";
            var erCollectionEntitiesPairs = scenarioContext.AllERCollectionToEntitiesPairs().ToList();

            for (int k = 0; k < erCollectionEntitiesPairs.Count; k++)
            {
                var headers = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionEntitiesPairs[k].Key)
                };
                var getCreatedEntities = erCollectionEntitiesPairs[k].Value.ToList();
                for (int j = 0; j < getCreatedEntities.Count; j++)
                {
                    Log.Information($"Attempting to delete all entities from ER Collection {erCollectionEntitiesPairs[k].Key}");
                    var deleteEntityResponseMsg = await ERService.DeleteEntity(getCreatedEntities[j].Id, headers);

                    deleteEntityResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.OK, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to delete entity {getCreatedEntities[j].Id} from er collection {erCollectionEntitiesPairs[k].Key}");
                }
            }
        }
        public async Task WhenTheIMSUserPostsNewRelationshipSBetweenTheEntitiesBelongingToDifferentERCollectionsWhereIsUsingVInThERCollectionTimeS(int numOfRelationships, string asyncHeader, string asyncValue, string version)
        {
            restClientUser = "******";
            for (int i = 0; i < numOfRelationships; i++)
            {
                var erCollectionEntitiesPairList = scenarioContext.AllERCollectionToEntitiesPairs().ToList();

                var sourceERCollectionId = erCollectionEntitiesPairList[i].Key;
                var NewSourceEntities    = erCollectionEntitiesPairList[i].Value;

                var destinationERCollectionId = erCollectionEntitiesPairList[i + 1].Key;
                var NewDestinationEntities    = erCollectionEntitiesPairList[i + 1].Value;

                for (int j = 0; j < NewSourceEntities.Count; j++)
                {
                    List <Relationship> relationshipsToCreate = new List <Relationship>();
                    var newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: RelationshipTypes.BrickRelationshipHasPartType, relationshipName: "test relationship", sourceEntityId: NewSourceEntities[j].Id, destinationEntityId: NewDestinationEntities[j].Id)
                    {
                        SourceERCollectionId      = sourceERCollectionId,
                        DestinationERCollectionId = destinationERCollectionId
                    };

                    relationshipsToCreate.Add(newRelationship);
                    scenarioContext.AddERCollectionToRelationshipsPair(new KeyValuePair <string, List <Relationship> >(sourceERCollectionId, relationshipsToCreate));
                }
            }

            //Post relationships across ER Collections
            var erCollectionRelationshipsPairs = scenarioContext.AllERCollectionToRelationshipsPairs().ToList();

            for (int i = 0; i < erCollectionRelationshipsPairs.Count; i++)
            {
                var headers = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionRelationshipsPairs[i].Key),
                    new KeyValuePair <string, string>(asyncHeader, asyncValue)
                };
                var getRelationships = erCollectionRelationshipsPairs[i].Value;

                Log.Information($"Attempting to post new Relationship(s) between Entities in ER collection {erCollectionRelationshipsPairs[i].Key}");
                for (int j = 0; j < numOfRelationships; 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 {erCollectionRelationshipsPairs[i].Key}");
                        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 {erCollectionRelationshipsPairs[i].Key}");
                        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 static void RemoveERCollectionToEntitiesPair(this ScenarioContext scenarioContext, KeyValuePair <string, List <Entity> > ERCollectionEntitiesPair)
 {
     scenarioContext.AllERCollectionToEntitiesPairs().Remove(ERCollectionEntitiesPair);
 }