コード例 #1
0
        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());
                    }
                }
            }
        }