public void TestValidTransitional() { string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""> <html> <head><title>required</title></head> <body><iframe></iframe></body> </html> "; XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.XhtmlTransitional_10); using (TempFile temp = new TempFile()) { temp.WriteAllText(doc); v.Validate(@"C:\transitional.xhtml", new StreamReader(temp.Read())); } }
public void TestDownloadToFile() { byte[] src = new byte[ushort.MaxValue]; new Random().NextBytes(src); using (TempFile file = new TempFile()) { SecureTransfer.Server server = new SecureTransfer.Server(ServerKey, ClientKey.PublicKey, new RegistryStorage()); server.MaxOutboundFileChunk = 1000; server.DownloadBytes += (o, e) => { using (MemoryStream ms = new MemoryStream(e.ReadLength)) { ms.Write(src, (int)e.ReadOffset, e.ReadLength); e.SetBytes(src.Length, ms.ToArray()); } }; SecureTransfer.Client client = new SecureTransfer.Client(ClientKey, ServerKey.PublicKey, (id, name, stream) => server.Receive(stream)); client.Download("bla", file.TempPath); Assert.AreEqual(Hash.SHA256(src), Hash.SHA256(file.Read())); } }
public void TestCompressFile() { byte[] testData = new byte[ushort.MaxValue]; new Random().NextBytes(testData); Array.Clear(testData, 0, testData.Length / 2); Hash compressedHash; Hash hash = Hash.SHA512(testData); using (TempFile f = new TempFile()) { f.WriteAllBytes(testData); Assert.AreEqual((long)testData.Length, f.Length); IOStream.Compress(f.TempPath); Assert.IsTrue(f.Length < testData.Length); compressedHash = Hash.SHA512(f.Read()); Assert.IsFalse(compressedHash == hash); IOStream.Decompress(f.TempPath); Assert.AreEqual((long)testData.Length, f.Length); Assert.IsTrue(hash == Hash.SHA512(f.Read())); } MemoryStream ms = new MemoryStream(testData), gz = new MemoryStream(); IOStream.Compress(ms, gz); Assert.IsTrue(compressedHash == Hash.SHA512(gz.ToArray())); ms = new MemoryStream(); gz.Position = 0; IOStream.Decompress(gz, ms); Assert.IsTrue(hash == Hash.SHA512(ms.ToArray())); }
public void TestFileReadAccess() { TempFile file = new TempFile(); Stream r = file.Read(); Assert.IsFalse(r.CanWrite); Assert.IsTrue(r.CanRead); Stream o = file.Open(); Assert.IsTrue(o.CanWrite); Assert.IsTrue(o.CanRead); o.Dispose(); r.Dispose(); file.Dispose(); }
public void TestFileCreateAccess() { TempFile file = new TempFile(); Stream c = file.Create(); Assert.IsTrue(c.CanWrite); Assert.IsFalse(c.CanRead); Stream r = file.Read(); Assert.IsFalse(r.CanWrite); Assert.IsTrue(r.CanRead); c.Dispose(); r.Dispose(); file.Dispose(); }