-
Notifications
You must be signed in to change notification settings - Fork 5
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
ddef6d0
commit 76fe7a6
Showing
11 changed files
with
146 additions
and
7 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,3 @@ | ||
{ | ||
"dotnet-test-explorer.testProjectPath": "**/*Tests.csproj" | ||
} |
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 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
22 changes: 22 additions & 0 deletions
22
tests/COVIDScreeningApi.Tests/COVIDScreeningApi.Tests.csproj
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" Version="29.0.2" /> | ||
<PackageReference Include="FluentAssertions" Version="5.10.3" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | ||
<PackageReference Include="Xunit.DependencyInjection" Version="6.1.0" /> | ||
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.8.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="5.0.0-preview.2.20159.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\COVIDScreeningApi\COVIDScreeningApi.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,50 @@ | ||
using System; | ||
using System.Text.Json; | ||
using Bogus; | ||
using COVIDScreeningApi.Controllers; | ||
using COVIDScreeningApi.Data; | ||
using COVIDScreeningApi.Models; | ||
using FluentAssertions; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Xunit; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace COVIDScreeningApi.Tests { | ||
public class RepresentativeTests { | ||
private readonly DataContext _dataContext; | ||
private readonly IConfiguration _configuration; | ||
public RepresentativeTests (DataContext dataContext, IConfiguration configuration) { | ||
_configuration = configuration; | ||
_dataContext = dataContext; | ||
} | ||
|
||
[Fact] | ||
public void RepresentativeCanBeCreated () { | ||
Console.WriteLine (JsonSerializer.Serialize<RepresentativeData> (CreateRandomRepresentative (), | ||
new JsonSerializerOptions { | ||
WriteIndented = true | ||
})); | ||
} | ||
|
||
[Fact] | ||
public void RepresentativeCanBeSavedToDatabase () { | ||
var controller = new RepresentativeDataController(_dataContext, _configuration); | ||
var rep = CreateRandomRepresentative(); | ||
var result = controller.Post(rep); | ||
result.Value.Should().NotBeNull(); | ||
} | ||
|
||
RepresentativeData CreateRandomRepresentative () { | ||
return new Faker<RepresentativeData> () | ||
.RuleFor (x => x.Id, f => Guid.NewGuid ()) | ||
.RuleFor (x => x.RepContact, f => f.Phone.PhoneNumber ()) | ||
.RuleFor (x => x.RepLocation, f => f.Address.City ()) | ||
.RuleFor (x => x.RepName, f => f.Name.FullName ()) | ||
.FinishWith ((f, u) => { | ||
u.RepEmail = f.Internet.Email (u.RepName); | ||
}) | ||
.Generate (); | ||
} | ||
} | ||
} |
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,38 @@ | ||
using System.Configuration; | ||
using System.Reflection; | ||
using COVIDScreeningApi.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.DependencyInjection; | ||
using Microsoft.Extensions.Configuration; | ||
using COVIDScreeningApi; | ||
|
||
[assembly: TestFramework("COVIDScreeningApi.Tests.Startup", "COVIDScreeningApi.Tests")] | ||
|
||
namespace COVIDScreeningApi.Tests | ||
{ | ||
public class Startup : DependencyInjectionTestFramework | ||
{ | ||
public IConfiguration Configuration { get; } | ||
|
||
public Startup(IMessageSink messageSink) : base(messageSink) { } | ||
|
||
protected void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddSingleton<IConfiguration, Configuration>(); | ||
services.AddDbContext<DataContext>(optionsBuilder => | ||
{ | ||
optionsBuilder.UseCosmos( | ||
Configuration.GetConnectionString("CosmosDbConnectionString"), | ||
"COVIDScreeningDb"); | ||
}); | ||
} | ||
|
||
protected override IHostBuilder CreateHostBuilder(AssemblyName assemblyName) => | ||
base.CreateHostBuilder(assemblyName) | ||
.ConfigureServices(ConfigureServices); | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"SwaggerBaseUrl": "https://localhost:5001", | ||
"ConnectionStrings": { | ||
"CosmosDbConnectionString" : "" | ||
} | ||
} | ||
|