/// <summary> /// Verifies that the result of the test is what the test expected. /// </summary> /// <param name="stream">The stream after writing the message content. This method should use it /// to read the message content and verify it.</param> /// <param name="payloadKind">The payload kind specified in the test descriptor.</param> /// <param name="testConfiguration">The test configuration to use.</param> public override void VerifyResult( TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger) { // Get observed payload #if !SILVERLIGHT var observed = TestWriterUtils.ReadToString(message); if (logger != null) logger.LogPayload(TestWriterUtils.BaseLineFixup(observed)); #endif // TODO: Handle SILVERLIGHT }
/// <summary> /// Verifies the result of the write-read. /// </summary> /// <param name="message">The test message is not used but is required to keep the method signature the same.</param> /// <param name="payloadKind">The payload kind is not used but is required to keep the method signature the same.</param> /// <param name="testConfiguration">The test configuration is used for some fixups.</param> public override void VerifyResult(TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger=null) { //TODO: Use Logger to verify result, right now this change is only to unblock writer testcase checkin Debug.Assert(ObservedElement != null, "ObservedElement not provided"); // Fixup the expected and get the content type ODataPayloadElement expected = this.ExpectedPayload.DeepCopy(); ODataPayloadElement observed = this.ObservedElement.DeepCopy(); observed.Accept(new RemoveTypeNameAnnotationFromComplexInCollection()); expected.Accept(new ReorderProperties()); expected.Accept(new RemoveComplexWithNoProperties()); // Compare this.settings.PayloadElementComparer.Compare(expected, observed); }
/// <summary> /// Verifies that the result of the test is what the test expected. /// </summary> /// <param name="stream">The stream after writing the message content. This method should use it /// to read the message content and verify it.</param> /// <param name="payloadKind">The payload kind specified in the test descriptor.</param> /// <param name="testConfiguration">The test configuration to use.</param> public override void VerifyResult( TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger) { this.settings.Assert.IsTrue(payloadKind == ODataPayloadKind.MetadataDocument, "Only metadata payload kind is supported."); // read the message content using the Taupo infrastructure ExceptionUtilities.CheckArgumentNotNull(message.TestStream, "stream != null"); #if !SILVERLIGHT var observed = TestWriterUtils.ReadToString(message); if (logger != null) logger.LogPayload(TestWriterUtils.BaseLineFixup(observed)); #endif // TODO: Handle SILVERLIGHT }
/// <summary> /// Creates an <see cref="ODataCollectionWriter"/> for the specified format and the specified version and /// invokes the specified methods on it. It then parses /// the written Xml/JSON and compares it to the expected result as specified in the descriptor. /// </summary> /// <param name="descriptor">The test descriptor to process.</param> /// <param name="testConfiguration">The configuration of the test.</param> /// <param name="assert">The assertion handler to report errors to.</param> /// <param name="baselineLogger">Logger to log baseline.</param> internal static void WriteAndVerifyCollectionPayload(CollectionWriterTestDescriptor descriptor, WriterTestConfiguration testConfiguration, AssertionHandler assert, BaselineLogger baselineLogger) { baselineLogger.LogConfiguration(testConfiguration); baselineLogger.LogModelPresence(descriptor.Model); // serialize to a memory stream using (var memoryStream = new MemoryStream()) using (var testMemoryStream = new TestStream(memoryStream, ignoreDispose: true)) { TestMessage testMessage = null; Exception exception = TestExceptionUtils.RunCatching(() => { using (var messageWriter = TestWriterUtils.CreateMessageWriter(testMemoryStream, testConfiguration, assert, out testMessage, null, descriptor.Model)) { IEdmTypeReference itemTypeReference = descriptor.ItemTypeParameter; ODataCollectionWriter writer = itemTypeReference == null ? messageWriter.CreateODataCollectionWriter() : messageWriter.CreateODataCollectionWriter(itemTypeReference); WriteCollectionPayload(messageWriter, writer, true, descriptor); } }); exception = TestExceptionUtils.UnwrapAggregateException(exception, assert); WriterTestExpectedResults expectedResults = descriptor.ExpectedResultCallback(testConfiguration); TestWriterUtils.ValidateExceptionOrLogResult(testMessage, testConfiguration, expectedResults, exception, assert, descriptor.TestDescriptorSettings.ExpectedResultSettings.ExceptionVerifier, baselineLogger); TestWriterUtils.ValidateContentType(testMessage, expectedResults, true, assert); } }
/// <summary> /// Verifies that the result of the test (the message reader) is what the test expected. /// </summary> /// <param name="stream">Stream which contains the results of the write.</param> /// <param name="payloadKind">The payload kind specified in the test descriptor.</param> /// <param name="testConfiguration">The test configuration to use.</param> public virtual void VerifyResult( TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger) { // throw if not implemented; eventually we can make this method abstract when the WriterTestExpectedResults // are not used directly anymore throw new NotImplementedException("Subclasses must implement their own validation logic."); }
/// <summary> /// Runs the test specified by this test descriptor. /// </summary> /// <param name="testConfiguration">The test configuration to use for running the test.</param> public virtual void RunTest(WriterTestConfiguration testConfiguration, BaselineLogger logger) { if (this.ShouldSkipForTestConfiguration(testConfiguration)) { return; } // Wrap the memory stream in a non-disposing stream so we can dump the message content // even in the case of a failure where the message stream normally would get disposed. logger.LogConfiguration(testConfiguration); logger.LogModelPresence(this.Model); this.messageStream = new NonDisposingStream(new MemoryStream()); TestMessage message = this.CreateOutputMessage(this.messageStream, testConfiguration); IEdmModel model = this.GetMetadataProvider(); WriterTestExpectedResults expectedResult = this.GetExpectedResult(testConfiguration); ExceptionUtilities.Assert(expectedResult != null, "The expected result could not be determined for the test. Did you specify it?"); Exception exception = TestExceptionUtils.RunCatching(() => { using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(message, model, testConfiguration, this.settings.Assert)) { this.WritePayload(messageWriterWrapper, testConfiguration); expectedResult.VerifyResult(message, this.PayloadKind, testConfiguration, logger); } }); try { expectedResult.VerifyException(exception); } catch (Exception failureException) { this.TraceFailureInformation(message, this.messageStream, testConfiguration); throw failureException; } }