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
10 changes: 5 additions & 5 deletions TestHosts/TestHosts/Controllers/DeveloperController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TestHosts.Controllers
public class DeveloperController : ControllerBase
{
private readonly IDbContextResolver<PataPawaContext> ContextResolver;

private const String PataPawaReadModelKey = "PataPawaReadModel";
public DeveloperController(IDbContextResolver<PataPawaContext> contextResolver) {
this.ContextResolver = contextResolver;
}
Expand All @@ -27,7 +27,7 @@ public DeveloperController(IDbContextResolver<PataPawaContext> contextResolver)
[Route("patapawaprepay/createuser")]
public async Task<IActionResult> CreatePrepayUser([FromBody] CreatePatapawaPrePayUser request, CancellationToken cancellationToken){

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

Guid userId = Guid.NewGuid();

Expand Down Expand Up @@ -57,7 +57,7 @@ await resolvedContext.Context.PrePayUsers.AddAsync(new PrePayUser
[Route("patapawaprepay/adduserdebt")]
public async Task<IActionResult> AddUserDebt([FromBody] AddPatapawaPrePayUserDebt request, CancellationToken cancellationToken)
{
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

PrePayUser user = await resolvedContext.Context.PrePayUsers.SingleOrDefaultAsync(u => u.UserName == request.UserName, cancellationToken);

Expand All @@ -75,7 +75,7 @@ public async Task<IActionResult> AddUserDebt([FromBody] AddPatapawaPrePayUserDeb
[HttpPost]
[Route("patapawaprepay/createmeter")]
public async Task<IActionResult> CreatePrepayMeter([FromBody] CreatePatapawaPrePayMeter request, CancellationToken cancellationToken){
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

Guid meterId = Guid.NewGuid();

Expand All @@ -101,7 +101,7 @@ await resolvedContext.Context.PrePayMeters.AddAsync(new PrePayMeter
public async Task<IActionResult> CreateHostConfiguration([FromBody] CreatePataPawaPostPayBill request,
CancellationToken cancellationToken)
{
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

Guid billIdentifier = Guid.NewGuid();

Expand Down
14 changes: 7 additions & 7 deletions TestHosts/TestHosts/Controllers/PataPawaPrePaidController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
[ApiController]
public class PataPawaPrePaidController : ControllerBase{
private readonly IDbContextResolver<PataPawaContext> ContextResolver;

private const String PataPawaReadModelKey = "PataPawaReadModel";
#region Fields

//private List<(String username, String password, String key, String balance)> users = new();

#endregion
Expand Down Expand Up @@ -175,7 +175,7 @@ private async Task<IActionResult> HandleBalanceRequest(IFormCollection requestFo
String key = requestForm["key"].ToString();
String meter = requestForm["meter"].ToString();

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

PrePayUser user = await resolvedContext.Context.PrePayUsers.SingleOrDefaultAsync(u => u.UserName == username && u.Key == key, cancellationToken);

Expand All @@ -196,7 +196,7 @@ private async Task<IActionResult> HandleLastVendRequest(RequestType xlatedReques
if (meterValidation.result != null)
return meterValidation.result;

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

IQueryable<Database.PataPawa.Transaction> transactions = resolvedContext.Context.Transactions.Where(t => t.MeterNumber == meter).AsQueryable();

Expand All @@ -223,7 +223,7 @@ private async Task<IActionResult> HandleLoginRequest(IFormCollection requestForm
String username = requestForm["username"].ToString();
String password = requestForm["password"].ToString();

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

PrePayUser user = await resolvedContext.Context.PrePayUsers.SingleOrDefaultAsync(u => u.UserName == username && u.Password == password, cancellationToken);

Expand Down Expand Up @@ -272,7 +272,7 @@ private async Task<IActionResult> HandleVendRequest(IFormCollection requestForm,
if (meterValidation.result != null)
return meterValidation.result;

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

Database.PataPawa.Transaction transaction = this.CreateTransactionRecord(amount, meterValidation.meterDetails);

Expand Down Expand Up @@ -320,7 +320,7 @@ private RequestType TranslateRequestType(String formRequest){
}));
}

using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);

PrePayMeter meterDetails = await resolvedContext.Context.PrePayMeters.SingleOrDefaultAsync(m => m.MeterNumber == meterNumber, cancellationToken);

Expand Down
4 changes: 2 additions & 2 deletions TestHosts/TestHosts/Database/PataPawa/PataPawaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace TestHosts.Database.PataPawa
public class PataPawaContext : DbContext
{
private readonly String ConnectionString;

private const String PataPawaReadModelKey = "PataPawaReadModel";
public PataPawaContext()
{
// This is the migration connection string

// Get connection string from configuration.
this.ConnectionString = ConfigurationReader.GetConnectionString("PataPawaReadModel");
this.ConnectionString = ConfigurationReader.GetConnectionString(PataPawaReadModelKey);
}

public PataPawaContext(String connectionString)
Expand Down
13 changes: 8 additions & 5 deletions TestHosts/TestHosts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Shared.Middleware;
using System;
using System.IO;
using System.Security;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
Expand All @@ -31,7 +32,9 @@
using TestHosts.SoapServices;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;

try {
const String PataPawaReadModelKey = "PataPawaReadModel";
const String TestBankReadModelKey = "TestBankReadModel";
try {

WebApplicationBuilder builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args, ContentRootPath = AppContext.BaseDirectory });

Expand Down Expand Up @@ -93,16 +96,16 @@
builder.Services.AddSingleton(typeof(IDbContextResolver<>), typeof(DbContextResolver<>));
if (builder.Environment.IsEnvironment("IntegrationTest") || builder.Configuration.GetValue<Boolean>("ServiceOptions:UseInMemoryDatabase") == true)
{
builder.Services.AddDbContext<TestBankContext>(builder => builder.UseInMemoryDatabase("TestBankReadModel"));
builder.Services.AddDbContext<PataPawaContext>(builder => builder.UseInMemoryDatabase("PataPawaReadModel"));
builder.Services.AddDbContext<TestBankContext>(builder => builder.UseInMemoryDatabase(TestBankReadModelKey));
builder.Services.AddDbContext<PataPawaContext>(builder => builder.UseInMemoryDatabase(PataPawaReadModelKey));

}
else
{
String testBankConnectionString = ConfigurationReader.GetConnectionString("TestBankReadModel");
String testBankConnectionString = ConfigurationReader.GetConnectionString(TestBankReadModelKey);
builder.Services.AddDbContext<TestBankContext>(builder => builder.UseSqlServer(testBankConnectionString));

String pataPawaConnectionString = ConfigurationReader.GetConnectionString("PataPawaReadModel");
String pataPawaConnectionString = ConfigurationReader.GetConnectionString(PataPawaReadModelKey);
builder.Services.AddDbContext<PataPawaContext>(builder => builder.UseSqlServer(pataPawaConnectionString));
}
builder.Services.AddScoped<TenantContext>(x => new TenantContext());
Expand Down
8 changes: 4 additions & 4 deletions TestHosts/TestHosts/SoapServices/PataPawaPostPayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TestHosts.SoapServices;
public class PataPawaPostPayService : IPataPawaPostPayService
{
private readonly IDbContextResolver<PataPawaContext> ContextResolver;

private const String PataPawaReadModelKey = "PataPawaReadModel";
#region Constructors

public PataPawaPostPayService(IDbContextResolver<PataPawaContext> contextResolver) {
Expand All @@ -26,7 +26,7 @@ public PataPawaPostPayService(IDbContextResolver<PataPawaContext> contextResolve
public LoginResponse Login(String username,
String password) {
// Check if we have an api key
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);
PostPaidAccount account = PataPawaPostPayService.GetPostPaidAccount(username, resolvedContext.Context);

if (account == null) {
Expand Down Expand Up @@ -67,7 +67,7 @@ public ProcessBillResponse ProcessBill(String username,
String mobile_no,
String customer_name,
Decimal amount) {
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);
PostPaidAccount account = PataPawaPostPayService.GetAccount(username, api_key, resolvedContext.Context);
if (account == null) {
// TODO: this might not be the correct way to respond in this case
Expand Down Expand Up @@ -104,7 +104,7 @@ public ProcessBillResponse ProcessBill(String username,
public VerifyResponse VerifyAccount(String username,
String api_key,
String account_no) {
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve("PataPawaReadModel");
using ResolvedDbContext<PataPawaContext>? resolvedContext = this.ContextResolver.Resolve(PataPawaReadModelKey);
PostPaidAccount account = PataPawaPostPayService.GetAccount(username, api_key, resolvedContext.Context);
if (account == null) {
// TODO: this might not be the correct way to respond in this case
Expand Down
Loading