Initial project commit
This commit is contained in:
111
TorLibraryTest/ControlConnectionUnitTests.cs
Normal file
111
TorLibraryTest/ControlConnectionUnitTests.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TorControlLibrary;
|
||||
using TorControlLibrary.Responses;
|
||||
using System.Threading;
|
||||
using Hermes.Objects;
|
||||
|
||||
namespace TorLibraryTest
|
||||
{
|
||||
[TestClass]
|
||||
public class ControlConnectionUnitTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Connect()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
connection.Close();
|
||||
}
|
||||
[TestMethod]
|
||||
public void GetCircuitStatuses()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
List<CircuitStatusResponse> circuits = connection.GetCircuitStatuses();
|
||||
connection.Close();
|
||||
}
|
||||
[TestMethod]
|
||||
public void GetStreamStatuses()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
List<StreamStatusResponse> circuits = connection.GetStreamStatuses();
|
||||
connection.Close();
|
||||
}
|
||||
[TestMethod]
|
||||
public void GetRouterStatuses()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
List<RouterStatusResponse> routerInfo = connection.GetAllRouterStatusInfo();
|
||||
connection.Close();
|
||||
}
|
||||
[TestMethod]
|
||||
public void GetRouterStatusByName()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
RouterStatusResponse routerInfo = connection.GetRouterStatusInfoByNickname("moria1");
|
||||
connection.Close();
|
||||
Assert.AreEqual("moria1", routerInfo.NickName);
|
||||
}
|
||||
[TestMethod]
|
||||
public void GetRouterDescriptionByName()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
RouterDescription routerInfo = connection.GetRouterDescriptionByNickname("desync");
|
||||
connection.Close();
|
||||
Assert.AreEqual("desync", routerInfo.NickName);
|
||||
}
|
||||
[TestMethod]
|
||||
public void GetRouterStatusByID()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
RouterStatusResponse routerInfo = connection.GetRouterStatusInfoByID("03C0FB35B3A0D3D12410475C5FDB8F525B7342CD");
|
||||
connection.Close();
|
||||
Assert.AreEqual("zagon", routerInfo.NickName);
|
||||
}
|
||||
[TestMethod]
|
||||
public void SendRawCommand()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
CommandResponse resp = connection.SendRawCommand("getinfo version");
|
||||
Assert.AreEqual(250, resp.StatusCode);
|
||||
Assert.IsTrue(resp.Response.Contains("version"));
|
||||
}
|
||||
[TestMethod]
|
||||
public void SimpleEventTest()
|
||||
{
|
||||
ControlConnection connection = new ControlConnection();
|
||||
connection.Connect();
|
||||
connection.ServerEvent += new Action<EventResponse>(connection_ServerEvent);
|
||||
connection.SendRawCommand("SETEVENTS BW");
|
||||
Assert.IsTrue(eventTest.WaitOne(60000));
|
||||
connection.Close();
|
||||
}
|
||||
[TestMethod]
|
||||
public void SocksTest()
|
||||
{
|
||||
Socks5Stream stream = new Socks5Stream("localhost", 9050, "www.google.com", 80);
|
||||
System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
|
||||
System.IO.StreamReader reader = new System.IO.StreamReader(stream);
|
||||
writer.Write("GET / HTTP 1.1\r\nHost: www.google.com\r\n\r\n");
|
||||
writer.Flush();
|
||||
String results = reader.ReadLine();
|
||||
}
|
||||
|
||||
void connection_ServerEvent(EventResponse obj)
|
||||
{
|
||||
if (obj.EventType.Equals("BW"))
|
||||
eventTest.Set();
|
||||
}
|
||||
private AutoResetEvent eventTest = new AutoResetEvent(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user