-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed SaveChanges code w/ Domain interface enhancements
- Loading branch information
Showing
18 changed files
with
281 additions
and
177 deletions.
There are no files selected for viewing
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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace E13.Common.Domain | ||
{ | ||
public interface ICreatable : IEntity | ||
{ | ||
string CreatedBy { get; set; } | ||
string CreatedSource { get; set; } | ||
DateTime Created { get; set; } | ||
} | ||
} |
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
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
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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace E13.Common.Domain | ||
{ | ||
public interface IModifiable : IEntity | ||
{ | ||
string ModifiedBy { get; set; } | ||
string ModifiedSource { get; set; } | ||
DateTime? Modified { get; set; } | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.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,64 @@ | ||
using E13.Common.Data.Db.Tests.Sample; | ||
using FluentAssertions; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace E13.Common.Data.Db.Tests | ||
{ | ||
public class BaseDbContext_ICreatableTests | ||
{ | ||
private TestDbContext Context; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddDbContext<TestDbContext>(o => o.UseInMemoryDatabase($"{Guid.NewGuid()}")); | ||
|
||
Context = services.BuildServiceProvider().GetService<TestDbContext>(); | ||
Context.AddTestData(); | ||
} | ||
[Test] | ||
public void InitialData_CreatedSource_AddTestData() | ||
{ | ||
var arranged = Context.Creatables.First(); | ||
|
||
arranged.CreatedSource.Should().Be("E13.Common.Data.Db.Tests.Sample.TestDbContext.AddTestData"); | ||
} | ||
|
||
[Test] | ||
public void InitialData_CreatedBy_Unknown() | ||
{ | ||
var arranged = Context.Creatables.First(); | ||
|
||
arranged.CreatedBy.Should().Be(BaseDbContext.UnknownUser); | ||
} | ||
|
||
[Test] | ||
public void SaveChanges_UnknownUser_CreatedByUnknown() | ||
{ | ||
var id = Guid.NewGuid(); | ||
Context.Creatables.Add(new TestCreatable { Id = id }); | ||
Context.SaveChanges(); | ||
|
||
var arranged = Context.Creatables.First(e => e.Id == id); | ||
|
||
arranged.CreatedBy.Should().Be(BaseDbContext.UnknownUser); | ||
} | ||
|
||
[Test] | ||
public void SaveChanges_NamedUser_CreatedByNamedUser() | ||
{ | ||
var id = Guid.NewGuid(); | ||
Context.Creatables.Add(new TestCreatable { Id = id }); | ||
Context.SaveChanges(nameof(SaveChanges_NamedUser_CreatedByNamedUser)); | ||
|
||
var arranged = Context.Creatables.First(e => e.Id == id); | ||
|
||
arranged.CreatedBy.Should().Be(nameof(SaveChanges_NamedUser_CreatedByNamedUser)); | ||
} | ||
} | ||
} |
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
129 changes: 0 additions & 129 deletions
129
test/E13.Common.Data.Db.Tests/BaseDbContext_IEntityTests.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.