public async Task ConverterConstructorObsolete() { var formatter = new JsonApiMediaTypeFormatter( new StringEnumConverter()); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/companies/456/"); _output.WriteLine(result.ToString()); Assert.Equal("National", result["data"]["attributes"]["location"].Value<string>()); } }
public async Task UrlBuilderConstructorObsolete() { var formatter = new JsonApiMediaTypeFormatter( new CanonicalUrlPathBuilder()); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/people/"); _output.WriteLine(result.ToString()); var relatedUrl = result["data"][0]["relationships"]["job"]["links"]["related"] .Value<string>(); Assert.Equal("http://localhost/corporations/456/", relatedUrl); } }
public async Task DefaultConstructorObsolete() { var formatter = new JsonApiMediaTypeFormatter(); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/companies/456/"); _output.WriteLine(result.ToString()); Assert.Equal(1, result["data"]["attributes"]["location"].Value<int>()); result = await client.GetJsonResponseAsync("api/people/"); _output.WriteLine(result.ToString()); var relatedUrl = result["data"][0]["relationships"]["job"]["links"]["related"] .Value<string>(); Assert.Equal("http://localhost/api/people/0/employer/", relatedUrl); } }
public async Task GivesUsefulErrorObsolete() { var formatter = new JsonApiMediaTypeFormatter(); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/broken/123/"); _output.WriteLine(result.ToString()); var error = result["errors"][0]; Assert.Equal("https://github.com/joukevandermaas/saule/wiki", error["links"]["about"].Value<string>()); Assert.Equal("Saule.JsonApiException", error["code"].Value<string>()); Assert.Equal("Saule.JsonApiException: You must add a [ReturnsResourceAttribute] to action methods.", error["detail"].Value<string>()); } }
public async Task AppliesSortingBeforePaginationObsolete(string path) { var formatter = new JsonApiMediaTypeFormatter(); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result1 = await client.GetJsonResponseAsync($"api/{path}/people?sort=age"); var result2 = await client.GetJsonResponseAsync($"api/{path}/people?sort=age&page[number]=1"); _output.WriteLine(result1.ToString()); _output.WriteLine(result2.ToString()); var ages1 = ((JArray)result1["data"]) .Select(p => p["attributes"]["age"].Value<int>()) .ToList(); var ages2 = ((JArray)result2["data"]) .Select(p => p["attributes"]["age"].Value<int>()) .ToList(); var sorted = ages1.Concat(ages2).OrderBy(a => a).ToList(); Assert.Equal(sorted, ages1.Concat(ages2).ToList()); } }
public async Task AppliesSortingConditionallyObsolete() { var formatter = new JsonApiMediaTypeFormatter(); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/people?sort=age"); _output.WriteLine(result.ToString()); var ages = ((JArray)result["data"]) .Select(p => p["attributes"]["age"].Value<int>()) .ToList(); var sorted = ages.OrderBy(a => a).ToList(); Assert.NotEqual(sorted, ages); } }
public async Task AppliesFilteringObsolete() { var formatter = new JsonApiMediaTypeFormatter(); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/query/people?filter[last-name]=Russel"); _output.WriteLine(result.ToString()); var names = ((JArray)result["data"]) .Select(p => p["attributes"]["last-name"].Value<string>()) .ToList(); var filtered = names.Where(a => a == "Russel").ToList(); Assert.Equal(filtered.Count, names.Count); } }
public async Task AppliesPaginationObsolete() { var formatter = new JsonApiMediaTypeFormatter(); using (var server = new ObsoleteSetupJsonApiServer(formatter)) { var client = server.GetClient(); var result = await client.GetJsonResponseAsync("api/companies/"); _output.WriteLine(result.ToString()); Assert.Equal(12, (result["data"] as JArray)?.Count); } }