- Sources.zip
- GeneratedCrawler.Sample
- GeneratedCrawler.Sample.sln
- GeneratedCrawler.Sample.suo
- GeneratedCrawler.Sample.vsmdi
- GeneratedCrawler.Sample
- GeneratedCrawler.Tests
- LightWebTestFramework
- bin
- Debug
- Release
- LightWebTestFramework.csproj
- Microsoft.VisualStudio.QualityTools.WebTestFramework
- Microsoft.VisualStudio.TestTools.WebTesting.Rules
- Microsoft.VisualStudio.TestTools.WebTesting
- obj
- Debug
- Properties
- WebTesting.Properties.Resources.resources
- Local.testsettings
- TraceAndTestImpact.testsettings
|
using System;
using System.IO;
using System.Text;
namespace LightWebTestFramework
{
[Serializable]
public class StringHttpBody : IHttpBody, ICloneable
{
internal const string ContentTypeJSON = "application/json";
private string m_contentType;
private string m_bodyString = string.Empty;
private bool m_insertByteOrderMark;
public string BodyString
{
get
{
return this.m_bodyString;
}
set
{
this.m_bodyString = value;
}
}
public string ContentType
{
get
{
return this.m_contentType;
}
set
{
this.m_contentType = value;
}
}
public bool InsertByteOrderMark
{
get
{
return this.m_insertByteOrderMark;
}
set
{
this.m_insertByteOrderMark = value;
}
}
public void WriteHttpBody(WebTestRequest request, Stream bodyStream)
{
if (this.m_bodyString == null)
{
return;
}
if (this.InsertByteOrderMark)
{
Encoding encoding = request.Encoding;
if (request.Encoding.EncodingName.Equals(Encoding.UTF8.EncodingName, StringComparison.OrdinalIgnoreCase))
{
encoding = Encoding.UTF8;
}
else
{
if (request.Encoding.EncodingName.Equals(Encoding.UTF32.EncodingName, StringComparison.OrdinalIgnoreCase))
{
encoding = Encoding.UTF32;
}
else
{
if (request.Encoding.EncodingName.Equals(Encoding.Unicode.EncodingName, StringComparison.OrdinalIgnoreCase))
{
encoding = Encoding.Unicode;
}
}
}
using (StreamWriter streamWriter = new StreamWriter(bodyStream, encoding))
{
streamWriter.Write(this.m_bodyString);
return;
}
}
byte[] bytes = request.Encoding.GetBytes(this.m_bodyString);
bodyStream.Write(bytes, 0, bytes.Length);
}
public object Clone()
{
return (StringHttpBody)base.MemberwiseClone();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am currently the CTO of
Metaco, we are leveraging the Bitcoin Blockchain for delivering financial services.
I also developed a tool to make IaaS on Azure more easy to use
IaaS Management Studio.
If you want to contact me, go
this way