public void MetadataDocumentWriterAtomTest() { MetadataWriterTestDescriptor testDescriptor = new MetadataWriterTestDescriptor(this.Settings) { Model = new EdmModel().Fixup(), ContentType = "application/unsupported", ExpectedODataExceptionMessage = "A default MIME type could not be found for the requested payload in format 'Atom'.", }; this.CombinatorialEngineProvider.RunCombinations( this.WriterTestConfigurationProvider.AtomFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testConfiguration) => testDescriptor.RunTest(testConfiguration, this.Logger)); }
public void MetadataDocumentWithODataAnnotationsWriterTest() { IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildODataAnnotationTestModel(false); // NamedStream IEdmEntityType personType = model.FindType("TestModel.PersonType") as IEdmEntityType; this.Assert.IsNotNull(personType, "Expected to find the person type."); // MIME types IEdmProperty nameProperty = personType.DeclaredProperties.Where(p => p.Name == "Name").Single(); model.SetMimeType(nameProperty, "text/plain"); IEdmProperty addressProperty = personType.DeclaredProperties.Where(p => p.Name == "Address").Single(); IEdmComplexType addressType = addressProperty.Type.Definition as IEdmComplexType; this.Assert.IsNotNull(addressType, "Expected address to have a complex type."); IEdmProperty zipProperty = addressType.DeclaredProperties.Where(p => p.Name == "Zip").Single(); model.SetMimeType(zipProperty, "text/plain"); IEnumerable <IEdmOperationImport> functionGroup = model.EntityContainer.FindOperationImports("ServiceOperation1"); IEdmOperationImport functionImport = functionGroup.Single() as IEdmOperationImport; this.Assert.IsNotNull(functionImport, "Expected to find the function import."); model.SetMimeType(functionImport.Operation, "img/jpeg"); MetadataWriterTestDescriptor[] testDescriptors = new MetadataWriterTestDescriptor[] { new MetadataWriterTestDescriptor(this.Settings) { EdmVersion = EdmVersion.V40, Model = model, } }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration, this.Logger); }); }
public void MetadataDocumentWriterTest() { // TODO: add more interesting metadata payloads IEnumerable<MetadataWriterTestDescriptor> metadataDescriptors = MetadataWriterTestDescriptorGenerator.CreateMetadataDocumentWriterDescriptors(this.Settings); MetadataWriterTestDescriptor[] manualDescriptors = new MetadataWriterTestDescriptor[] { new MetadataWriterTestDescriptor(this.Settings) { EdmVersion = EdmVersion.V40, Model = CreateTestModel(MetadataUtils.EdmxVersion4) }, }; IEnumerable<MetadataWriterTestDescriptor> testDescriptors = metadataDescriptors.Concat(manualDescriptors); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration, this.Logger)); }
public void MetadataFunctionImportAnnotationsWriterTest() { // HttpMethod var interestingValues = new [] { new { HttpMethod = "GET" }, new { HttpMethod = "POST" }, new { HttpMethod = string.Empty }, new { HttpMethod = "45" }, }; EdmModel model = (EdmModel)Microsoft.Test.OData.Utils.Metadata.TestModels.BuildODataAnnotationTestModel(false); var container = (EdmEntityContainer)model.EntityContainer; foreach (var value in interestingValues) { var action = new EdmAction("TestModel", "ActionImport_" + value.HttpMethod, null, true, null); model.AddElement(action); IEdmActionImport actionImport = container.AddActionImport(action); this.Assert.IsNotNull(actionImport, "Expected to find the function import."); } MetadataWriterTestDescriptor[] testDescriptors = new MetadataWriterTestDescriptor[] { new MetadataWriterTestDescriptor(this.Settings) { EdmVersion = EdmVersion.V40, Model = model, } }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration, this.Logger); }); }
public void MetadataDocumentWriterTest() { // TODO: add more interesting metadata payloads IEnumerable <MetadataWriterTestDescriptor> metadataDescriptors = MetadataWriterTestDescriptorGenerator.CreateMetadataDocumentWriterDescriptors(this.Settings); MetadataWriterTestDescriptor[] manualDescriptors = new MetadataWriterTestDescriptor[] { new MetadataWriterTestDescriptor(this.Settings) { EdmVersion = EdmVersion.V40, Model = CreateTestModel(MetadataUtils.EdmxVersion4) }, }; IEnumerable <MetadataWriterTestDescriptor> testDescriptors = metadataDescriptors.Concat(manualDescriptors); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration, this.Logger)); }
public void MetadataDocumentWriterErrorTest() { MetadataWriterTestDescriptor[] errorDescriptors = new MetadataWriterTestDescriptor[] { // EdmLib writes entity types without key //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.EntityTypeWithoutKey, // ExpectedODataExceptionMessage = "foo", //}, // EdmLib writes duplicate types and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.DuplicateEntityTypes, // ExpectedODataExceptionMessage = "foo2", //}, // EdmLib writes duplicate types and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.DuplicateComplexTypes, // ExpectedODataExceptionMessage = "foo3", //}, // EdmLib writes duplicate properties and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.ComplexTypeWithDuplicateProperties, // ExpectedODataExceptionMessage = "foo4", //}, // EdmLib writes duplicate properties and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.EntityTypeWithDuplicateProperties, // ExpectedODataExceptionMessage = "foo5", //}, }; IEnumerable <MetadataWriterErrorTestCase> testCases = errorDescriptors.Select(desc => new MetadataWriterErrorTestCase { TestDescriptor = desc, }); IEnumerable <MetadataWriterErrorTestCase> manualTestCases = new MetadataWriterErrorTestCase[] { new MetadataWriterErrorTestCase { TestDescriptor = new MetadataWriterTestDescriptor(this.Settings) { Model = new EdmModel().Fixup(), ExpectedException = new TaupoNotSupportedException("Asynchronous metadata writing is not supported.") }, RunInAsync = true, }, new MetadataWriterErrorTestCase { TestDescriptor = new MetadataWriterTestDescriptor(this.Settings) { Model = new EdmModel().Fixup(), ExpectedODataExceptionMessage = "A metadata document cannot be written to request payloads. Metadata documents are only supported in responses.", }, RunInRequest = true, }, }; var allTestCases = testCases.Concat(manualTestCases); this.CombinatorialEngineProvider.RunCombinations( allTestCases, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent, (testCase, testConfiguration) => { if (testCase.RunInAsync == testConfiguration.Synchronous) { return; } if (testCase.RunInRequest != testConfiguration.IsRequest) { return; } testCase.TestDescriptor.RunTest(testConfiguration, this.Logger); }); }
public void MetadataDocumentWriterErrorTest() { MetadataWriterTestDescriptor[] errorDescriptors = new MetadataWriterTestDescriptor[] { // EdmLib writes entity types without key //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.EntityTypeWithoutKey, // ExpectedODataExceptionMessage = "foo", //}, // EdmLib writes duplicate types and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.DuplicateEntityTypes, // ExpectedODataExceptionMessage = "foo2", //}, // EdmLib writes duplicate types and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.DuplicateComplexTypes, // ExpectedODataExceptionMessage = "foo3", //}, // EdmLib writes duplicate properties and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.ComplexTypeWithDuplicateProperties, // ExpectedODataExceptionMessage = "foo4", //}, // EdmLib writes duplicate properties and test infrastructure can't handle them //new MetadataWriterTestDescriptor(this.Settings) //{ // PayloadModel = TestModels.InvalidModels.EntityTypeWithDuplicateProperties, // ExpectedODataExceptionMessage = "foo5", //}, }; IEnumerable<MetadataWriterErrorTestCase> testCases = errorDescriptors.Select(desc => new MetadataWriterErrorTestCase { TestDescriptor = desc, }); IEnumerable<MetadataWriterErrorTestCase> manualTestCases = new MetadataWriterErrorTestCase[] { new MetadataWriterErrorTestCase { TestDescriptor = new MetadataWriterTestDescriptor(this.Settings) { Model = new EdmModel().Fixup(), ExpectedException = new TaupoNotSupportedException("Asynchronous metadata writing is not supported.") }, RunInAsync = true, }, new MetadataWriterErrorTestCase { TestDescriptor = new MetadataWriterTestDescriptor(this.Settings) { Model = new EdmModel().Fixup(), ExpectedODataExceptionMessage = "A metadata document cannot be written to request payloads. Metadata documents are only supported in responses.", }, RunInRequest = true, }, }; var allTestCases = testCases.Concat(manualTestCases); this.CombinatorialEngineProvider.RunCombinations( allTestCases, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent, (testCase, testConfiguration) => { if (testCase.RunInAsync == testConfiguration.Synchronous) { return; } if (testCase.RunInRequest != testConfiguration.IsRequest) { return; } testCase.TestDescriptor.RunTest(testConfiguration, this.Logger); }); }
public void MetadataFunctionImportAnnotationsWriterTest() { // HttpMethod var interestingValues = new [] { new { HttpMethod = "GET" }, new { HttpMethod= "POST" }, new { HttpMethod= string.Empty }, new { HttpMethod = "45" }, }; EdmModel model = (EdmModel) Microsoft.Test.OData.Utils.Metadata.TestModels.BuildODataAnnotationTestModel(false); var container = (EdmEntityContainer) model.EntityContainer; foreach (var value in interestingValues) { var action = new EdmAction("TestModel", "ActionImport_" + value.HttpMethod, null, true, null); model.AddElement(action); IEdmActionImport actionImport = container.AddActionImport(action); this.Assert.IsNotNull(actionImport, "Expected to find the function import."); } MetadataWriterTestDescriptor[] testDescriptors = new MetadataWriterTestDescriptor[] { new MetadataWriterTestDescriptor(this.Settings) { EdmVersion = EdmVersion.V40, Model = model, } }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration, this.Logger); }); }
public void MetadataDocumentWithODataAnnotationsWriterTest() { IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildODataAnnotationTestModel(false); // NamedStream IEdmEntityType personType = model.FindType("TestModel.PersonType") as IEdmEntityType; this.Assert.IsNotNull(personType, "Expected to find the person type."); // MIME types IEdmProperty nameProperty = personType.DeclaredProperties.Where(p => p.Name == "Name").Single(); model.SetMimeType(nameProperty, "text/plain"); IEdmProperty addressProperty = personType.DeclaredProperties.Where(p => p.Name == "Address").Single(); IEdmComplexType addressType = addressProperty.Type.Definition as IEdmComplexType; this.Assert.IsNotNull(addressType, "Expected address to have a complex type."); IEdmProperty zipProperty = addressType.DeclaredProperties.Where(p => p.Name == "Zip").Single(); model.SetMimeType(zipProperty, "text/plain"); IEnumerable<IEdmOperationImport> functionGroup = model.EntityContainer.FindOperationImports("ServiceOperation1"); IEdmOperationImport functionImport = functionGroup.Single() as IEdmOperationImport; this.Assert.IsNotNull(functionImport, "Expected to find the function import."); model.SetMimeType(functionImport.Operation, "img/jpeg"); MetadataWriterTestDescriptor[] testDescriptors = new MetadataWriterTestDescriptor[] { new MetadataWriterTestDescriptor(this.Settings) { EdmVersion = EdmVersion.V40, Model = model, } }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.DefaultFormatConfigurationsWithIndent .Where(tc => tc.Synchronous && !tc.IsRequest), (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration, this.Logger); }); }