public void ShouldWriteParameterPayloadInRequestWithoutModelAndWithoutFunctionImport() { Action <ODataJsonLightOutputContext> test = outputContext => { var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); parameterWriter.WriteValue("primitive", Guid.Empty); var resourceWriter = parameterWriter.CreateResourceWriter("complex"); resourceWriter.WriteStart(new ODataResource() { Properties = new[] { new ODataProperty { Name = "prop1", Value = 1 } } }); resourceWriter.WriteEnd(); var collectionWriter = parameterWriter.CreateCollectionWriter("collection"); collectionWriter.WriteStart(new ODataCollectionStart()); collectionWriter.WriteItem("item1"); collectionWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"primitive\":\"00000000-0000-0000-0000-000000000000\",\"complex\":{\"prop1\":1},\"collection\":[\"item1\"]}", writingResponse: false); }
public void WriteNullEntryWithOperation() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("entry", new EdmEntityTypeReference(entityType, true)); Action <ODataJsonLightOutputContext> test = outputContext => { var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceWriter("entry"); entryWriter.WriteStart((ODataResource)null); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"entry\":null}", writingResponse: false); }
public void WriteFeedWithoutOperation() { Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataResource(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceSetWriter("feed"); entryWriter.WriteStart(new ODataResourceSet()); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"feed\":[{\"ID\":1}]}", writingResponse: false); }
public void WriteFeedWithMultipleEntries() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmEntityType derivedType = new EdmEntityType("NS", "DerivedType", entityType); derivedType.AddProperty(new EdmStructuralProperty(derivedType, "Name", EdmCoreModel.Instance.GetString(false))); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("feed", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)))); Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataResource(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 } }; var entry2 = new ODataResource() { TypeName = "NS.DerivedType", }; entry2.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, new ODataProperty() { Name = "Name", Value = "TestName" } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceSetWriter("feed"); entryWriter.WriteStart(new ODataResourceSet()); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); entryWriter.WriteStart(entry2); entryWriter.WriteEnd(); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"feed\":[{\"ID\":1},{\"@odata.type\":\"#NS.DerivedType\",\"ID\":1,\"Name\":\"TestName\"}]}", writingResponse: false); }
public void ShouldWriteParameterPayloadInRequestWithTypeDefinition() { EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("Length", new EdmTypeDefinitionReference(new EdmTypeDefinition("NS", "Length", EdmPrimitiveTypeKind.Int32), false)); Action <ODataJsonLightOutputContext> test = outputContext => { var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation); parameterWriter.WriteStart(); parameterWriter.WriteValue("Length", 123); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"Length\":123}", writingResponse: false); }
public void WriteEntryAndComplex() { Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataResource(); var complex = new ODataResource() { Properties = new List <ODataProperty>() { new ODataProperty() { Name = "Name", Value = "ComplexName" } } }; entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 } }; var nestedComplexInfo = new ODataNestedResourceInfo() { Name = "complexProperty", IsCollection = false }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceWriter("entry"); entryWriter.WriteStart(entry); entryWriter.WriteStart(nestedComplexInfo); entryWriter.WriteStart(complex); entryWriter.WriteEnd(); entryWriter.WriteEnd(); entryWriter.WriteEnd(); var complexWriter = parameterWriter.CreateResourceWriter("complex"); complexWriter.WriteStart(complex); complexWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"entry\":{\"ID\":1,\"complexProperty\":{\"Name\":\"ComplexName\"}},\"complex\":{\"Name\":\"ComplexName\"}}", writingResponse: false); }
public void WriteEntryAndComplex() { Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataEntry(); var complex = new ODataComplexValue() { Properties = new List <ODataProperty>() { new ODataProperty() { Name = "Name", Value = "ComplexName" } } }; entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, new ODataProperty() { Name = "complexProperty", Value = complex } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateEntryWriter("entry"); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); parameterWriter.WriteValue("complex", complex); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"entry\":{\"ID\":1,\"complexProperty\":{\"Name\":\"ComplexName\"}},\"complex\":{\"Name\":\"ComplexName\"}}", writingResponse: false); }
public void WriteOpenEntry() { EdmEntityType entityType = new EdmEntityType("NS", "Entity", null, false, true); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("entry", new EdmEntityTypeReference(entityType, false)); Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataResource(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, new ODataProperty() { Name = "DynamicProperty", Value = "DynamicValue" } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceWriter("entry"); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"entry\":{\"ID\":1,\"DynamicProperty\":\"DynamicValue\"}}", writingResponse: false); }
public void WriteFeedWithOperation() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("feed", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)))); Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataEntry(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateFeedWriter("feed"); entryWriter.WriteStart(new ODataFeed()); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"feed\":[{\"ID\":1}]}", writingResponse: false); }
public void WriteContainedFeed() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); entityType.AddProperty(new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false))); EdmEntityType expandEntityType = new EdmEntityType("NS", "ExpandEntity"); expandEntityType.AddProperty(new EdmStructuralProperty(expandEntityType, "Id", EdmCoreModel.Instance.GetInt32(false))); expandEntityType.AddProperty(new EdmStructuralProperty(expandEntityType, "Name", EdmCoreModel.Instance.GetString(false))); entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Property1", Target = expandEntityType, TargetMultiplicity = EdmMultiplicity.Many }); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("entry", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)))); Action <ODataJsonLightOutputContext> test = outputContext => { var entry1 = new ODataResource(); entry1.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, }; var entry2 = new ODataResource(); entry2.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, new ODataProperty() { Name = "Name", Value = "TestName" } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceSetWriter("feed"); entryWriter.WriteStart(new ODataResourceSet()); entryWriter.WriteStart(entry1); entryWriter.WriteStart(new ODataNestedResourceInfo() { Name = "Property1", IsCollection = true }); entryWriter.WriteStart(new ODataResourceSet()); entryWriter.WriteStart(entry2); entryWriter.WriteEnd(); entryWriter.WriteEnd(); entryWriter.WriteEnd(); entryWriter.WriteEnd(); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"feed\":[{\"ID\":1,\"Property1\":[{\"ID\":1,\"Name\":\"TestName\"}]}]}", writingResponse: false); }