Skip to content

Commit

Permalink
Update borehole copy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehats committed Dec 12, 2024
1 parent 03855ef commit 2b769f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 2 additions & 7 deletions tests/api/Controllers/BoreholeControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,16 @@ public static async Task ClassCleanup()
if (testBoreholeWithIdentifiers != null)
{
cleanupContext.BoreholeCodelists.RemoveRange(testBoreholeWithIdentifiers.BoreholeCodelists);
await cleanupContext.SaveChangesAsync();
}

// This is necessary because the some tests work with multiple contexts and actually write to the database.
var boreholesToDelete = cleanupContext.Boreholes.Where(b => b.Id > MaxBoreholeSeedId);
cleanupContext.Boreholes.RemoveRange(boreholesToDelete);
await cleanupContext.SaveChangesAsync();

await cleanupContext.DisposeAsync();
}

private async Task<List<Codelist>> GetCodelists(BdmsContext context, List<int> codelistIds)
{
return await context.Codelists.Where(c => codelistIds.Contains(c.Id)).ToListAsync().ConfigureAwait(false);
}

[TestMethod]
public async Task GetAllAsyncWithFilterIds()
{
Expand Down Expand Up @@ -359,7 +354,7 @@ public async Task CopyBoreholeWithHydrotests()
using var verifyContext = ContextFactory.CreateContext();
var readController = GetTestController(verifyContext);

var response = await readController.GetByIdAsync(boreholeId).ConfigureAwait(false);
var response = await readController.GetByIdAsync((int)copiedBoreholeId).ConfigureAwait(false);
OkObjectResult okResult = (OkObjectResult)response.Result!;
Borehole copiedBorehole = (Borehole)okResult.Value!;
Assert.IsNotNull(copiedBorehole);
Expand Down
8 changes: 8 additions & 0 deletions tests/api/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,12 @@ internal static IQueryable<Layer> GetLayersWithIncludes(IQueryable<Layer> query)
.Include(l => l.LayerOrganicComponentCodes)
.Include(l => l.OrganicComponentCodelists);
}

/// <summary>
/// Get the codelists for the provided codelist ids.
/// </summary>
internal static async Task<List<Codelist>> GetCodelists(BdmsContext context, List<int> codelistIds)
{
return await context.Codelists.Where(c => codelistIds.Contains(c.Id)).ToListAsync().ConfigureAwait(false);
}
}

0 comments on commit 2b769f0

Please sign in to comment.