public void NamedStreamValidationTest() { var testCases = new NamedStreamValidationTestCase[] { // null property is not valid new NamedStreamValidationTestCase { StreamProperty = (ODataProperty)null, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_EnumerableContainsANullItem", "ODataResource.Properties"), }, // null property name is not valid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = null, Value = new ODataStreamReferenceValue() }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_PropertiesMustHaveNonEmptyName"), }, // empty property name is not valid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = string.Empty, Value = new ODataStreamReferenceValue() }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_PropertiesMustHaveNonEmptyName"), }, // ReadLink and EditLink cannot be both null new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamReferenceValueMustHaveEditLinkOrReadLink"), }, // empty content type is not valid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { ContentType = string.Empty } }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamReferenceValueEmptyContentType"), }, // etag without an edit link is invalid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { ReadLink = new Uri("someUri", UriKind.RelativeOrAbsolute), ETag = "\"etagValue\"" } }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamReferenceValueMustHaveEditLinkToHaveETag"), }, // relative read link without base uri is invalid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { ReadLink = new Uri("someUri", UriKind.RelativeOrAbsolute) } }, ExpectedException = ODataExpectedExceptions.ODataException("ODataWriter_RelativeUriUsedWithoutBaseUriSpecified", "someUri"), }, // relative edit link without base uri is invalid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { EditLink = new Uri("someUri", UriKind.RelativeOrAbsolute) } }, ExpectedException = ODataExpectedExceptions.ODataException("ODataWriter_RelativeUriUsedWithoutBaseUriSpecified", "someUri"), }, }; var testDescriptors = testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataResource() { Properties = new ODataProperty[] { testCase.StreamProperty } }, testConfiguration => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = testCase.ExpectedException })); // TODO: Fix places where we've lost JsonVerbose coverage to add JsonLight this.CombinatorialEngineProvider.RunCombinations( testDescriptors.PayloadCases(WriterPayloads.NamedStreamPayloads), this.WriterTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => false), (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void NamedStreamValidationTest() { var testCases = new NamedStreamValidationTestCase[] { // null property is not valid new NamedStreamValidationTestCase { StreamProperty = (ODataProperty)null, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_EnumerableContainsANullItem", "ODataEntry.Properties"), }, // null property name is not valid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = null, Value = new ODataStreamReferenceValue() }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_PropertiesMustHaveNonEmptyName"), }, // empty property name is not valid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = string.Empty, Value = new ODataStreamReferenceValue() }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_PropertiesMustHaveNonEmptyName"), }, // ReadLink and EditLink cannot be both null new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamReferenceValueMustHaveEditLinkOrReadLink"), }, // empty content type is not valid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { ContentType = string.Empty } }, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamReferenceValueEmptyContentType"), }, // etag without an edit link is invalid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { ReadLink = new Uri("someUri", UriKind.RelativeOrAbsolute), ETag = "\"etagValue\"" }}, ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamReferenceValueMustHaveEditLinkToHaveETag"), }, // relative read link without base uri is invalid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { ReadLink = new Uri("someUri", UriKind.RelativeOrAbsolute) }}, ExpectedException = ODataExpectedExceptions.ODataException("ODataWriter_RelativeUriUsedWithoutBaseUriSpecified", "someUri"), }, // relative edit link without base uri is invalid new NamedStreamValidationTestCase { StreamProperty = new ODataProperty() { Name = "Stream1", Value = new ODataStreamReferenceValue() { EditLink = new Uri("someUri", UriKind.RelativeOrAbsolute) }}, ExpectedException = ODataExpectedExceptions.ODataException("ODataWriter_RelativeUriUsedWithoutBaseUriSpecified", "someUri"), }, }; var testDescriptors = testCases.Select(testCase => new PayloadWriterTestDescriptor<ODataItem>( this.Settings, new ODataEntry() { Properties = new ODataProperty[] { testCase.StreamProperty } }, testConfiguration => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = testCase.ExpectedException })); // TODO: Fix places where we've lost JsonVerbose coverage to add JsonLight this.CombinatorialEngineProvider.RunCombinations( testDescriptors.PayloadCases(WriterPayloads.NamedStreamPayloads), this.WriterTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => ! tc.IsRequest && tc.Format == ODataFormat.Atom), (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }