Example #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 void WhenTheIMSUserUploadsFiles(string userName, string file1, string file2)
        {
            var filesToUpload = new List <string>
            {
                file1,
                file2
            };
            // var ercollectionId = "testER-" + Guid.NewGuid().ToString();
            string ercollectionId = this.scenarioContext.Get <dynamic>("CollectionsResponse");

            scenarioContext.AddERCollections(ercollectionId);
            var token            = FileService.GetIMSAccessToken(userName);
            var fileEntityIdList = new List <string>();

            for (int i = 0; i <= filesToUpload.Count - 1; i++)
            {
                Log.Information($"Attempting to upload file synchronously in ER collection in Blob storage{ercollectionId}");
                var fileUploadResponseMessage = FileService.UploadFile(token, filesToUpload[i], ercollectionId);
                fileUploadResponseMessage.StatusCode.Should().Be(HttpStatusCode.OK, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post file er collection {ercollectionId}");

                var     response = fileUploadResponseMessage.Content;
                JObject o        = JObject.Parse(response);
                var     entityId = (string)o.SelectToken("data.entityId");
                fileEntityIdList.Add(entityId);
            }
            scenarioContext.Set(fileEntityIdList, "FileEntityIdList");
        }
Example #4
0
        public async Task ThenValidateTheIMSUserCopiesEntitiesAndRelationshipsFromSourceERCollectionToDestinationERCollection()
        {
            restClientUser = "******";
            var sourceERCollectionId = "";
            var erCollectionIdList   = scenarioContext.CreatedERCollections().ToList();

            for (int i = 0; i < erCollectionIdList.Count; i++)
            {
                sourceERCollectionId = erCollectionIdList[i];
            }
            // var destinationERCollectionId = "destination-" + Guid.NewGuid().ToString();

            string destinationERCollectionId = this.scenarioContext.Get <dynamic>("CollectionsResponse");

            scenarioContext.AddERCollections(destinationERCollectionId);
            var copyErCollectionsList = new List <CopyERCollections> {
                new CopyERCollections {
                    SourceERCollectionID      = sourceERCollectionId,
                    DestinationERCollectionID = destinationERCollectionId
                }
            };

            Log.Information($"Attempting to copy entities and relationships from source ER collection {sourceERCollectionId} to destination ER collection{destinationERCollectionId}");
            var postEntitiesResponseMsg = await ERService.CopyERCollections(copyErCollectionsList);

            var response = JObject.Parse(postEntitiesResponseMsg.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult()).SelectToken("data");

            postEntitiesResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.Accepted, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be able to post a new entity in er collection");
        }
        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 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());
                }
            }
        }