Skip to content

Commit 83cb33b

Browse files
committed
Adding the HTTP API endpoint, tidying up unit test
1 parent e4f8022 commit 83cb33b

8 files changed

+122
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace StringProcessor.API.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class StringController : ControllerBase
8+
{
9+
/// <summary>
10+
/// Retrieves the populated StringStatsModel of the specified string
11+
/// </summary>
12+
/// <param name="inputString">The string to retrieve the StringStatsModel of</param>
13+
/// <returns>The populated StringStatsModel</returns>
14+
[HttpGet("{inputString}")]
15+
public ActionResult<StringStatsModel> GetStringStatsModelByString(string inputString)
16+
{
17+
var stringStatsProcessor = new StringStatsProcessor();
18+
var stringStatsModel = stringStatsProcessor.Run(inputString);
19+
20+
return Ok(stringStatsModel);
21+
}
22+
}
23+
}

StringProcessor.API/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllers();
24+
25+
app.Run();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:19797",
8+
"sslPort": 44382
9+
}
10+
},
11+
"profiles": {
12+
"StringProcessor.API": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "https://localhost:7226;http://localhost:5114",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
24+
"launchBrowser": true,
25+
"launchUrl": "swagger",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\src\StringProcessor.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

StringProcessor.API/appsettings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

StringProcessor.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StringProcessor", "src\Stri
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StringProcessor.Tests", "tests\StringProcessor.Tests.csproj", "{8638A404-5C18-45BE-A6C3-6EE3A5F87847}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StringProcessor.API", "StringProcessor.API\StringProcessor.API.csproj", "{56295773-445B-497A-87A0-63B54ADFA113}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{8638A404-5C18-45BE-A6C3-6EE3A5F87847}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{8638A404-5C18-45BE-A6C3-6EE3A5F87847}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{8638A404-5C18-45BE-A6C3-6EE3A5F87847}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{56295773-445B-497A-87A0-63B54ADFA113}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{56295773-445B-497A-87A0-63B54ADFA113}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{56295773-445B-497A-87A0-63B54ADFA113}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{56295773-445B-497A-87A0-63B54ADFA113}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

tests/StringStatsProcessorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public void Run_SimpleString_ReturnsStats()
5353
Assert.Equal(6, results.NumberOfWords);
5454
}
5555

56-
// TODO: For bonus points, write a unit test which tests very large input to the StringStatsProcessor.Run(string) method.
56+
// For bonus points, write a unit test which tests very large input to the StringStatsProcessor.Run(string) method.
5757
[Theory]
58-
[InlineData(5000)]
58+
[InlineData(5055)]
5959
[InlineData(10000)]
60-
[InlineData(1000)]
60+
[InlineData(999)]
6161
public void Run_LargeInputNoSpace_ReturnsStats(int stringLength)
6262
{
6363
string testData = new('a', stringLength);

0 commit comments

Comments
 (0)