static void Main(string[] args) { var Node = new BlockChainNode(); Node.Initiate(); var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node); HttpHost.Start(); Console.WriteLine("Server running, press any key to quit"); Console.ReadLine(); }
public void CreateHostAndCheckResponsive() { var Node = new BlockChainNode(); Node.Initiate(); var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node); HttpHost.Start(); using (var client = new HttpClient()) { var response = client.PostAsync("http://localhost:8080/count/", null).Result; Assert.Equal(true, response.IsSuccessStatusCode); } }
public void GetBlockCountWhenChainNew() { var Node = new BlockChainNode(); Node.Initiate(); var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node); HttpHost.Start(); using (var client = new HttpClient()) { var response = client.PostAsync("http://localhost:8080/count/", null).Result; var contents = response.Content.ReadAsStringAsync().Result; Assert.Equal("1", contents); } }
public void SubmitInvalidData() { var Node = new BlockChainNode(); Node.Initiate(); var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node); HttpHost.Start(); using (var client = new HttpClient()) { var myContent = ""; var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); var response = client.PostAsync("http://localhost:8080/add/", byteContent).Result; var contents = response.Content.ReadAsStringAsync().Result; Assert.Equal("No data found, cannot add block with no data, that's pointless!", contents); } }
public void SubmitValidData() { var Node = new BlockChainNode(); Node.Initiate(); var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node); HttpHost.Start(); using (var client = new HttpClient()) { var myContent = "TestBlockData"; var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); var response = client.PostAsync("http://localhost:8080/add/", byteContent).Result; var contents = response.Content.ReadAsStringAsync().Result; Assert.Equal("ADDED|2", contents); } }
public void SubmitNewBlocksAndGetCount() { var Node = new BlockChainNode(); Node.Initiate(); var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node); HttpHost.Start(); using (var client = new HttpClient()) { var myContent = "TestBlockData"; var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); for (int i = 0; i < 10; i++) { client.PostAsync("http://localhost:8080/add/", byteContent).Wait(); } var response = client.PostAsync("http://localhost:8080/count/", null).Result; var contents = response.Content.ReadAsStringAsync().Result; Assert.Equal("11", contents); } }