-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
7dfe2ba
commit 0de45f1
Showing
3 changed files
with
67 additions
and
0 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,26 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
|
||
name: test | ||
|
||
on: | ||
[push, pull_request] | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Test | ||
run: dotnet test --no-restore | ||
|
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,34 @@ | ||
using System.Data; | ||
using NSubstitute; | ||
using Xunit; | ||
using AnalyticsWebApi.Datamodel; | ||
using Dapper; | ||
|
||
namespace AnalyticsWebApi; | ||
|
||
public class AnalyticsRepositoryTests | ||
{ | ||
[Fact] | ||
public async Task SaveAnalyticsData_ValidData_ReturnsSuccess() | ||
{ | ||
// Arrange | ||
var mockConnection = Substitute.For<IDbConnection>(); | ||
var repository = new AnalyticsRepository(""); // Pass an empty string here | ||
var data = new AnalyticsData { | ||
Referer = "https://www.example.com", | ||
IpAddress = "127.0.0.1", | ||
DataKey = "test-key", | ||
Data = "test-data" | ||
}; | ||
|
||
mockConnection.ExecuteAsync(Arg.Any<string>(), Arg.Any<object>()).Returns(1); | ||
|
||
// Act | ||
int result = await repository.SaveAnalyticsData(data); | ||
|
||
// Assert | ||
Assert.Equal(1, result); | ||
// ... rest of your assertions | ||
} | ||
|
||
} |
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