dave1
dave1
CC#
Created by dave1 on 8/4/2023 in #help
❔ base class/abstract for record
is the only way to do this and use the properties of a record to use method extensions
8 replies
CC#
Created by dave1 on 5/22/2023 in #help
❔ How to bugfix this issue of Ambigious call when it's pointing to the same package
infrastructure/Program.cs(50,18): error CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.MediatorDependencyInjectionExtensions.AddMediator(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action<Mediator.MediatorOptions>)' and 'Microsoft.Extensions.DependencyInjection.MediatorDependencyInjectionExtensions.AddMediator(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action<Mediator.MediatorOptions>)'
4 replies
CC#
Created by dave1 on 5/19/2023 in #help
❔ How explicitly define command and handlers for MediatR
I have my commands and handlers in a different project, and i dont want to include mediatr as a package
21 replies
CC#
Created by dave1 on 5/9/2023 in #help
Registering IDbCommand and autowiring and testing
i've registered the following
builder.Services.AddScoped<IDbConnection>(
_ => new NpgsqlConnection(builder.Configuration.GetConnectionString("DefaultConnection"))
);
builder.Services.AddScoped<RegionRepository>();
builder.Services.AddScoped<IDbConnection>(
_ => new NpgsqlConnection(builder.Configuration.GetConnectionString("DefaultConnection"))
);
builder.Services.AddScoped<RegionRepository>();
i now want to change that in my CustomWebApplicationFactory like..
var conn = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IDbConnection));
if (conn is null)
{
throw new Exception("NpgsqlConnection is not registered.");
}
services.Remove(conn);
services.AddScoped<IDbConnection>(
_ => new NpgsqlConnection(_postgreSqlContainer.GetConnectionString())
);
var conn = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IDbConnection));
if (conn is null)
{
throw new Exception("NpgsqlConnection is not registered.");
}
services.Remove(conn);
services.AddScoped<IDbConnection>(
_ => new NpgsqlConnection(_postgreSqlContainer.GetConnectionString())
);
but doing this the 'regions' table cannot be found, i'd presume it's not registering it correctly. When not swapping the implementation, it finds my local db with my local appsettings connection string the table does exist because i'm also registering AppDbContext with entity framework(and those tests are passing, i'm currently converting everything to repositories)
3 replies
CC#
Created by dave1 on 5/7/2023 in #help
Can someone point me in the right direction to write the following class so only the Command..
is accessible publically
public record UpsertAreaShapesCommand(
long AreaId,
List<Shapes>[] shapes
) : IRequest<Result<bool>>;

public record Shapes(
string Title,
Point[] Polygon
);

public record Point(
double X,
double Y
);
public record UpsertAreaShapesCommand(
long AreaId,
List<Shapes>[] shapes
) : IRequest<Result<bool>>;

public record Shapes(
string Title,
Point[] Polygon
);

public record Point(
double X,
double Y
);
what is the 'correct' way of writing this so Point and Shape are only accessible from that command
6 replies
CC#
Created by dave1 on 4/27/2023 in #help
❔ Struggling to delete a many to many relation
public async Task<IStatusCodeActionResult> Remove(long areaId, long houseId)
{
var area = await _context.Areas
.Include(s => s.Houses)
.FirstOrDefaultAsync(s => s.Id == areaId);

if (area == null)
return BadRequest("Area does not exist");

var house = await _context.Houses
.FirstOrDefaultAsync(s => s.Id ==houseId);

if (house == null)
return BadRequest("House does not exist");

var success = area.Houses.Remove(house);

if (success == false)
return BadRequest("House not found in this area");

_context.Areas.Update(area);

await _context.SaveChangesAsync();
public async Task<IStatusCodeActionResult> Remove(long areaId, long houseId)
{
var area = await _context.Areas
.Include(s => s.Houses)
.FirstOrDefaultAsync(s => s.Id == areaId);

if (area == null)
return BadRequest("Area does not exist");

var house = await _context.Houses
.FirstOrDefaultAsync(s => s.Id ==houseId);

if (house == null)
return BadRequest("House does not exist");

var success = area.Houses.Remove(house);

if (success == false)
return BadRequest("House not found in this area");

_context.Areas.Update(area);

await _context.SaveChangesAsync();
59 replies
CC#
Created by dave1 on 4/22/2023 in #help
❔ when using client.PostAsync('...') in a test how do you go about using transactions
As title
83 replies
CC#
Created by dave1 on 4/22/2023 in #help
❔ how to run a test to test an endpoint and to check in the database that the data been stored
I dont know what the correct way is to do this in aspnet, or if this is how it is done in .net I want to basically post to an endpointz , say /blog Check for a 201 response then check it has been stored in the database.
40 replies