-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose | ||
{ | ||
"name": ".NET API Tests", | ||
|
||
// Update the 'dockerComposeFile' list if you have more compose files or use different names. | ||
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. | ||
"dockerComposeFile": [ | ||
"../../docker-compose.yml" | ||
], | ||
|
||
// The 'service' property is the name of the service for the container that VS Code should | ||
// use. Update this value and .devcontainer/docker-compose.yml to the real service name. | ||
"service": "tests", | ||
|
||
// The optional 'workspaceFolder' property is the path VS Code should open by default when | ||
// connected. This is typically a file mount in .devcontainer/docker-compose.yml | ||
"workspaceFolder": "/workspace/tests", | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
|
||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Uncomment the next line if you want start specific services in your Docker Compose config. | ||
// "runServices": [], | ||
|
||
// Uncomment the next line if you want to keep your containers running after VS Code shuts down. | ||
"shutdownAction": "none", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-dotnettools.csharp", | ||
"rangav.vscode-thunder-client", | ||
"GitHub.copilot", | ||
"ms-dotnettools.csdevkit" | ||
] | ||
} | ||
} | ||
|
||
// Uncomment the next line to run commands after the container is created. | ||
//"postCreateCommand": "chmod +x ./setup.sh; ./setup.sh" | ||
|
||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "devcontainer" | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,73 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Api.Function; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Moq; | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace tests | ||
public class GetVisitorCounterTests | ||
{ | ||
public class TestCounter | ||
private readonly ILogger<GetVisitorCounter> logger; | ||
private readonly Mock<HttpRequestData> mockRequest; | ||
private readonly Mock<FunctionContext> mockFunctionContext; | ||
|
||
public GetVisitorCounterTests() | ||
{ | ||
logger = Mock.Of<ILogger<GetVisitorCounter>>(); | ||
mockFunctionContext = new Mock<FunctionContext>(); | ||
mockRequest = new Mock<HttpRequestData>(MockBehavior.Strict, mockFunctionContext.Object); | ||
|
||
mockRequest.Setup(req => req.CreateResponse()).Returns(() => CreateMockHttpResponseData(mockFunctionContext.Object)); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task Run_ShouldIncrementCounter() | ||
{ | ||
private readonly ILogger logger = TestFactory.CreateLogger(); | ||
|
||
[Fact] | ||
public async void Http_trigger_should_return_known_string() | ||
{ | ||
var counter = new Company.Function.Counter(); | ||
counter.Id = "1"; | ||
counter.Count = 2; | ||
var request = TestFactory.CreateHttpRequest(); | ||
var response = (HttpResponseMessage) Company.Function.GetResumeCounter.Run(request, counter, out counter, logger); | ||
Assert.Equal(3, counter.Count); | ||
} | ||
// Arrange | ||
var counter = new Counter(id : "index"){ Count = 1 }; | ||
var function = new GetVisitorCounter(logger); | ||
var loggerFactoryMock = new Mock<ILoggerFactory>(); | ||
var loggerMock = new Mock<ILogger>(); | ||
loggerFactoryMock.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(loggerMock.Object); | ||
var requestMock = new Mock<HttpRequestData>(); | ||
var responseMock = new Mock<HttpResponseData>(); | ||
|
||
// Simulate the function call | ||
var response = function.Run(requestMock.Object, counter); | ||
|
||
// Assert | ||
Assert.NotNull(response); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
|
||
// Verify that the response contains the expected content type | ||
Assert.True(response.Headers.TryGetValues("Content-Type", out var contentTypes)); | ||
Assert.Contains("text/plain; charset=utf-8", contentTypes); | ||
|
||
// Act | ||
var result = await function.Run(mockRequest.Object, counter); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.Equal(2, result.NewCounter.Count); // Check if the counter is incremented | ||
// Additional assertions as necessary | ||
} | ||
} | ||
} | ||
|
||
// Arrange | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.002.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tests", "tests.csproj", "{C077F20F-7BF0-4112-84C9-AFE8DD6F2D66}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "testing1", "testing1\testing1.csproj", "{BAB3BC90-56E1-4FA6-BF08-01919496262C}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C077F20F-7BF0-4112-84C9-AFE8DD6F2D66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C077F20F-7BF0-4112-84C9-AFE8DD6F2D66}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C077F20F-7BF0-4112-84C9-AFE8DD6F2D66}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C077F20F-7BF0-4112-84C9-AFE8DD6F2D66}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{BAB3BC90-56E1-4FA6-BF08-01919496262C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BAB3BC90-56E1-4FA6-BF08-01919496262C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BAB3BC90-56E1-4FA6-BF08-01919496262C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BAB3BC90-56E1-4FA6-BF08-01919496262C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {09FE1130-5B6A-4B10-B953-AB072EAE676D} | ||
EndGlobalSection | ||
EndGlobal |