예제 #1
0
        public async Task WhenTheIMSUserPostsNewEntitiesWhereIsUsingVInERCollectionTimeS(int numOfEntities, int numOfERCollections, string asyncHeader, string asyncValue, string version, int numOfTimes)
        {
            for (int k = 0; k < numOfERCollections; k++)
            {
                restClientUser = "******";
                List <Entity> entityList = new List <Entity>();
                for (int i = 0; i < numOfEntities; i++)
                {
                    var newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: EntityTypes.EquipmentBrickEntityType, entityName: "test entity");
                    entityList.Add(newEntity);
                }

                var erCollectionId = "testER-" + Guid.NewGuid().ToString();

                scenarioContext.AddERCollectionToEntitiesPair
                    (new KeyValuePair <string, List <Entity> >(erCollectionId, entityList));

                var headers = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionId),
                    new KeyValuePair <string, string>(asyncHeader, asyncValue)
                };

                Log.Information($"Attempting to post new entity/entities in ER collection {erCollectionId}");
                for (int i = 0; i < numOfTimes; i++)
                {
                    var postEntityResponseMsg = await ERService.PostEntities(version, entityList, headers);

                    if (asyncValue == "true")
                    {
                        postEntityResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Accepted, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection {erCollectionId}");
                        Thread.Sleep(50000);
                    }
                    else
                    {
                        postEntityResponseMsg.Response.StatusCode.ToString().Should().Be("OK", $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection {erCollectionId}");
                        var     response            = postEntityResponseMsg.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                        JObject jObjResponse        = JObject.Parse(response);
                        var     successEntityIDList = from entity in jObjResponse["data"]["responses"]["success"]
                                                      select(string) entity["id"];
                        var getEntityIDList = from entity in entityList
                                              select entity.Id;

                        getEntityIDList.Should().BeEquivalentTo(successEntityIDList);
                        getEntityIDList.Count().Should().Be(successEntityIDList.Count());
                    }
                }
            }
        }