Skip to content

Commit

Permalink
creating new bogus data
Browse files Browse the repository at this point in the history
  • Loading branch information
bradygaster committed Jul 7, 2020
1 parent ddef6d0 commit 76fe7a6
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet-test-explorer.testProjectPath": "**/*Tests.csproj"
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/COVIDScreeningApi/COVIDScreeningApi.csproj",
"${workspaceFolder}/COVIDScreeningApi.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand Down
13 changes: 12 additions & 1 deletion src/COVIDScreeningApi.sln → COVIDScreeningApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30014.187
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COVIDScreeningApi", "COVIDScreeningApi\COVIDScreeningApi.csproj", "{B2A6F07E-1C41-4F1B-8DB9-50CEC1D730BC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COVIDScreeningApi", "src\COVIDScreeningApi\COVIDScreeningApi.csproj", "{B2A6F07E-1C41-4F1B-8DB9-50CEC1D730BC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CAEFA69E-FAAE-4366-8B00-6F9BA7ACA7CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COVIDScreeningApi.Tests", "tests\COVIDScreeningApi.Tests\COVIDScreeningApi.Tests.csproj", "{C7B963D3-AF0C-44EE-B061-0089F49025B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,11 +19,18 @@ Global
{B2A6F07E-1C41-4F1B-8DB9-50CEC1D730BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2A6F07E-1C41-4F1B-8DB9-50CEC1D730BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2A6F07E-1C41-4F1B-8DB9-50CEC1D730BC}.Release|Any CPU.Build.0 = Release|Any CPU
{C7B963D3-AF0C-44EE-B061-0089F49025B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7B963D3-AF0C-44EE-B061-0089F49025B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7B963D3-AF0C-44EE-B061-0089F49025B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7B963D3-AF0C-44EE-B061-0089F49025B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9CE1A19-0B11-4E36-9772-C540EE3EE609}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C7B963D3-AF0C-44EE-B061-0089F49025B5} = {CAEFA69E-FAAE-4366-8B00-6F9BA7ACA7CC}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PortsOfEntry Get(Guid id)

// POST api/<PortsOfEntryController>
[HttpPost]
public ActionResult Post([FromBody] PortsOfEntry value)
public ActionResult<PortsOfEntry> Post([FromBody] PortsOfEntry value)
{
var dataObject = PortOfEntry.FromApiModel(value);
Guid newId = Guid.NewGuid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RepresentativeData Get (Guid id) {

// POST api/<RepresentativeDataController>
[HttpPost]
public ActionResult Post ([FromBody] RepresentativeData value) {
public ActionResult<RepresentativeData> Post ([FromBody] RepresentativeData value) {
var dataObject = Representative.FromApiModel(value);
Guid newId = Guid.NewGuid();
dataObject.Id = newId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ScreeningDataTable Get (Guid id) {

// POST api/<ScreeningDataTableController>
[HttpPost]
public ActionResult Post ([FromBody] ScreeningDataTable value) {
public ActionResult<ScreeningDataTable> Post ([FromBody] ScreeningDataTable value) {
var dataObject = Screening.FromApiModel(value);
Guid newId = Guid.NewGuid();
dataObject.Id = newId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace COVIDScreeningApi
{
internal static class DbContextOptionsBuilderExtensions
public static class DbContextOptionsBuilderExtensions
{
internal static DbContextOptionsBuilder UseCosmos(this DbContextOptionsBuilder builder,
public static DbContextOptionsBuilder UseCosmos(this DbContextOptionsBuilder builder,
string connectionString,
string databaseName)
{
Expand Down
22 changes: 22 additions & 0 deletions tests/COVIDScreeningApi.Tests/COVIDScreeningApi.Tests.csproj
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>
50 changes: 50 additions & 0 deletions tests/COVIDScreeningApi.Tests/RepresentativeTests.cs
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 ();
}
}
}
38 changes: 38 additions & 0 deletions tests/COVIDScreeningApi.Tests/Startup.cs
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);
}
}
15 changes: 15 additions & 0 deletions tests/COVIDScreeningApi.Tests/appsettings.json
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" : ""
}
}

0 comments on commit 76fe7a6

Please sign in to comment.