mirror of
https://github.com/AlexMacocian/MTSC.git
synced 2026-07-21 01:39:31 +00:00
Added HttpRequest unit tests
Modified HttpRequest parser to skip the first '/' from URI
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MTSC.Common.Http;
|
||||
using System.Text;
|
||||
|
||||
namespace MTSC.UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class HttpRequestTests
|
||||
{
|
||||
private const string postWithHeader = "POST /test/demo_form.php HTTP/1.1\n\rHost: w3schools.com\n\r\n\r";
|
||||
|
||||
private const string emptyGet = "GET / HTTP/1.1\n\r\n\r";
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(postWithHeader)]
|
||||
[DataRow(emptyGet)]
|
||||
public void ParseShouldPass(string requestString)
|
||||
{
|
||||
HttpRequest request = HttpRequest.FromBytes(ASCIIEncoding.ASCII.GetBytes(requestString));
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(postWithHeader, "test/demo_form.php")]
|
||||
[DataRow(emptyGet, "")]
|
||||
public void UriShouldBeAsExpected(string requestString, string uri)
|
||||
{
|
||||
HttpRequest request = HttpRequest.FromBytes(ASCIIEncoding.ASCII.GetBytes(requestString));
|
||||
Assert.AreEqual(request.RequestURI, uri);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HeaderShouldExist()
|
||||
{
|
||||
HttpRequest request = HttpRequest.FromBytes(ASCIIEncoding.ASCII.GetBytes(postWithHeader));
|
||||
Assert.AreEqual(request.Headers[HttpMessage.RequestHeaders.Host], "w3schools.com");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,7 @@ namespace MTSC.Common.Http
|
||||
* Get each character one by one. When meeting a SP character, parse the URI and clear the buffer.
|
||||
*/
|
||||
StringBuilder parseBuffer = new StringBuilder();
|
||||
ms.ReadByte(); //Ignore the first '/'
|
||||
while (ms.Position < ms.Length)
|
||||
{
|
||||
try
|
||||
|
||||
+3
-3
@@ -5,12 +5,12 @@
|
||||
<TargetFrameworks>netcoreapp2.1;net48;netstandard2.0;netcoreapp3.0</TargetFrameworks>
|
||||
<ApplicationIcon />
|
||||
<StartupObject />
|
||||
<Version>1.5.6</Version>
|
||||
<Version>1.5.7</Version>
|
||||
<Authors>Alexandru-Victor Macocian</Authors>
|
||||
<Product>MTSC</Product>
|
||||
<Description>Modular TCP Server and Client</Description>
|
||||
<AssemblyVersion>0.1.5.6</AssemblyVersion>
|
||||
<FileVersion>0.1.5.6</FileVersion>
|
||||
<AssemblyVersion>0.1.5.7</AssemblyVersion>
|
||||
<FileVersion>0.1.5.7</FileVersion>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<PackageProjectUrl>https://github.com/AlexMacocian/MTSC</PackageProjectUrl>
|
||||
|
||||
@@ -4,9 +4,6 @@ using MTSC.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using static MTSC.Common.Http.HttpMessage;
|
||||
|
||||
namespace MTSC.Server.Handlers
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user