Ejemplo n.º 1
0
        internal async Task <RestClientResponse <T> > ExecuteRequest <T>(string endpoint, HttpMethod method) where T : class
        {
            RestClientResponse <T> rcResponse = null;
            string responseContent            = string.Empty;
            HttpResponseMessage response      = null;
            HttpRequestMessage  request       = new HttpRequestMessage(method, endpoint);

            response = await Client.SendAsync(request, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);

            HttpStatusCode statusCode = response.StatusCode;

            if (statusCode != HttpStatusCode.OK)
            {
                responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                HttpRequestException ex = JsonConvert.DeserializeObject <HttpRequestException>(responseContent);
                throw ex;
            }
            else
            {
                responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                T body = JsonConvert.DeserializeObject <T>(responseContent);

                rcResponse          = new RestClientResponse <T>();
                rcResponse.Body     = body;
                rcResponse.Request  = request;
                rcResponse.Response = response;
            }

            return(rcResponse);
        }
Ejemplo n.º 2
0
        public async Task WhenTheIMSUserChangeTheEntityTypeForThePostedEntityWhereIsUsingVInTheERCollectionTimeS(string asyncHeader, string asyncValue, string version, int numOfTimes)
        {
            restClientUser = "******";

            var getNewEntities     = scenarioContext.CreatedEntities().ToList();
            var erCollectionIdList = scenarioContext.CreatedERCollections().ToList();

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

                List <Entity> partialUpdateEntitiesList = new List <Entity>();
                for (int j = 0; j < getNewEntities.Count; j++)
                {
                    Log.Information($"Attempting to update entities from ER Collection {erCollectionIdList[i]}");

                    Entity newEntity = new Entity(id: getNewEntities[j].Id, entityType: BrickEntityTypes.LocationBrickEntityType, entityName: getNewEntities[j].EntityName);
                    partialUpdateEntitiesList.Add(newEntity);
                }

                RestClientResponse <PlatformItemResponse> postEntityResponseMsg = null;
                try
                {
                    postEntityResponseMsg = await ERService.PostEntities(version, partialUpdateEntitiesList, headers);
                }
                catch (RestClientException ex)
                {
                    scenarioContext.AddRestClientExceptionErrors(ex);
                }
            }
        }
        public async Task ThenValidateIMSUserCannotDeleteTheRelationshipSFromTheERCollection()
        {
            restClientUser = "******";

            var getNewRelationships = scenarioContext.CreatedRelationships().ToList();
            var erCollectionIdList  = scenarioContext.CreatedERCollections().ToList();

            for (int i = 0; i < erCollectionIdList.Count; i++)
            {
                var headers = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[i])
                };

                for (int j = 0; j < getNewRelationships.Count; j++)
                {
                    Log.Information($"Attempting to delete relationship from ER Collection {erCollectionIdList[i]}");
                    RestClientResponse <PlatformItemResponse> deleteRelationshipResponseMsg = null;
                    try
                    {
                        deleteRelationshipResponseMsg = await ERService.DeleteRelationship(getNewRelationships[j].Id, headers);

                        deleteRelationshipResponseMsg.Response.StatusCode.Should().Be(HttpStatusCode.NotFound, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be not able to delete relationship {getNewRelationships[j].Id} from er collection {erCollectionIdList[i]}");
                    }
                    catch (RestClientException ex)
                    {
                        ex.Response.StatusCode.Should().Be(HttpStatusCode.BadRequest, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be not able to delete relationship {getNewRelationships[j].Id} from er collection {erCollectionIdList[i]}");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public async Task WhenTheIMSUserPostsNewEntityWhereIsWithInvalidTokenUsingVInAnERCollectionTimeS(int numOfEntities, string asyncHeader, string asyncValue, string version, int numOfTimes)
        {
            GenerateTokenForInvalidIMSUser();
            restClientUser = "******";
            string erCollectionId = this.scenarioContext.Get <dynamic>("CollectionsResponse");

            //scenarioContext.AddERCollections(erCollectionId);
            for (int i = 0; i < numOfEntities; i++)
            {
                var newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: BrickEntityTypes.FloorBrickEntityType, entityName: "test entity");
                scenarioContext.AddEntity(newEntity);
            }

            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 without an ER collection");
            for (int i = 0; i < numOfTimes; i++)
            {
                RestClientResponse <PlatformItemResponse> postEntityResponseMsg = null;
                try
                {
                    postEntityResponseMsg = await ERService.PostEntities(version, getentities, headers);
                }
                catch (RestClientException ex)
                {
                    ex.Response.StatusCode.Should().Be(HttpStatusCode.Unauthorized, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should not be able to post a new entity without an er collection");
                }
            }
        }
Ejemplo n.º 5
0
        public async Task ThenValidateIMSUserGetsForbiddenErrorCodeForDeleteEntitiesRequestAsync(HttpStatusCode errorCode)
        {
            restClientUser = "******";

            var getNewEntities     = scenarioContext.CreatedEntities().ToList();
            var erCollectionIdList = scenarioContext.CreatedERCollections().ToList();

            for (int i = 0; i < erCollectionIdList.Count; i++)
            {
                var headers = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[i])
                };

                for (int j = 0; j < getNewEntities.Count; j++)
                {
                    Log.Information($"Attempting to delete entities from ER Collection {erCollectionIdList[i]}");
                    RestClientResponse <PlatformItemResponse> deleteAEntityResponseMsg = null;

                    try
                    {
                        deleteAEntityResponseMsg = await ERService.DeleteEntity(getNewEntities[j].Id, headers);
                    }
                    catch (RestClientException ex)
                    {
                        ex.Response.StatusCode.Should().Be(errorCode, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be not able to delete entity {getNewEntities[j].Id} from er collection {erCollectionIdList[i]}");
                        break;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public async Task WhenTheIMSUserPostsNewEntitiesWhereIsInAnERCollectionTimeS(int numOfEntities, string asyncHeader, string asyncValue, string version, int numOfTimes)
        {
            restClientUser = "******";
            for (int i = 0; i < numOfEntities; i++)
            {
                var newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: BrickEntityTypes.FloorBrickEntityType, entityName: "test entity");
                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 in ER collection {erCollectionId}");
            for (int i = 0; i < numOfTimes; i++)
            {
                RestClientResponse <PlatformItemResponse> postEntityResponseMsg = null;
                try
                {
                    postEntityResponseMsg = await ERService.PostEntities(version, getentities, headers);
                }
                catch (RestClientException ex)
                {
                    scenarioContext.AddRestClientExceptionErrors(ex);
                }
            }
        }
Ejemplo n.º 7
0
        public async Task WhenTheIMSUserPostsNewEntityIsWithoutTheERCollectionTimes(int numOfEntities, string asyncHeader, string asyncValue, string version, int numOfTimes)
        {
            restClientUser = "******";
            for (int i = 0; i < numOfEntities; i++)
            {
                var newEntity = new Entity(id: $"test-{Guid.NewGuid()}", entityType: BrickEntityTypes.FloorBrickEntityType, entityName: "test entity");
                scenarioContext.AddEntity(newEntity);
            }
            var headers = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(asyncHeader, asyncValue)
            };
            var getentities = scenarioContext.CreatedEntities().ToList();

            Log.Information($"Attempting to post new entity/entities without an ER collection");
            for (int i = 0; i < numOfTimes; i++)
            {
                RestClientResponse <PlatformItemResponse> postEntityResponseMsg = null;
                try
                {
                    postEntityResponseMsg = await ERService.PostEntities(version, getentities, headers);
                }
                catch (RestClientException ex)
                {
                    ex.Response.StatusCode.Should().Be(HttpStatusCode.BadRequest, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should not be able to post a new entity without an er collection");
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets available version list of nuget packages using exact package Id
        /// TODO:
        ///     If you want to filter on pre-release and stable, provide the override for the function
        ///     the URL has two properties, package id and if it's a pre-release
        /// </summary>
        /// <param name="exactPackageId"></param>
        /// <returns></returns>
        public List <NuGetVersion> GetAvailablePackageVersion(string exactPackageId, bool includePreRelease = true)
        {
            List <string> responseVerList = null;
            //List<Version> availableVersionList = new List<Version>();
            List <NuGetVersion> availableVersionList = new List <NuGetVersion>();
            string endPointUrl = string.Format(Nuget_Operation_EnumPkgVersions, exactPackageId, includePreRelease);

            Task <RestClientResponse <EnumeratePkgVersionModel> > pkgVersionTask = Task.Run <RestClientResponse <EnumeratePkgVersionModel> >(async() =>
                                                                                                                                             await this.ExecuteRequest <EnumeratePkgVersionModel>(endPointUrl, HttpMethod.Get).ConfigureAwait(false));

            RestClientResponse <EnumeratePkgVersionModel> rcResponse = pkgVersionTask.GetAwaiter().GetResult();
            EnumeratePkgVersionModel enumVers = rcResponse.Body;

            responseVerList = enumVers.data;

            if (responseVerList == null)
            {
                //throw new ApplicationException("Unable to retrieve available package versions. Please try again");
                UtilLogger.LogWarning("Unable to retrieve available package versions for nuget pacakge '{0}'", exactPackageId);
            }

            foreach (string ver in responseVerList)
            {
                NuGetVersion nugVer = new NuGetVersion(ver);
                availableVersionList.Add(nugVer);
            }

            UtilLogger.LogInfo(availableVersionList, "Available versions on nuget.org for Pacakge '{0}'", exactPackageId);

            return(availableVersionList);
        }
Ejemplo n.º 9
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}");
                }
            }
        }
Ejemplo n.º 10
0
        private RestClientResponse ConvertResponse(IRestResponse response)
        {
            var restClientResponse = new RestClientResponse();

            restClientResponse.StatusCode = response.StatusCode;

            foreach (var header in response.Headers)
            {
                restClientResponse.Headers.Add(header.Name, header.Value.ToString());
            }

            restClientResponse.Content = response.Content;

            return(restClientResponse);
        }
Ejemplo n.º 11
0
        public async Task ThenIMSUserCannotDeleteTheEntityWithoutTheERCollectionAsync()
        {
            restClientUser = "******";
            var getNewEntities = scenarioContext.CreatedEntities().ToList();

            for (int i = 0; i < getNewEntities.Count; i++)
            {
                Log.Information($"Attempting to delete entities without ER Collection");
                RestClientResponse <PlatformItemResponse> deleteAEntityResponseMsg = null;
                try
                {
                    deleteAEntityResponseMsg = await ERService.DeleteEntity(getNewEntities[i].Id);
                }
                catch (RestClientException ex)
                {
                    ex.Response.StatusCode.Should().Be(HttpStatusCode.BadRequest, $"{restClientUser} user with {_testCfg.ImsScopes} scopes should be not able to delete entity {getNewEntities[i].Id} without ER collection");
                }
            }
        }
        public async Task WhenTheIMSUserPostsNewRelationshipSBetweenTheEntitiesWhereIsWithInvalidDestinationEntityIdUsingVInTheERCollectionTimeS(int numOfRelationship, string asyncHeader, string asyncValue, 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;
                newRelationship = new Relationship(id: $"test-{Guid.NewGuid()}", relationshipType: BrickRelationshipTypes.BrickEquipmentIsLocatedInLocation, relationshipName: "test relationship", sourceEntityId: sourceEntityId, destinationEntityId: $"test-{destinationEntityId}");
                scenarioContext.AddRelationship(newRelationship);
            }
            var erCollectionIdList = scenarioContext.CreatedERCollections().ToList();

            for (int i = 0; i < erCollectionIdList.Count; i++)
            {
                var headers = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>(PlatformHeaders.ErCollectionId, erCollectionIdList[i]),
                    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 {erCollectionIdList[i]}");
                RestClientResponse <PlatformItemResponse> postRelationshipResponseMsg = null;
                try
                {
                    postRelationshipResponseMsg = await ERService.PostRelationship(version, getRelationships, headers);
                }
                catch (RestClientException ex)
                {
                    scenarioContext.AddRestClientExceptionErrors(ex);
                }
            }
        }
 public static void RemovePartialUpdateResponses(this ScenarioContext scenarioContext, RestClientResponse <PlatformItemResponse> response)
 {
     scenarioContext.AllPartialUpdateResponses().Remove(response);
 }
 public static void RemoveHttpResponse(this ScenarioContext scenarioContext, RestClientResponse <PlatformCollectionResponse> response)
 {
     scenarioContext.AllHttpResponses().Remove(response);
 }
        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);
            //}
        }