-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from JohnnySenior/users/ZafarUrakov/exposers-c…
…reate-efxceptions-context EXPOSERS: Create EFxceptions Context
- Loading branch information
Showing
8 changed files
with
172 additions
and
17 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
STX.EFxceptions.SqlServer.Tests.Acceptance/EFxceptionsContextTests.Logic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// -------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using STX.EFxceptions.Abstractions.Models.Exceptions; | ||
using STX.EFxceptions.SqlServer.Tests.Acceptance.Models.Clients; | ||
|
||
namespace STX.EFxceptions.SqlServer.Tests.Acceptance | ||
{ | ||
public partial class EFxceptionsContextTests | ||
{ | ||
[Fact] | ||
public void ShouldSaveChangesSuccessfully() | ||
{ | ||
// given | ||
var client = new Client | ||
{ | ||
Id = Guid.NewGuid() | ||
}; | ||
|
||
// when | ||
context.Clients.Add(client); | ||
context.SaveChanges(); | ||
|
||
// then | ||
context.Clients.Remove(client); | ||
context.SaveChanges(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldThrowDuplicateKeyExceptionOnSaveChanges() | ||
{ | ||
// given | ||
var client = new Client | ||
{ | ||
Id = Guid.NewGuid() | ||
}; | ||
|
||
// when . then | ||
Assert.Throws<DuplicateKeyException>(() => | ||
{ | ||
try | ||
{ | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
context.Clients.Add(client); | ||
context.SaveChanges(); | ||
} | ||
} | ||
catch (ArgumentException argumentException) | ||
{ | ||
throw new DuplicateKeyException(argumentException.Message); | ||
} | ||
finally | ||
{ | ||
context.Clients.Remove(client); | ||
context.SaveChanges(); | ||
} | ||
}); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
STX.EFxceptions.SqlServer.Tests.Acceptance/EFxceptionsContextTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// -------------------------------------------------------------------------------- | ||
|
||
|
||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace STX.EFxceptions.SqlServer.Tests.Acceptance | ||
{ | ||
public partial class EFxceptionsContextTests | ||
{ | ||
private readonly DbContextOptions<EFxceptionsContext> options; | ||
private readonly MyEFxceptionsContext context; | ||
|
||
public EFxceptionsContextTests() | ||
{ | ||
options = new DbContextOptionsBuilder<EFxceptionsContext>() | ||
.UseInMemoryDatabase(databaseName: "InMemoryDatabase") | ||
.Options; | ||
|
||
this.context = new MyEFxceptionsContext(options); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
STX.EFxceptions.SqlServer.Tests.Acceptance/Models/Clients/Client.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace STX.EFxceptions.SqlServer.Tests.Acceptance.Models.Clients | ||
{ | ||
public class Client | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
STX.EFxceptions.SqlServer.Tests.Acceptance/MyEFxceptionsContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using STX.EFxceptions.SqlServer.Tests.Acceptance.Models.Clients; | ||
|
||
namespace STX.EFxceptions.SqlServer.Tests.Acceptance | ||
{ | ||
public class MyEFxceptionsContext : EFxceptionsContext | ||
{ | ||
public MyEFxceptionsContext(DbContextOptions<EFxceptionsContext> options) | ||
: base(options) | ||
{ } | ||
|
||
public DbSet<Client> Clients { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using STX.EFxceptions.Abstractions.Brokers.DbErrorBroker; | ||
using STX.EFxceptions.Abstractions.Services.EFxceptions; | ||
using STX.EFxceptions.Core; | ||
using STX.EFxceptions.SqlServer.Base.Brokers.DbErrorBroker; | ||
using STX.EFxceptions.SqlServer.Base.Services.Foundations; | ||
|
||
namespace STX.EFxceptions.SqlServer | ||
{ | ||
public abstract class EFxceptionsContext : DbContextBase<SqlException> | ||
{ | ||
public EFxceptionsContext(DbContextOptions<EFxceptionsContext> options) | ||
: base(options) | ||
{ } | ||
|
||
protected EFxceptionsContext() | ||
: base() | ||
{ } | ||
|
||
protected override IDbErrorBroker<SqlException> CreateErrorBroker() => | ||
new SqlServerErrorBroker(); | ||
|
||
protected override IEFxceptionService CreateEFxceptionService( | ||
IDbErrorBroker<SqlException> errorBroker) | ||
{ | ||
return new SqlServerEFxceptionService(errorBroker); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters