public static class Zip
{
public static byte[] Decompress(byte[] zippedData)
{
byte[] decompressedData = null;
using (MemoryStream outputStream = new MemoryStream())
{
using (MemoryStream inputStream = new MemoryStream(zippedData))
{
using (GZipStream zip = new GZipStream(inputStream, CompressionMode.Decompress))
{
zip.CopyTo(outputStream);
}
}
decompressedData = outputStream.ToArray();
}
return decompressedData;
}
public static byte[] Compress(byte[] plainData)
{
byte[] compressesData = null;
using (MemoryStream outputStream = new MemoryStream())
{
using (GZipStream zip = new GZipStream(outputStream, CompressionMode.Compress))
{
zip.Write(plainData, 0, plainData.Length);
}
//Dont get the MemoryStream data before the GZipStream is closed
//since it doesn’t yet contain complete compressed data.
//GZipStream writes additional data including footer information when its been disposed
compressesData = outputStream.ToArray();
}
return compressesData;
}
}
And MS Test
[TestClass]
public class ZipTEST
{
[TestMethod]
public void TestMethod1()
{
string text = "Hello World";
byte [] data = System.Text.Encoding.UTF8.GetBytes(text);
byte [] compressedData = Zip.Compress(data);
byte [] decompressedData = Zip.Decompress(compressedData);
string textAfterComDecompress = System.Text.Encoding.UTF8.GetString(decompressedData);
Assert.AreEqual<string>(text, textAfterComDecompress);
}
}
Software architecture and development in .NET, SharePoint, SQL Server, Windows Server, Best Practices
Zobrazujú sa príspevky s označením MSTest. Zobraziť všetky príspevky
Zobrazujú sa príspevky s označením MSTest. Zobraziť všetky príspevky
štvrtok 12. januára 2012
pondelok 9. januára 2012
Unit Test Atributes in commom testing frameworks
I'm rewriting some my old test classes, writed in NUnit to the "new" MS Test.
I was looking for the alternative of TestFixtureTearDown
and Whoa la, I found this very usefull table:
I was looking for the alternative of TestFixtureTearDown
and Whoa la, I found this very usefull table:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prihlásiť na odber:
Príspevky (Atom)