Skip to content

Commit

Permalink
Full requested url will now be shown by default
Browse files Browse the repository at this point in the history
Reduced default interval to 1 second
Fixed a bug where an extra request would be sent when using --n argument
Removed interval when on last request
Improved incorrect argument check
Added option to only show hostnames
Fixed colour bleeding on error messages
Added proper help message
Added specific build platforms for x86 and x64
Improved tls and ssl setup
Added more tests
Bump version to 1.1
  • Loading branch information
Killeroo committed Oct 29, 2023
1 parent 027de71 commit 89c16e8
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 58 deletions.
26 changes: 26 additions & 0 deletions HttpPing.Tests/HttpPing.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
Expand Down
155 changes: 140 additions & 15 deletions HttpPing.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.IO;
using System.Text;
using web_ping;

namespace HttpPing.Tests
{
Expand All @@ -22,48 +23,172 @@ public void Init()
}

[TestMethod]
public void When_params_are_empty_should_return_usage_test()
public void When_params_are_empty_should_return_help_test()
{
var expectedValue = "USAGE: HttpPing web_address [-d] [-t] [-ts] [-https] [-n count] [-i interval] [-l] [-nc] [-r redirectCount] \r\n";
string expectedValue = Program.HelpMessage.Replace("\r\n", "");

string[] parameters = new string[]{};

web_ping.Program.Main(parameters, _environmentServiceForTestPurpose);
web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(actualOutput.ToString().Equals(expectedValue));
}

[TestMethod]
public void When_show_help_argument_show_help_message_test()
{
string expectedValue = Program.HelpMessage.Replace("\r\n", "");

Assert.IsTrue(_consoleOutput.ToString().Equals(expectedValue));
string[] parameters = new string[] { "-help" };

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(actualOutput.ToString().Equals(expectedValue));
}

[TestMethod]
public void When_full_uri_path_should_be_displayed_test()
{
string expectedOutput =
@"Sending HTTPS requests to [https://github.com/Killeroo]:
Response from https://github.com/Killeroo: Code=200:OK Size=-1
";

string[] parameters = new string[] { "https://github.com/Killeroo",
"-n", "1"};

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);

Assert.IsTrue(_consoleOutput.ToString().Equals(expectedOutput));
}

[TestMethod]
public void When_params_webaddress_simple_count_1_interval_500ms_should_response_test()
public void When_hosts_only_argument_uri_path_should_not_be_displayed_test()
{
var expectedValue = "Sending HTTP requests to [https://www.starwars.com]:\r\nResponse from www.starwars.com: Code=200:OK Size=-1\r\nResponse from www.starwars.com: Code=200:OK Size=-1\r\n";
string expectedOutput =
@"Sending HTTPS requests to [https://github.com/Killeroo]:
Response from github.com: Code=200:OK Size=-1
";

string[] parameters = new string[] { "https://www.starwars.com",
string[] parameters = new string[] { "https://github.com/Killeroo",
"-n", "1",
"-i", "500" };
"-h"};

web_ping.Program.Main(parameters, _environmentServiceForTestPurpose);
web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);

Assert.IsTrue(_consoleOutput.ToString().Equals(expectedValue));
Assert.IsTrue(_consoleOutput.ToString().Equals(expectedOutput));
}

[TestMethod]
public void When_bad_argument_throw_exception_test()
{
string expectedOutput =
@"Incorrect argument found
" + Program.UsageMessage + @"
";

string[] parameters = new string[] { "https://github.com/Killeroo",
"-n", "1",
"-notrealargument"};

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);

Assert.IsTrue(_consoleOutput.ToString().Equals(expectedOutput));
}

[TestMethod]
public void When_params_webaddress_contains_dash_should_not_return_error_test()
public void When_request_count_is_one_only_one_request_is_sent_test()
{
//var expectedValue = "Incorrect argument found\r\nUSAGE: HttpPing web_address [-d] [-t] [-ts] [-https] [-n count] [-i interval] [-l] [-nc] [-r redirectCount] \r\n";
var expectedValue = "Sending HTTP requests to [https://www.star-wars.com]:\r\nResponse from www.star-wars.com: Code=200:OK Size=-1\r\nResponse from www.star-wars.com: Code=200:OK Size=-1\r\n";
string expectedOutput =
@"Sending HTTPS requests to [https://github.com/Killeroo]:
Response from https://github.com/Killeroo: Code=200:OK Size=-1
".Replace("\r\n", "");

string[] parameters = new string[] { "https://github.com/Killeroo",
"-n", "1"};

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(actualOutput.Equals(expectedOutput));
}

