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.ReadAsObject <JObject>(); // Assert Assert.Null(result.Property("*****@*****.**")); Assert.Null(result.Property("*****@*****.**")); Assert.Null(result.Property("*****@*****.**")); string doublePropertyValue = (string)result["DoubleProperty"]; if (!doublePropertyValue.Equals("INF", StringComparison.InvariantCulture) && !doublePropertyValue.Equals("-INF", StringComparison.InvariantCulture) && !doublePropertyValue.Equals("NaN", StringComparison.InvariantCulture)) { Assert.Null(result.Property("*****@*****.**")); } Assert.Null(result.Property("*****@*****.**")); if (acceptHeader.Contains("odata.metadata=none")) { Assert.Null(result.Property("@odata.context")); } else { ODataUrlAssert.UrlEquals(expectedContextUrl, result, "@odata.context", BaseAddress); } if (acceptHeader.Contains("odata.metadata=full")) { ODataUrlAssert.UrlEquals(requestUrl, result, "@odata.id", BaseAddress); Assert.Equal("#Binary", result.Property("*****@*****.**").Value); Assert.Equal("#Duration", result.Property("*****@*****.**").Value); Assert.Equal("#Decimal", result.Property("*****@*****.**").Value); Assert.Equal("#Single", result.Property("*****@*****.**").Value); Assert.Equal("#Guid", result.Property("*****@*****.**").Value); Assert.Equal("#Int16", result.Property("*****@*****.**").Value); Assert.Equal("#Int64", result.Property("*****@*****.**").Value); Assert.Equal("#SByte", result.Property("*****@*****.**").Value); Assert.Equal("#DateTimeOffset", result.Property("*****@*****.**").Value); } }
public async Task TransientCustomActionsGetAdvertisedInDerivedTypesWithTheTargetWhenAvailable(string acceptHeader) { // Arrange string baseActionName = "TransientActionBaseType"; string qualifiedBaseActionName = "Default." + baseActionName; string baseContainerName = "#" + qualifiedBaseActionName; string baseTargetUrl = BaseAddress + "/CustomActionConventions/BaseEntity(8)/" + qualifiedBaseActionName; string derivedActionName = "TransientActionDerivedType"; string qualifiedDerivedActionName = "Default." + derivedActionName; string derivedContainerName = "#" + qualifiedDerivedActionName; string derivedTargetUrl = String.Format("{0}/CustomActionConventions/BaseEntity(8)/{1}/{2}", BaseAddress, typeof(DerivedEntity).FullName, qualifiedDerivedActionName); // Act var requestUrl = BaseAddress.ToLowerInvariant() + "/CustomActionConventions/BaseEntity(8)/"; var response = await Client.GetWithAcceptAsync(requestUrl, acceptHeader); var result = await response.Content.ReadAsObject <JObject>(); // Assert if (acceptHeader.Contains("odata.metadata=none")) { JsonAssert.DoesNotContainProperty(baseContainerName, result); JsonAssert.DoesNotContainProperty(derivedContainerName, result); } else { JsonAssert.ContainsProperty(baseContainerName, result); JObject container = (JObject)result[baseContainerName]; var actualBaseTargetUrl = container["target"].ToString(); ODataUrlAssert.UrlEquals(baseTargetUrl, actualBaseTargetUrl, BaseAddress); JsonAssert.ContainsProperty(derivedContainerName, result); JObject derivedContainer = (JObject)result[derivedContainerName]; var actualDerivedTargetUrl = derivedContainer["target"].ToString(); ODataUrlAssert.UrlEquals(actualDerivedTargetUrl, derivedTargetUrl, BaseAddress); if (acceptHeader.Contains("odata.metadata=full")) { JsonAssert.PropertyEquals(derivedActionName, "title", derivedContainer); JsonAssert.PropertyEquals(baseActionName, "title", container); } else { JsonAssert.DoesNotContainProperty("title", derivedContainer); JsonAssert.DoesNotContainProperty("title", container); } } }
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 async Task TransientActionsGetAdvertisedWhenTheyAreAvailable(string acceptHeader) { //Arrange string actionName = "TransientActionBaseType"; string qualifiedActionName = "Default." + actionName; string containerName = "#" + qualifiedActionName; string expectedTargetUrl = BaseAddress + "/Actions/BaseEntity(2)/" + qualifiedActionName; string expectedContextUrl = BaseAddress + "/Actions/$metadata#BaseEntity/$entity"; //Act var requestUrl = BaseAddress + "/Actions/BaseEntity(2)/"; var response = await Client.GetWithAcceptAsync(requestUrl, acceptHeader); var result = await response.Content.ReadAsObject <JObject>(); // Assert if (acceptHeader.Contains("odata.metadata=full")) { // full metadata JObject container = (JObject)result[containerName]; var actualTargetUrl = container["target"].ToString(); ODataUrlAssert.UrlEquals(expectedTargetUrl, actualTargetUrl, BaseAddress); JsonAssert.PropertyEquals(actionName, "title", container); var actualContextUrl = result["@odata.context"].ToString(); ODataUrlAssert.UrlEquals(expectedContextUrl, actualContextUrl, BaseAddress); JsonAssert.PropertyEquals("#Microsoft.Test.E2E.AspNet.OData.Formatter.JsonLight.Metadata.Model.BaseEntity", "@odata.type", result); } else if (acceptHeader.Contains("odata.metadata=none")) { // none metadta JsonAssert.DoesNotContainProperty("@odata.context", result); JsonAssert.DoesNotContainProperty("@odata.type", result); JsonAssert.PropertyEquals("2", "Id", result); } else { // minimal metadata & "application/json" var actualContextUrl = result["@odata.context"].ToString(); ODataUrlAssert.UrlEquals(expectedContextUrl, actualContextUrl, BaseAddress); JsonAssert.DoesNotContainProperty("@odata.type", result); } }
public async Task TransientActionsGetAdvertisedForDerivedTypesWhenTheyAreAvailable(string acceptHeader) { // Arrange string baseActionName = "TransientActionBaseType"; string baseQualifiedActionName = "Default." + baseActionName; string baseContainerName = "#" + baseQualifiedActionName; string baseTargetUrl = BaseAddress + "/Actions/BaseEntity(8)/" + baseQualifiedActionName; string derivedActionName = "TransientActionDerivedType"; string derivedQualifiedActionName = "Default." + derivedActionName; string derivedContainerName = "#" + derivedQualifiedActionName; string derviedTargetUrl = string.Format("{0}/Actions/BaseEntity(8)/{1}/{2}", BaseAddress, typeof(DerivedEntity).FullName, derivedQualifiedActionName); // Act var requestUrl = BaseAddress + "/Actions/BaseEntity(8)/"; var response = await Client.GetWithAcceptAsync(requestUrl, acceptHeader); var result = await response.Content.ReadAsObject <JObject>(); // Assert JObject baseContainer = (JObject)result[baseContainerName]; JObject derivedContainer = (JObject)result[derivedContainerName]; if (acceptHeader.Contains("odata.metadata=full")) { var actualBaseTargetUrl = baseContainer["target"].ToString(); ODataUrlAssert.UrlEquals(baseTargetUrl, actualBaseTargetUrl, BaseAddress); JsonAssert.PropertyEquals(baseActionName, "title", baseContainer); var actualDerivedTargetUrl = derivedContainer["target"].ToString(); ODataUrlAssert.UrlEquals(derviedTargetUrl, actualDerivedTargetUrl, BaseAddress); JsonAssert.PropertyEquals(derivedActionName, "title", derivedContainer); } else { JsonAssert.Equals(null, baseContainer); JsonAssert.Equals(null, derivedContainer); } }
public async Task TransientCustomActionsGetAdvertisedWithTheTargetWhenAvailable(string acceptHeader) { // Arrange string actionName = "TransientActionBaseType"; string qualifiedActionName = "Default." + actionName; string containerName = "#" + qualifiedActionName; string targetUrl = BaseAddress + "/CustomActionConventions/BaseEntity(2)/" + qualifiedActionName; // Act var requestUri = BaseAddress + "/CustomActionConventions/BaseEntity(2)/"; var response = await Client.GetWithAcceptAsync(requestUri, acceptHeader); var result = await response.Content.ReadAsObject <JObject>(); // Assert if (acceptHeader.Contains("odata.metadata=none")) { JsonAssert.DoesNotContainProperty(containerName, result); } else { JsonAssert.ContainsProperty(containerName, result); JObject container = (JObject)result[containerName]; var actualTargetUrl = container["target"].ToString(); ODataUrlAssert.UrlEquals(targetUrl, actualTargetUrl, BaseAddress); //JsonAssert.PropertyEquals(targetUrl, "target", container); if (acceptHeader.Contains("odata.metadata=full")) { JsonAssert.PropertyEquals(actionName, "title", container); } else { JsonAssert.DoesNotContainProperty("title", container); } } }