Exemplo n.º 1
0
        public async Task ThenTheIMSUserPostsNewEntityWithoutAnyFieldInAnERCollectionTimeSAsync(int numOfEntities, string asyncHeader, string asyncValue, string missingField, string version, int numOfTimes)
        {
            restClientUser = "******";
            for (int i = 0; i < numOfEntities; i++)
            {
                Entity newEntity = null;

                if (missingField.Equals("entityId"))
                {
                    newEntity = new Entity(id: null, entityType: BrickEntityTypes.FloorBrickEntityType, entityName: "test entity");
                }

                if (missingField.Equals("entityType"))
                {
                    newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: null, entityName: "test entity");
                }

                if (missingField.Equals("entityName"))
                {
                    newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: BrickEntityTypes.FloorBrickEntityType, entityName: null);
                }

                scenarioContext.AddEntity(newEntity);
            }
            //var erCollectionId = "test-" + Guid.NewGuid().ToString();
            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 getentities = scenarioContext.CreatedEntities().ToList();

            Log.Information($"Attempting to post new entity/entities with missing field in ER collection {erCollectionId}");
            for (int j = 0; j < numOfTimes; j++)
            {
                RestClientResponse <PlatformItemResponse> postEntityResponseMsg = null;
                //try
                //{
                postEntityResponseMsg = await ERService.PostEntities(version, getentities, headers);

                //}
                //catch (RestClientException ex)
                //{
                //    scenarioContext.AddRestClientExceptionErrors(ex);
                //}
                if (asyncValue == "true")
                {
                    postEntityResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Accepted, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should not be able to post entity in er collection {erCollectionId}");
                }
                else
                {
                    postEntityResponseMsg.Response.StatusCode.ToString().Should().Be("207", $"{restClientUser} user with {_testCfg.ImsScopes} scopes should not be able to post entity in er collection {erCollectionId}");
                }
            }
        }
        private async Task PostEntitiesWithLabels(int numOfEntities, int numOfLabels, string asyncHeader, string asyncValue, string version, int numOfERCollections)
        {
            for (int i = 0; i < numOfEntities; i++)
            {
                var newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: EntityTypes.EquipmentBrickEntityType, entityName: "test entity")
                {
                    Labels = new List <string>()
                };
                for (int k = 0; k < numOfLabels; k++)
                {
                    newEntity.Labels.Add($"testLabel-{Guid.NewGuid()}");
                }
                scenarioContext.AddEntity(newEntity);
            }
            for (int j = 0; j < numOfERCollections; j++)
            {
                //var erCollectionId = "test-" + Guid.NewGuid().ToString();
                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 getentities = scenarioContext.CreatedEntities().ToList();

                Log.Information($"Attempting to post new entity/entities synchronously in ER collection {erCollectionId}");

                var postEntitiesResponseMsg = await ERService.PostEntities(version, getentities, 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 {erCollectionId}");
                    Thread.Sleep(10000);
                }
                else
                {
                    postEntitiesResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.OK, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection {erCollectionId}");
                    var     response            = postEntitiesResponseMsg.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 getentities
                                          select entity.Id;

                    getEntityIDList.Should().BeEquivalentTo(successEntityIDList);
                    getEntityIDList.Count().Should().Be(successEntityIDList.Count());
                }
            }
        }
        public async Task WhenTheIMSUserPostsNewEntitiesWithGeoBoundaryAndGeoLocationWhereIsUsingVInAnERCollectionTimeS(int numOfEntities, string asyncHeader, string asyncValue, string version, int numOfTimes)
        {
            restClientUser = "******";
            List <GeoBoundary> GeoBoundaries = GeoBoundariesConstants.GeoBoundaryList;
            List <GeoLocation> GeoLocations  = GeoLocationsConstants.GeoLocationList;

            for (int i = 0; i < numOfEntities; i++)
            {
                GeoBoundary boundary; GeoLocation location;
                var         index = i;
                while (GeoBoundaries.Count <= index)
                {
                    index = index - GeoBoundaries.Count;
                }

                boundary = GeoBoundaries[index];

                index = i;

                while (GeoLocations.Count <= index)
                {
                    index = index - GeoLocations.Count;
                }

                location = GeoLocations[i];

                var newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: EntityTypes.EquipmentBrickEntityType, entityName: "test entity")
                {
                    GeoBoundary = boundary,
                    GeoLocation = location
                };

                scenarioContext.AddEntity(newEntity);
            }
            // var erCollectionId = "test-" + Guid.NewGuid().ToString();
            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 getentities = scenarioContext.CreatedEntities().ToList();

            Log.Information($"Attempting to post new entity/entities synchronously in ER collection {erCollectionId}");
            for (int i = 0; i < numOfTimes; i++)
            {
                var postEntitiesResponseMsg = await ERService.PostEntities(version, getentities, 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 {erCollectionId}");
                    Thread.Sleep(10000);
                }
                else
                {
                    postEntitiesResponseMsg.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            = postEntitiesResponseMsg.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 getentities
                                          select entity.Id;

                    getEntityIDList.Should().BeEquivalentTo(successEntityIDList);
                    getEntityIDList.Count().Should().Be(successEntityIDList.Count());
                }
            }
        }
        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]}");
                    }
                }
            }
        }