committed by
GitHub
parent
ac20664446
commit
79549bea05
24
MainProject.Tests/TestsUtils/ExceptionSqlServerContext.cs
Normal file
24
MainProject.Tests/TestsUtils/ExceptionSqlServerContext.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using BasicDotnetTemplate.MainProject.Core.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
public class ExceptionSqlServerContext : SqlServerContext
|
||||
{
|
||||
public bool ThrowExceptionOnSave { get; set; }
|
||||
|
||||
public ExceptionSqlServerContext() : base(TestUtils.CreateInMemorySqlContextOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (ThrowExceptionOnSave)
|
||||
{
|
||||
throw new Exception("Database error");
|
||||
}
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user