public void BasicEncodingTest() { byte[] kvfBytes = KeyValueFormEncoding.GetBytes(this.sampleData); string responseString = Encoding.UTF8.GetString(kvfBytes); Assert.IsFalse(responseString.Contains("\n\n")); Assert.IsTrue(responseString.EndsWith("\n", StringComparison.Ordinal)); int count = 0; foreach (string line in responseString.Split('\n')) { if (line.Length == 0) { break; } int colon = line.IndexOf(':'); Assert.IsTrue(colon > 0); string key = line.Substring(0, colon); string value = line.Substring(colon + 1); Assert.AreEqual(this.sampleData[key], value); count++; } Assert.AreEqual(this.sampleData.Count, count); }
public async Task DirectResponsesReceivedAsKeyValueForm() { var fields = new Dictionary <string, string> { { "var1", "value1" }, { "var2", "value2" }, }; var response = new HttpResponseMessage { Content = new StreamContent(new MemoryStream(KeyValueFormEncoding.GetBytes(fields))), }; Assert.IsTrue(MessagingUtilities.AreEquivalent(fields, await this.channel.ReadFromResponseCoreAsyncTestHook(response, CancellationToken.None))); }
public void DirectResponsesReceivedAsKeyValueForm() { var fields = new Dictionary <string, string> { { "var1", "value1" }, { "var2", "value2" }, }; var response = new CachedDirectWebResponse { CachedResponseStream = new MemoryStream(KeyValueFormEncoding.GetBytes(fields)), }; Assert.IsTrue(MessagingUtilities.AreEquivalent(fields, this.channel.ReadFromResponseCoreTestHook(response))); }
public async Task DirectResponsesSentUsingKeyValueForm() { IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); MessageDictionary messageFields = this.MessageDescriptions.GetAccessor(message); byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields); string expectedContentType = OpenIdChannel.KeyValueFormContentType; var directResponse = this.channel.PrepareDirectResponseTestHook(message); Assert.AreEqual(expectedContentType, directResponse.Content.Headers.ContentType.MediaType); byte[] actualBytes = await directResponse.Content.ReadAsByteArrayAsync(); Assert.IsTrue(MessagingUtilities.AreEquivalent(expectedBytes, actualBytes)); }
public void DirectResponsesSentUsingKeyValueForm() { IProtocolMessage message = MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired); MessageDictionary messageFields = this.MessageDescriptions.GetAccessor(message); byte[] expectedBytes = KeyValueFormEncoding.GetBytes(messageFields); string expectedContentType = OpenIdChannel.KeyValueFormContentType; OutgoingWebResponse directResponse = this.channel.PrepareDirectResponseTestHook(message); Assert.AreEqual(expectedContentType, directResponse.Headers[HttpResponseHeader.ContentType]); byte[] actualBytes = new byte[directResponse.ResponseStream.Length]; directResponse.ResponseStream.Read(actualBytes, 0, actualBytes.Length); Assert.IsTrue(MessagingUtilities.AreEquivalent(expectedBytes, actualBytes)); }
public void KVDictTest(byte[] kvform, IDictionary <string, string> dict, TestMode mode) { if ((mode & TestMode.Decoder) == TestMode.Decoder) { var d = this.keyValueForm.GetDictionary(new MemoryStream(kvform)); foreach (string key in dict.Keys) { Assert.AreEqual(d[key], dict[key], "Decoder fault: " + d[key] + " and " + dict[key] + " do not match."); } } if ((mode & TestMode.Encoder) == TestMode.Encoder) { var e = KeyValueFormEncoding.GetBytes(dict); Assert.IsTrue(MessagingUtilities.AreEquivalent(e, kvform), "Encoder did not produced expected result."); } }