[TestMethod]
public void When_request_count_is_two_then_two_requests_are_sent_test()
{
string expectedOutput =
@"Sending HTTPS requests to [https://github.com/]:
Response from https://github.com/: Code=200:OK Size=-1
Response from https://github.com/: Code=200:OK Size=-1
".Replace("\r\n", "");

string[] parameters = new string[] { "https://github.com/",
"-n", "2"};

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(actualOutput.Equals(expectedOutput));
}

[TestMethod]
public void When_no_params_url_is_google_http_should_respond_test()
{
string expectedOutput =
@"Sending HTTP requests to [http://www.google.com]:
Response from http://www.google.com/: Code=200:OK Size=-1
Response from http://www.google.com/: Code=200:OK Size=-1
Response from http://www.google.com/: Code=200:OK Size=-1
Response from http://www.google.com/: Code=200:OK Size=-1
Response from http://www.google.com/: Code=200:OK Size=-1
".Replace("\r\n", "");

string[] parameters = new string[] { "http://www.google.com" };

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(actualOutput.Equals(expectedOutput));
}

[TestMethod]
public void When_no_params_url_is_google_https_should_respond_test()
{
string expectedOutput =
@"Sending HTTPS requests to [https://www.google.com]:
Response from https://www.google.com/: Code=200:OK Size=-1
Response from https://www.google.com/: Code=200:OK Size=-1
Response from https://www.google.com/: Code=200:OK Size=-1
Response from https://www.google.com/: Code=200:OK Size=-1
Response from https://www.google.com/: Code=200:OK Size=-1
".Replace("\r\n", "");

string[] parameters = new string[] { "https://www.google.com" };

web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(actualOutput.Equals(expectedOutput));
}

[TestMethod]
public void When_params_webaddress_contains_dash_should_not_return_error_test()
{
string expectedOutput =
@"Sending HTTPS requests to [https://www.star-wars.com]:
Response from https://www.starwars.com/: Code=200:OK Size=-1
".Replace("\r\n", "");

string[] parameters = new string[] { "https://www.star-wars.com",
"-n", "1",
"-i", "500" };

web_ping.Program.Main(parameters, _environmentServiceForTestPurpose);
web_ping.Program.Run(parameters, _environmentServiceForTestPurpose);
string actualOutput = _consoleOutput.ToString().Replace("\r\n", "");

Assert.IsTrue(_consoleOutput.ToString().Equals(expectedValue));
Assert.IsTrue(actualOutput.Equals(expectedOutput));
}
}
}
20 changes: 20 additions & 0 deletions HttpPing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,37 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Debug|x64.ActiveCfg = Debug|x64
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Debug|x64.Build.0 = Debug|x64
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Debug|x86.ActiveCfg = Debug|x86
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Debug|x86.Build.0 = Debug|x86
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Release|Any CPU.Build.0 = Release|Any CPU
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Release|x64.ActiveCfg = Release|x64
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Release|x64.Build.0 = Release|x64
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Release|x86.ActiveCfg = Release|x86
{D4D36105-4AC4-4AD6-92DD-5EF9A05AF312}.Release|x86.Build.0 = Release|x86
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Debug|x64.ActiveCfg = Debug|x64
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Debug|x64.Build.0 = Debug|x64
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Debug|x86.ActiveCfg = Debug|x86
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Debug|x86.Build.0 = Debug|x86
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Release|Any CPU.Build.0 = Release|Any CPU
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Release|x64.ActiveCfg = Release|x64
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Release|x64.Build.0 = Release|x64
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Release|x86.ActiveCfg = Release|x86
{6006C2E4-372B-4375-904E-A4E0D67BC2F2}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
28 changes: 28 additions & 0 deletions HttpPing/HttpPing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
Loading

0 comments on commit 89c16e8

Please sign in to comment.