mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-03 22:33:19 +00:00
fix: distinguish uplift request key conflicts
This commit is contained in:
parent
8af9ad076f
commit
0ca9b767ed
3 changed files with 18 additions and 3 deletions
|
|
@ -547,9 +547,7 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
{
|
{
|
||||||
var number = exceptionType.GetProperty("Number")?.GetValue(databaseException) as int?;
|
var number = exceptionType.GetProperty("Number")?.GetValue(databaseException) as int?;
|
||||||
return number is 2601 or 2627
|
return number is 2601 or 2627
|
||||||
&& databaseException.Message.Contains(
|
&& IsActiveDispatchIndexViolationMessage(databaseException.Message);
|
||||||
"IX_DispatchUpliftRequests_DispatchId",
|
|
||||||
StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (provider?.Contains("Sqlite", StringComparison.OrdinalIgnoreCase) == true
|
if (provider?.Contains("Sqlite", StringComparison.OrdinalIgnoreCase) == true
|
||||||
|
|
@ -576,6 +574,12 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsActiveDispatchIndexViolationMessage(string message)
|
||||||
|
{
|
||||||
|
const string activeDispatchIndex = "'IX_DispatchUpliftRequests_DispatchId'";
|
||||||
|
return message.Contains(activeDispatchIndex, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<T> ExecuteWorkOrderMutationAsync<T>(
|
public async Task<T> ExecuteWorkOrderMutationAsync<T>(
|
||||||
int workOrderId,
|
int workOrderId,
|
||||||
Func<CancellationToken, Task<T>> work,
|
Func<CancellationToken, Task<T>> work,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Api.SeaHavenIndustries.Tests")]
|
[assembly: InternalsVisibleTo("Api.SeaHavenIndustries.Tests")]
|
||||||
|
[assembly: InternalsVisibleTo("SeaHavenIndustries.Tests")]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,16 @@ namespace SeaHavenIndustries.Tests;
|
||||||
|
|
||||||
public sealed class UpliftDataServiceTransactionTests
|
public sealed class UpliftDataServiceTransactionTests
|
||||||
{
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Cannot insert duplicate key row with unique index 'IX_DispatchUpliftRequests_DispatchId'.", true)]
|
||||||
|
[InlineData("Cannot insert duplicate key row with unique index 'IX_DispatchUpliftRequests_DispatchId_RequestKey'.", false)]
|
||||||
|
public void IsActiveDispatchIndexViolationMessage_MatchesOnlyTheActiveDispatchIndex(
|
||||||
|
string message,
|
||||||
|
bool expected)
|
||||||
|
{
|
||||||
|
Assert.Equal(expected, UpliftDataService.IsActiveDispatchIndexViolationMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SaveChangesAsync_ActiveUpliftOnSameDispatch_MapsConcurrentInsertConflict()
|
public async Task SaveChangesAsync_ActiveUpliftOnSameDispatch_MapsConcurrentInsertConflict()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue