Skip to content

Commit 144f411

Browse files
Nuget issues
2 parents c2566bf + 4f8f11a commit 144f411

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

TestHosts/TestHosts/Controllers/TestBankController.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
using System;
44
using System.Linq;
55
using System.Net.Http;
6+
using System.Text;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using Database.TestBank;
910
using DataTransferObjects.TestBank;
1011
using Microsoft.AspNetCore.Mvc;
1112
using Newtonsoft.Json;
1213
using Shared.General;
14+
using Shared.Logger;
1315
using Deposit = Database.TestBank.Deposit;
1416

1517
[Route("api/testbank")]
@@ -72,15 +74,19 @@ public async Task<IActionResult> CreateHostConfiguration([FromBody] CreateHostCo
7274
public async Task<IActionResult> MakeDeposit([FromBody] MakeDepositRequest makeDepositRequest,
7375
CancellationToken cancellationToken)
7476
{
75-
// TODO: Store the deposits
77+
Logger.LogInformation(JsonConvert.SerializeObject(makeDepositRequest));
78+
7679
String connectionString = ConfigurationReader.GetConnectionString("TestBankReadModel");
7780
TestBankContext context = this.ContextFactory(connectionString);
7881
HostConfiguration host = context.HostConfigurations.SingleOrDefault(h => h.AccountNumber == makeDepositRequest.ToAccountNumber &&
7982
h.SortCode == makeDepositRequest.ToSortCode);
8083
Guid depositId = Guid.Empty;
81-
if (host != null)
84+
if (host == null)
8285
{
83-
depositId = Guid.NewGuid();
86+
return this.NotFound($"No host found");
87+
}
88+
89+
depositId = Guid.NewGuid();
8490
Deposit deposit = new Deposit
8591
{
8692
Amount = makeDepositRequest.Amount,
@@ -112,16 +118,15 @@ public async Task<IActionResult> MakeDeposit([FromBody] MakeDepositRequest makeD
112118

113119
HttpClient client = new HttpClient();
114120
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, host.CallbackUri);
115-
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(depositDto));
121+
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(depositDto), Encoding.UTF8, "application/json");
116122
HttpResponseMessage response = await client.SendAsync(requestMessage, cancellationToken);
117123
if (response.IsSuccessStatusCode)
118124
{
119125
deposit.SentToHost = true;
120126
await context.SaveChangesAsync(cancellationToken);
121127
}
122128
}
123-
}
124-
129+
125130
return this.Ok(new
126131
{
127132
host.HostIdentifier,

TestHosts/TestHosts/Startup.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace TestHosts
1313
using Microsoft.EntityFrameworkCore;
1414
using Microsoft.Extensions.Logging;
1515
using Microsoft.OpenApi.Models;
16+
using Newtonsoft.Json;
17+
using Newtonsoft.Json.Serialization;
1618
using Shared.EntityFramework;
1719
using Shared.Extensions;
1820
using Shared.General;
@@ -40,7 +42,14 @@ public void ConfigureServices(IServiceCollection services)
4042
{
4143
ConfigurationReader.Initialise(Startup.Configuration);
4244

43-
services.AddControllers();
45+
services.AddControllers().AddNewtonsoftJson(options =>
46+
{
47+
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
48+
options.SerializerSettings.TypeNameHandling = TypeNameHandling.None;
49+
options.SerializerSettings.Formatting = Formatting.Indented;
50+
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
51+
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
52+
});
4453

4554
// Register the Swagger generator, defining 1 or more Swagger documents
4655
services.AddSwaggerGen(c =>
@@ -51,14 +60,17 @@ public void ConfigureServices(IServiceCollection services)
5160
if (Startup.WebHostEnvironment.IsEnvironment("IntegrationTest") || Startup.Configuration.GetValue<Boolean>("ServiceOptions:UseInMemoryDatabase") == true)
5261
{
5362
services.AddDbContext<TestBankContext>(builder => builder.UseInMemoryDatabase("TestBankReadModel"));
63+
DbContextOptionsBuilder<TestBankContext> builder = new DbContextOptionsBuilder<TestBankContext>();
64+
builder = builder.UseInMemoryDatabase("TestBankReadModel");
65+
66+
services.AddSingleton<Func<String, TestBankContext>>(cont => (connectionString) => { return new TestBankContext(builder.Options);});
5467
}
5568
else
5669
{
5770
var connString = ConfigurationReader.GetConnectionString("TestBankReadModel");
5871
services.AddDbContext<TestBankContext>(builder => builder.UseSqlServer(connString));
72+
services.AddSingleton<Func<String, TestBankContext>>(cont => (connectionString) => { return new TestBankContext(connectionString); });
5973
}
60-
61-
services.AddSingleton<Func<String, TestBankContext>>(cont => (connectionString) => { return new TestBankContext(connectionString); });
6274
}
6375

6476
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

0 commit comments

Comments
 (0)