public void ThenTheResponseMatchesTheCreatedItem()
        {
            var    createdItem  = context.GetDataItems().Last();
            string responseJson = (string)context[constants.responseContent];
            string itemJson     = JsonConvert.SerializeObject(createdItem);

            itemJson = JsonHelper.AddPropertyToJsonString(itemJson, "_links", "[{}]");

            var result = JsonHelper.CompareJsonString(itemJson, responseJson);

            result.Should().BeTrue("Because the data returned should match the created item");
        }
        public void GivenIMakeARequestToTheServiceTaxonomyAPI(string p0, Table table)
        {
            string requestBody  = "{}";
            string param        = (context.ContainsKey(constants.requestParam) ? context[constants.requestParam].ToString() : "");
            var    requestItems = table.SingleColumnToDictionary();

            foreach (var item in requestItems)
            {
                requestBody = JsonHelper.AddPropertyToJsonString(requestBody, item.Key, item.Value);
            }
            var response = RestHelper.Post(context.GetTaxonomyUri(p0, param), requestBody, context.GetTaxonomyApiHeaders());

            //response.StatusCode.Should().Be(HttpStatusCode.OK);
            context[constants.responseStatus]  = response.StatusCode;
            context[constants.responseContent] = response.Content;
        }
        public string AddLinksToJson(string json, _DataItem item)
        {
            int    count = item.Uri.Count(f => f == '/');
            string curie = GetNth(item.Uri, '/', count - 1);
            string id    = item.Uri.Substring(item.Uri.LastIndexOf("/") + 1);


            JObject linkDetails = new JObject();

            var groups = item.linkedItems.Select(x => x.RelationshipType)
                         .GroupBy(r => r)
                         .Select(g => new { Name = g.Key.ToString(), Count = g.Count() })
                         .OrderBy(o => o.Name);

            if (groups.Count() > 0)
            {
                linkDetails.Add(new JProperty("self", item.Uri));
                linkDetails.Add(new JProperty("curies",
                                              new JArray(
                                                  new JObject(
                                                      new JProperty("name", "cont"),
                                                      new JProperty("href", curie)
                                                      )
                                                  )
                                              )
                                );
            }

            foreach (var group in groups)
            {
                bool       asArray      = group.Count > 1;
                JContainer groupMembers = linkDetails;
                if (asArray)
                {
                    groupMembers = new JArray();
                }

                foreach (var linkItem in item.linkedItems.Where(x => x.RelationshipType == group.Name).OrderByDescending(x => x.Title))
                {
                    JObject link = new JObject(
                        new JProperty("href", linkItem.RelatedItem.Uri.Replace(curie, string.Empty)),
                        new JProperty("title", linkItem.Title),
                        new JProperty("contentType", linkItem.RelatedItem.TypeName)
                        );
                    if (asArray)
                    {
                        groupMembers.Add(link);
                    }
                    else
                    {
                        groupMembers.Add(new JProperty($"cont:{linkItem.RelationshipType}", link));
                    }
                }
                if (asArray)
                {
                    linkDetails.Add(new JProperty($"cont:{group.Name}", groupMembers));
                }
            }
            json = JsonHelper.AddPropertyToJsonString(json, "id", id);
            json = JsonHelper.AddPropertyToJsonString(json, "_links", linkDetails);
            return(json);
        }