private static void AssertProtectingFormCreatesExpectedXml(string originalXml, string expectedXml, IGenerateSignature signature)
        {
            using (var streamIn = new MemoryStream())
            {
                using (var streamOut = new MemoryStream())
                {
                    var writer = new StreamWriter(streamIn);
                    writer.Write(originalXml);
                    writer.Flush();

                    var formProtection = new FormsIntegrityUtility(signature, "PLACEHOLDER");
                    formProtection.SignForms(streamIn, streamOut);

                    streamOut.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(streamOut))
                    {
                        var xmlOut = reader.ReadToEnd();
                        Assert.AreEqual(expectedXml, xmlOut);
                    }
                }
            }
        }
        public void ShouldOmitExtraneousWhitespaceWhenPassingXmlToSignatureGenerator()
        {
            const string originalXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <shop xmlns=""http://schemas.restbucks.com/shop"">
              <model xmlns=""http://www.w3.org/2002/xforms"">
            <instance>
              <shop xmlns=""http://schemas.restbucks.com/shop"">
            <status>Awaiting Payment</status>
              </shop>
            </instance>
            <submission resource=""/orders?c=123&amp;s=PLACEHOLDER"" method=""put"" mediatype=""application/xml"" />
              </model>
            </shop>";
            const string expectedXml = @"<shop xmlns=""http://schemas.restbucks.com/shop""><status>Awaiting Payment</status></shop>";

            var mockSignature = MockRepository.GenerateMock<IGenerateSignature>();
            mockSignature.Expect(s => s.GenerateSignature(expectedXml)).Return("signature");

            using (var streamIn = new MemoryStream())
            {
                using (var streamOut = new MemoryStream())
                {
                    var writer = new StreamWriter(streamIn);
                    writer.Write(originalXml);
                    writer.Flush();

                    var formProtection = new FormsIntegrityUtility(mockSignature, "PLACEHOLDER");
                    formProtection.SignForms(streamIn, streamOut);
                }
            }

            mockSignature.VerifyAllExpectations();
        }