Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions completesolution/dotnet/MinimalAPI.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,208 @@ public async Task Get_ReturnsHelloWorld()
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("Hello World!", content);
}

[Fact]
public async Task DaysBetweenDates_ReturnsCorrectDays()
{
// Arrange
var date1 = "2024-01-01";
var date2 = "2024-01-10";

// Act
var response = await _client.GetAsync($"/daysbetweendates?startdate={date1}&enddate={date2}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("9", content);
}

[Fact]
public async Task ValidatePhoneNumber_ValidNumber_ReturnsTrue()
{
// Arrange
var phoneNumber = "+34666777888";

// Act
var response = await _client.GetAsync($"/validatephonenumber?phonenumber={Uri.EscapeDataString(phoneNumber)}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("True", content);
}

[Fact]
public async Task ValidatePhoneNumber_InvalidNumber_ReturnsFalse()
{
// Arrange
var phoneNumber = "123456";

// Act
var response = await _client.GetAsync($"/validatephonenumber?phonenumber={phoneNumber}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("False", content);
}

[Fact]
public async Task ValidateSpanishDni_ValidDni_ReturnsTrue()
{
// Arrange
var dni = "12345678Z";

// Act
var response = await _client.GetAsync($"/validatespanishdni?dni={dni}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("true", content.ToLower());
}

[Fact]
public async Task ValidateSpanishDni_InvalidDni_ReturnsFalse()
{
// Arrange
var dni = "12345678A";

// Act
var response = await _client.GetAsync($"/validatespanishdni?dni={dni}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("false", content.ToLower());
}

[Fact]
public async Task Color_ValidColor_ReturnsHexCode()
{
// Arrange
var color = "red";

// Act
var response = await _client.GetAsync($"/color?color={color}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("#FF0000", content);
}

[Fact]
public async Task TellMeAJoke_ReturnsJoke()
{
// Arrange

// Act
var response = await _client.GetAsync("/tellmeajoke");

// Assert - External API may not be accessible in all environments
// Just verify the endpoint exists and responds (even with error)
Assert.NotNull(response);
}

[Fact]
public async Task MoviesByDirector_ReturnsMovies()
{
// Arrange
var director = "Spielberg";

// Act
var response = await _client.GetAsync($"/moviesbydirector?director={director}");

// Assert - External API may not be accessible in all environments
// Just verify the endpoint exists and responds (even with error)
Assert.NotNull(response);
}

[Fact]
public async Task ParseUrl_ReturnsUrlParts()
{
// Arrange
var url = "https://example.com:8080/path";

// Act
var response = await _client.GetAsync($"/parseurl?url={Uri.EscapeDataString(url)}");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Contains("https", content);
Assert.Contains("example.com", content);
}

[Fact]
public async Task ListFiles_ReturnsFileList()
{
// Arrange

// Act
var response = await _client.GetAsync("/listfiles");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.NotEmpty(content);
}

[Fact]
public async Task CalculateMemoryUsage_ReturnsMemoryInGB()
{
// Arrange

// Act
var response = await _client.GetAsync("/calculatememoryusage");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Contains("GB", content);
}

[Fact]
public async Task RandomEuropeanCountry_ReturnsCountry()
{
// Arrange

// Act
var response = await _client.GetAsync("/randomeuropeancountry");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.NotEmpty(content);
}

[Fact]
public async Task GetFullTextFile_ReturnsLinesWithFusce()
{
// Arrange

// Act
var response = await _client.GetAsync("/getfulltextfile");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Contains("Fusce", content);
}

[Fact]
public async Task GetLineByLinefromtTextFile_ReturnsLinesWithFusce()
{
// Arrange

// Act
var response = await _client.GetAsync("/getlinebylinefromttextfile");

// Assert
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.Contains("Fusce", content);
}
}
15 changes: 9 additions & 6 deletions completesolution/dotnet/MinimalAPI/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# create dotnet 7 image for the current project
# Create dotnet 8 image for the current project

# Use the official .NET 7 SDK image as the base image
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS build
# Use the official .NET 8 SDK image as the base image
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

# Set the working directory to /app
WORKDIR /app
Expand All @@ -15,14 +15,17 @@ RUN dotnet restore
# Publish the project to a folder called "out"
RUN dotnet publish -c Release -o out

# Use the official .NET 7 runtime image as the base image
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS runtime
# Use the official .NET 8 ASP.NET runtime image as the base image
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime

# Set the working directory to /app
WORKDIR /app

# Copy the published output from the build image to the runtime image
COPY --from=build /app/out ./

# Expose port 80
EXPOSE 80

# Set the entry point to the application
ENTRYPOINT ["dotnet", "/app/MinimalAPI.dll"]
ENTRYPOINT ["dotnet", "MinimalAPI.dll"]
9 changes: 9 additions & 0 deletions completesolution/dotnet/MinimalAPI/MinimalAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<None Update="colors.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="sample.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading