public void CustomReadLinksAppearInFullAndMinimalMetadata(string acceptHeader) { //Arrange OneToOneParent[] entities = MetadataTestHelpers.CreateInstances <OneToOneParent[]>(); var entity = entities.First(); string requestUrl = BaseAddress.ToLowerInvariant() + "/CustomReadLinkConventions/OneToOneParent(" + entity.Id + ")"; string expectedReadLinkUrl = "http://*****:*****@odata.readLink", result); } else { JsonAssert.DoesNotContainProperty("@odata.readLink", result); } }
public void CanFollowGeneratedNavigationLinks(string acceptHeader) { //Arrange OneToOneParent[] entities = MetadataTestHelpers.CreateInstances <OneToOneParent[]>(); OneToOneChild[] childEntities = entities.Select(x => x.Child).ToArray(); JArray returnedChildEntities = new JArray(); JArray returnedParentEntities; int[] returnedChildrenIdentities; string requestUrl = BaseAddress.ToLowerInvariant() + "/Relationships/OneToOneParent"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.SetAcceptHeader(acceptHeader); //Act HttpResponseMessage response = Client.SendAsync(request).Result; JObject result = response.Content.ReadAsAsync <JObject>().Result; returnedParentEntities = (JArray)result["value"]; for (int i = 0; i < returnedParentEntities.Count; i++) { string childUrl = (string)returnedParentEntities[i]["*****@*****.**"]; HttpRequestMessage childRequest = new HttpRequestMessage(HttpMethod.Get, childUrl); HttpResponseMessage childResponse = Client.SendAsync(childRequest).Result; JObject childEntry = childResponse.Content.ReadAsAsync <JObject>().Result; returnedChildEntities.Add(childEntry); } returnedChildrenIdentities = returnedChildEntities.Select(x => (int)x["Id"]).ToArray(); //Assert foreach (var returnedChildEntityId in returnedChildrenIdentities) { Assert.True(childEntities.Any(x => x.Id == returnedChildEntityId)); } }
public async Task MetadataIsCorrectForFeedsOfEntriesWithJustPrimitiveTypeProperties( string acceptHeader) { // Arrange EntityWithSimpleProperties[] entities = MetadataTestHelpers.CreateInstances <EntityWithSimpleProperties[]>(); string requestUrl = BaseAddress.ToLowerInvariant() + "/EntityWithSimpleProperties/"; string expectedContextUrl = BaseAddress.ToLowerInvariant() + "/$metadata#EntityWithSimpleProperties"; HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestUrl); message.SetAcceptHeader(acceptHeader); // Act var response = await Client.SendAsync(message); var result = await response.Content.ReadAsAsync <JObject>(); // Assert JsonAssert.ArrayLength(entities.Length, "value", result); if (acceptHeader.Contains("odata.metadata=none")) { JsonAssert.DoesNotContainProperty("@odata.context", result); } else { JsonAssert.PropertyEquals(expectedContextUrl, "@odata.context", result); } }
public void NavigationLinksAppearOnlyInFullMetadata(string acceptHeader) { //Arrange OneToOneParent[] entities = MetadataTestHelpers.CreateInstances <OneToOneParent[]>(); var entity = entities.First(); string requestUrl = BaseAddress.ToLowerInvariant() + "/Relationships/OneToOneParent(" + entity.Id + ")"; string expectedNavigationLink = BaseAddress.ToLowerInvariant() + "/Relationships/OneToOneParent(" + entity.Id + ")/Child"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.SetAcceptHeader(acceptHeader); //Act HttpResponseMessage response = Client.SendAsync(request).Result; JObject result = response.Content.ReadAsAsync <JObject>().Result; //Assert if (acceptHeader.Contains("odata.metadata=full")) { JsonAssert.PropertyEquals(expectedNavigationLink, "*****@*****.**", result); } else { JsonAssert.DoesNotContainProperty("*****@*****.**", result); } }
public void CanReturnTheWholeResultSetUsingNextLink(string acceptHeader) { //Arrange StubEntity[] entities = MetadataTestHelpers.CreateInstances <StubEntity[]>(); string nextUrlToQuery = BaseAddress.ToLowerInvariant() + "/StubEntity/"; JToken token = null; JArray returnedEntities = new JArray(); JObject result = null; //Act do { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, nextUrlToQuery); message.SetAcceptHeader(acceptHeader); HttpResponseMessage response = Client.SendAsync(message).Result; result = response.Content.ReadAsAsync <JObject>().Result; JArray currentResults = (JArray)result["value"]; for (int i = 0; i < currentResults.Count; i++) { returnedEntities.Add(currentResults[i]); } if (result.TryGetValue("@odata.nextLink", out token)) { nextUrlToQuery = (string)token; } else { nextUrlToQuery = null; } }while (nextUrlToQuery != null); //Assert Assert.Equal(entities.Length, returnedEntities.Count); }
public async Task MetadataIsCorrectForAnEntryWithJustPrimitiveTypeProperties(string acceptHeader) { // Arrange EntityWithSimpleProperties entity = MetadataTestHelpers.CreateInstances <EntityWithSimpleProperties[]>() .FirstOrDefault(); Assert.NotNull(entity); string requestUrl = BaseAddress + "/EntityWithSimpleProperties(" + entity.Id + ")"; string expectedContextUrl = BaseAddress.ToLowerInvariant() + "/$metadata#EntityWithSimpleProperties/$entity"; // Act var response = await Client.GetWithAcceptAsync(requestUrl, acceptHeader); var result = await response.Content.ReadAsAsync <JObject>(); // Assert JsonAssert.DoesNotContainProperty("*****@*****.**", result); JsonAssert.DoesNotContainProperty("*****@*****.**", result); JsonAssert.DoesNotContainProperty("*****@*****.**", result); string doublePropertyValue = (string)result["DoubleProperty"]; if (!doublePropertyValue.Equals("INF", StringComparison.InvariantCulture) && !doublePropertyValue.Equals("-INF", StringComparison.InvariantCulture) && !doublePropertyValue.Equals("NaN", StringComparison.InvariantCulture)) { JsonAssert.DoesNotContainProperty("*****@*****.**", result); } JsonAssert.DoesNotContainProperty("*****@*****.**", result); if (acceptHeader.Contains("odata.metadata=none")) { JsonAssert.DoesNotContainProperty("@odata.context", result); } else { ODataUrlAssert.UrlEquals(expectedContextUrl, result, "@odata.context", BaseAddress); } if (acceptHeader.Contains("odata.metadata=full")) { ODataUrlAssert.UrlEquals(requestUrl, result, "@odata.id", BaseAddress); JsonAssert.PropertyEquals("#Binary", "*****@*****.**", result); JsonAssert.PropertyEquals("#Duration", "*****@*****.**", result); JsonAssert.PropertyEquals("#Decimal", "*****@*****.**", result); JsonAssert.PropertyEquals("#Single", "*****@*****.**", result); JsonAssert.PropertyEquals("#Guid", "*****@*****.**", result); JsonAssert.PropertyEquals("#Int16", "*****@*****.**", result); JsonAssert.PropertyEquals("#Int64", "*****@*****.**", result); JsonAssert.PropertyEquals("#SByte", "*****@*****.**", result); JsonAssert.PropertyEquals("#DateTimeOffset", "*****@*****.**", result); } }
public async Task MetadataIsCorrectForThePropertiesOfAnEntryWithJustPrimitiveTypeProperties( string acceptHeader, string propertyName, string edmType) { // Arrange EntityWithSimpleProperties entity = MetadataTestHelpers.CreateInstances <EntityWithSimpleProperties[]>() .FirstOrDefault(); Assert.NotNull(entity); string expectedContextUrl = BaseAddress + "/$metadata#EntityWithSimpleProperties(" + entity.Id + ")/" + propertyName; string[] inferableTypes = new string[] { "Edm.Int32", "Edm.Double", "Edm.String", "Edm.Boolean" }; // Act var entryUrl = BaseAddress + "/EntityWithSimpleProperties(" + entity.Id + ")/" + propertyName; var response = await Client.GetWithAcceptAsync(entryUrl, acceptHeader); var result = await response.Content.ReadAsAsync <JObject>(); bool isODataNull = result.Property("@odata.null") != null; // Assert if (acceptHeader.Contains("odata.metadata=none")) { if (!isODataNull) { JsonAssert.DoesNotContainProperty("@odata.*", result); } else { JsonAssert.Equals(true, (bool)result.Property("@odata.null")); } } else { ODataUrlAssert.UrlEquals(expectedContextUrl, result, "@odata.context", BaseAddress); if (!acceptHeader.Contains("odata.metadata=full") || (inferableTypes.Contains(edmType) && !result.IsSpecialValue())) { JsonAssert.DoesNotContainProperty("@odata.type", result); } else { var unqualifiedTypename = "#" + edmType.Substring(4); JsonAssert.PropertyEquals(unqualifiedTypename, "@odata.type", result); } } }
public void MetadataIsCorrectForThePropertiesOfAnEntryWithJustPrimitiveTypeProperties(string acceptHeader, string propertyName, string edmType) { //Arrange EntityWithSimpleProperties[] entities = MetadataTestHelpers.CreateInstances <EntityWithSimpleProperties[]>(); EntityWithSimpleProperties entity = entities.First(); string entryUrl = BaseAddress.ToLowerInvariant() + "/EntityWithSimpleProperties(" + entity.Id + ")/" + propertyName; HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, entryUrl); message.SetAcceptHeader(acceptHeader); string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#" + edmType; string[] inferableTypes = new string[] { "Edm.Int32", "Edm.Double", "Edm.String", "Edm.Boolean" }; bool isODataNull = false; //Act var response = Client.SendAsync(message).Result; JObject result = response.Content.ReadAsJObject(); isODataNull = result.Property("odata.null") != null; //Assert if (isODataNull) { expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#Edm.Null"; } if (acceptHeader.Contains("nometadata")) { if (!isODataNull) { JsonAssert.DoesNotContainProperty("odata.*", result); } else { JsonAssert.Equals(true, (bool)result.Property("odata.null")); } } else { JsonAssert.Equal(expectedMetadataUrl, "odata.metadata", result); if (!acceptHeader.Contains("fullmetadata") || (inferableTypes.Contains(edmType) && !IsSpecialValue(result))) { JsonAssert.DoesNotContainProperty("odata.type", result); } else { JsonAssert.Equal(edmType, "odata.type", result); } } }
public void MetadataIsCorrectForAnEntryWithJustPrimitiveTypeProperties(string acceptHeader) { //Arrange EntityWithSimpleProperties[] entities = MetadataTestHelpers.CreateInstances <EntityWithSimpleProperties[]>(); EntityWithSimpleProperties entity = entities.First(); string requestUrl = BaseAddress.ToLowerInvariant() + "/EntityWithSimpleProperties(" + entity.Id + ")"; string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#EntityWithSimpleProperties/@Element"; HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestUrl); message.SetAcceptHeader(acceptHeader); //Act HttpResponseMessage response = Client.SendAsync(message).Result; JObject result = response.Content.ReadAsJObject(); //Assert JsonAssert.DoesNotContainProperty("*****@*****.**", result); JsonAssert.DoesNotContainProperty("*****@*****.**", result); JsonAssert.DoesNotContainProperty("*****@*****.**", result); if (!(((string)result["DoubleProperty"]).Equals("Infinity", StringComparison.InvariantCultureIgnoreCase) || ((string)result["DoubleProperty"]).Equals("-Infinity", StringComparison.InvariantCultureIgnoreCase) || ((string)result["DoubleProperty"]).Equals("NaN", StringComparison.InvariantCultureIgnoreCase))) { JsonAssert.DoesNotContainProperty("*****@*****.**", result); } JsonAssert.DoesNotContainProperty("*****@*****.**", result); if (acceptHeader.Contains("nometadata")) { JsonAssert.DoesNotContainProperty("odata.metadata", result); } else { JsonAssert.Equal(expectedMetadataUrl, "odata.metadata", result); } if (acceptHeader.Contains("fullmetadata")) { JsonAssert.Equal(requestUrl, "odata.id", result); JsonAssert.Equal("Edm.Binary", "*****@*****.**", result); JsonAssert.Equal("Edm.DateTime", "*****@*****.**", result); JsonAssert.Equal("Edm.Decimal", "*****@*****.**", result); JsonAssert.Equal("Edm.Single", "*****@*****.**", result); JsonAssert.Equal("Edm.Guid", "*****@*****.**", result); JsonAssert.Equal("Edm.Int16", "*****@*****.**", result); JsonAssert.Equal("Edm.Int64", "*****@*****.**", result); JsonAssert.Equal("Edm.SByte", "*****@*****.**", result); JsonAssert.Equal("Edm.DateTimeOffset", "*****@*****.**", result); } }
public void ODataCountAndNextLinkAnnotationsAppearsOnAllMetadataLevelsWhenSpecified(string acceptHeader) { //Arrange StubEntity[] entities = MetadataTestHelpers.CreateInstances <StubEntity[]>(); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, BaseAddress.ToLowerInvariant() + "/StubEntity/Default.Paged"); message.SetAcceptHeader(acceptHeader); string expectedNextLink = new Uri("http://*****:*****@odata.count", result); JsonAssert.PropertyEquals(expectedNextLink, "@odata.nextLink", result); }
public void MetadataAnnotationAppearsOnlyForFullAndMinimalMetadata(string acceptHeader) { //Arrange StubEntity[] entities = MetadataTestHelpers.CreateInstances <StubEntity[]>(); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, BaseAddress.ToLowerInvariant() + "/StubEntity/"); message.SetAcceptHeader(acceptHeader); string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#StubEntity"; //Act HttpResponseMessage response = Client.SendAsync(message).Result; JObject result = response.Content.ReadAsAsync <JObject>().Result; //Assert if (acceptHeader.Contains("odata.metadata=none")) { JsonAssert.DoesNotContainProperty("@odata.context", result); } else { JsonAssert.PropertyEquals(expectedMetadataUrl, "@odata.context", result); } }