/// <summary>
            /// Verifies the result of reading the part headers.
            /// </summary>
            /// <param name="streamWrapper">The stream buffer used to read the headers from.</param>
            /// <param name="headers">The headers read from the part.</param>
            /// <param name="isChangeSetPart">true if we detected a changeset part; otherwise false.</param>
            private void VerifyResult(BatchReaderStreamWrapper streamWrapper, BatchOperationHeadersWrapper headers, bool isChangeSetPart)
            {
                base.VerifyResult(streamWrapper.BatchBuffer);

                if (this.ExpectChangeSetPart.HasValue)
                {
                    this.Assert.AreEqual(this.ExpectChangeSetPart.Value, isChangeSetPart,
                                         string.Format("\r\n{0}:\r\nExpected changeset part is '{1}' but reported value is '{2}'.", this.DebugDescription, this.ExpectChangeSetPart.Value, isChangeSetPart));
                }

                if (this.ExpectedHeaders != null)
                {
                    this.Assert.IsNotNull(headers, string.Format("Expected {0} headers but none were found.", this.ExpectedHeaders.Count()));

                    foreach (KeyValuePair <string, string> expectedHeader in this.ExpectedHeaders)
                    {
                        // check that the expected header is present
                        string actualHeaderValue;
                        if (headers.TryGetValue(expectedHeader.Key, out actualHeaderValue))
                        {
                            this.Assert.AreEqual(expectedHeader.Value, actualHeaderValue,
                                                 string.Format("Expected value '{0}' for header '{1}' but found '{2}'.", expectedHeader.Value, expectedHeader.Key, actualHeaderValue));
                        }
                        else
                        {
                            this.Assert.Fail(string.Format("Did not find expected header '{0}'.", expectedHeader.Key));
                        }
                    }

                    if (headers.Any(kvp => !this.ExpectedHeaders.Any(kvp2 => string.Compare(kvp.Key, kvp2.Key, /*ignoreCase*/ true) == 0)))
                    {
                        string expectedHeaders = string.Join(", ", this.ExpectedHeaders.Select(kvp => kvp.Key).ToArray());
                        string actualHeaders   = string.Join(", ", headers.Select(kvp => kvp.Key).ToArray());
                        this.Assert.Fail("Found unexpected headers in the message headers.\r\n"
                                         + "Expected headers: " + expectedHeaders + "\r\n"
                                         + "Actual headers: " + actualHeaders);
                    }
                }
            }
示例#2
0
            /// <summary>
            /// Verifies the result.
            /// </summary>
            /// <param name="headers">The headers read from the part.</param>
            private void VerifyResult(BatchOperationHeadersWrapper headers)
            {
                if (this.ExpectedHeaders != null)
                {
                    this.settings.Assert.IsNotNull(headers, string.Format("Expected {0} headers but none were found.", this.ExpectedHeaders.Count()));

                    foreach (KeyValuePair <string, string> expectedHeader in this.ExpectedHeaders)
                    {
                        // check that the expected header is present
                        if (!headers.ContainsKeyOrdinal(expectedHeader.Key))
                        {
                            this.settings.Assert.Fail(string.Format("Did not find expected header '{0}'.", expectedHeader.Key));
                        }

                        string actualValue;
                        headers.TryGetValue(expectedHeader.Key, out actualValue);
                        this.settings.Assert.AreEqual(expectedHeader.Value, actualValue, "Expected value '{0}' but found value '{1}'.", expectedHeader.Value, actualValue);
                    }

                    int headerCount = headers.Count();
                    this.settings.Assert.AreEqual(this.ExpectedHeaders.Count, headerCount, "Expected {0} headers but found {1}.", this.ExpectedHeaders.Count, headerCount);

                    // Make sure the enumerable works the same way in expected and actual enumerables
                    IEnumerator <KeyValuePair <string, string> > expectedEnumerator = this.ExpectedHeaders.GetEnumerator();
                    IEnumerator <KeyValuePair <string, string> > actualEnumerator   = headers.GetEnumerator();
                    using (expectedEnumerator)
                        using (actualEnumerator)
                        {
                            while (expectedEnumerator.MoveNext())
                            {
                                this.settings.Assert.IsTrue(actualEnumerator.MoveNext(), "Differing numbers of items should have been checked before.");

                                this.settings.Assert.AreEqual(expectedEnumerator.Current, actualEnumerator.Current, "Items don't match.");
                            }
                        }
                }
            }