Skip to content
Merged
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
17 changes: 11 additions & 6 deletions TestHosts/TestHosts/Controllers/TestBankController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Database.TestBank;
using DataTransferObjects.TestBank;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Shared.General;
using Shared.Logger;
using Deposit = Database.TestBank.Deposit;

[Route("api/testbank")]
Expand Down Expand Up @@ -72,15 +74,19 @@ public async Task<IActionResult> CreateHostConfiguration([FromBody] CreateHostCo
public async Task<IActionResult> MakeDeposit([FromBody] MakeDepositRequest makeDepositRequest,
CancellationToken cancellationToken)
{
// TODO: Store the deposits
Logger.LogInformation(JsonConvert.SerializeObject(makeDepositRequest));

String connectionString = ConfigurationReader.GetConnectionString("TestBankReadModel");
TestBankContext context = this.ContextFactory(connectionString);
HostConfiguration host = context.HostConfigurations.SingleOrDefault(h => h.AccountNumber == makeDepositRequest.ToAccountNumber &&
h.SortCode == makeDepositRequest.ToSortCode);
Guid depositId = Guid.Empty;
if (host != null)
if (host == null)
{
depositId = Guid.NewGuid();
return this.NotFound($"No host found");
}

depositId = Guid.NewGuid();
Deposit deposit = new Deposit
{
Amount = makeDepositRequest.Amount,
Expand Down Expand Up @@ -112,16 +118,15 @@ public async Task<IActionResult> MakeDeposit([FromBody] MakeDepositRequest makeD

HttpClient client = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, host.CallbackUri);
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(depositDto));
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(depositDto), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.SendAsync(requestMessage, cancellationToken);
if (response.IsSuccessStatusCode)
{
deposit.SentToHost = true;
await context.SaveChangesAsync(cancellationToken);
}
}
}


return this.Ok(new
{
host.HostIdentifier,
Expand Down
18 changes: 15 additions & 3 deletions TestHosts/TestHosts/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace TestHosts
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Shared.EntityFramework;
using Shared.Extensions;
using Shared.General;
Expand Down Expand Up @@ -40,7 +42,14 @@ public void ConfigureServices(IServiceCollection services)
{
ConfigurationReader.Initialise(Startup.Configuration);

services.AddControllers();
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
options.SerializerSettings.TypeNameHandling = TypeNameHandling.None;
options.SerializerSettings.Formatting = Formatting.Indented;
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});

// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
Expand All @@ -51,14 +60,17 @@ public void ConfigureServices(IServiceCollection services)
if (Startup.WebHostEnvironment.IsEnvironment("IntegrationTest") || Startup.Configuration.GetValue<Boolean>("ServiceOptions:UseInMemoryDatabase") == true)
{
services.AddDbContext<TestBankContext>(builder => builder.UseInMemoryDatabase("TestBankReadModel"));
DbContextOptionsBuilder<TestBankContext> builder = new DbContextOptionsBuilder<TestBankContext>();
builder = builder.UseInMemoryDatabase("TestBankReadModel");

services.AddSingleton<Func<String, TestBankContext>>(cont => (connectionString) => { return new TestBankContext(builder.Options);});
}
else
{
var connString = ConfigurationReader.GetConnectionString("TestBankReadModel");
services.AddDbContext<TestBankContext>(builder => builder.UseSqlServer(connString));
services.AddSingleton<Func<String, TestBankContext>>(cont => (connectionString) => { return new TestBankContext(connectionString); });
}

services.AddSingleton<Func<String, TestBankContext>>(cont => (connectionString) => { return new TestBankContext(connectionString); });
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
5 changes: 3 additions & 2 deletions TestHosts/TestHosts/TestHosts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="Shared" Version="0.0.11.3" />
<PackageReference Include="Shared" Version="1.0.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.1.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down