diff --git a/E13.Common.sln b/E13.Common.sln
index dd0fb20..ae2e5a6 100644
--- a/E13.Common.sln
+++ b/E13.Common.sln
@@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "E13.Common.Nunit.UI", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "E13.Common.Api.AzureAD", "src\E13.Common.Api.AzureAD\E13.Common.Api.AzureAD.csproj", "{3A9E46CA-6D1A-4811-93DB-1D9C0193E135}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "E13.Common.Data.Db.Tests", "test\E13.Common.Data.Db.Tests\E13.Common.Data.Db.Tests.csproj", "{E57FB194-8742-4183-8FBF-0EDA6C09F4A6}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -101,6 +103,10 @@ Global
{3A9E46CA-6D1A-4811-93DB-1D9C0193E135}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A9E46CA-6D1A-4811-93DB-1D9C0193E135}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A9E46CA-6D1A-4811-93DB-1D9C0193E135}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E57FB194-8742-4183-8FBF-0EDA6C09F4A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E57FB194-8742-4183-8FBF-0EDA6C09F4A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E57FB194-8742-4183-8FBF-0EDA6C09F4A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E57FB194-8742-4183-8FBF-0EDA6C09F4A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -109,6 +115,7 @@ Global
{C60CA223-5F6E-47BF-ACFE-66CD54F0D2DC} = {30D836B3-FF29-49DC-B503-94B8F9B6DC50}
{C4E41E15-6FBB-4861-84E8-B3ECA206948C} = {30D836B3-FF29-49DC-B503-94B8F9B6DC50}
{1C96B136-221B-4BF9-8626-F14637A37555} = {30D836B3-FF29-49DC-B503-94B8F9B6DC50}
+ {E57FB194-8742-4183-8FBF-0EDA6C09F4A6} = {30D836B3-FF29-49DC-B503-94B8F9B6DC50}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {86FB5264-87DD-494C-885E-05EA38F8DB19}
diff --git a/src/E13.Common.Data.Db/BaseDbContext.cs b/src/E13.Common.Data.Db/BaseDbContext.cs
index 6ca3db9..3de0d04 100644
--- a/src/E13.Common.Data.Db/BaseDbContext.cs
+++ b/src/E13.Common.Data.Db/BaseDbContext.cs
@@ -7,6 +7,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
+using System.Reflection;
namespace E13.Common.Data.Db
{
@@ -15,14 +16,13 @@ public abstract class BaseDbContext : DbContext
///
/// The user name used when the user name is null
///
- private const string UnknownUser = "*Unknown";
+ public const string UnknownUser = "*Unknown";
protected ILogger Logger { get;}
- protected string User { get; set; }
- protected BaseDbContext(ILogger logger, string user)
+ protected BaseDbContext(DbContextOptions options, ILogger logger)
+ : base(options)
{
Logger = logger;
- User = user;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
@@ -30,25 +30,39 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
base.OnConfiguring(optionsBuilder);
}
- public override int SaveChanges()
+ public int SaveChanges(string user, string source = null)
{
- var caller = new StackFrame(1).GetMethod();
- TagEntries($"{caller.DeclaringType}.{caller.Name}");
+ if(source == null)
+ {
+ var caller = new StackFrame(1).GetMethod();
+ source = $"{caller.DeclaringType}.{caller.Name}";
+ }
+
+ TagEntries(source, user);
var result = base.SaveChanges();
// saving after a reload effectively clears the change tracker affecting no records
Reload();
base.SaveChanges();
-
+
return result;
}
+ public override int SaveChanges()
+ {
+ var caller = new StackFrame(1).GetMethod();
+
+ return SaveChanges(UnknownUser, $"{caller.DeclaringType}.{caller.Name}");
+ }
+
public void Reload() => ChangeTracker.Entries()
.Where(e => e.Entity != null).ToList()
.ForEach(e => e.State = EntityState.Detached);
- private void TagEntries(string source)
+ private void TagEntries(string source, string user)
{
+ var e = ChangeTracker.Entries().ToList();
+
var entries = ChangeTracker.Entries().Where(e =>
e.Entity is IEntity &&
(e.State == EntityState.Added || e.State == EntityState.Modified || e.State == EntityState.Deleted)
@@ -61,28 +75,28 @@ e.Entity is IEntity &&
Logger.LogDebug($"Entity: {entry.Entity.GetType().Name}, State: {entry.State}");
var utcNow = DateTime.UtcNow;
- if (entry.Entity is IEntity)
+ if (entry.State == EntityState.Added && entry.Entity is ICreatable creatable)
+ {
+ creatable.Created = utcNow;
+ creatable.CreatedBy = user;
+ creatable.CreatedSource = source;
+ }
+
+ if (entry.Entity is IModifiable modifiable)
{
- if (entry.State == EntityState.Added)
- {
- ((IEntity)entry.Entity).Created = utcNow;
- ((IEntity)entry.Entity).CreatedBy = User ?? UnknownUser;
- ((IEntity)entry.Entity).CreatedSource = source;
- }
-
- ((IEntity)entry.Entity).Modified = utcNow;
- ((IEntity)entry.Entity).ModifiedBy = User ?? UnknownUser;
- ((IEntity)entry.Entity).ModifiedSource = source;
-
- if (entry.State == EntityState.Deleted && entry.Entity is IDeletable)
- {
- // Implementing IDeletable implies soft deletes required
- entry.State = EntityState.Modified;
-
- ((IDeletable)entry.Entity).Deleted = utcNow;
- ((IDeletable)entry.Entity).DeletedBy = User ?? UnknownUser;
- ((IDeletable)entry.Entity).DeletedSource = source;
- }
+ modifiable.Modified = utcNow;
+ modifiable.ModifiedBy = user;
+ modifiable.ModifiedSource = source;
+ }
+
+ if (entry.State == EntityState.Deleted && entry.Entity is IDeletable deletable)
+ {
+ // Implementing IDeletable implies soft deletes required
+ entry.State = EntityState.Modified;
+
+ deletable.Deleted = utcNow;
+ deletable.DeletedBy = user;
+ deletable.DeletedSource = source;
}
}
}
diff --git a/src/E13.Common.Data.Db/Repository.cs b/src/E13.Common.Data.Db/Repository.cs
index 0e84925..7353014 100644
--- a/src/E13.Common.Data.Db/Repository.cs
+++ b/src/E13.Common.Data.Db/Repository.cs
@@ -282,7 +282,7 @@ public virtual int Count(Expression> predicate = null)
/// The entity to insert.
public virtual void Insert(TEntity entity)
{
- var entry = DbSet.Add(entity);
+ DbSet.Add(entity);
}
///
diff --git a/src/E13.Common.Domain/ICreatable.cs b/src/E13.Common.Domain/ICreatable.cs
new file mode 100644
index 0000000..777782e
--- /dev/null
+++ b/src/E13.Common.Domain/ICreatable.cs
@@ -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; }
+ }
+}
diff --git a/src/E13.Common.Domain/IDeletable.cs b/src/E13.Common.Domain/IDeletable.cs
index 232ddb8..23ba7ff 100644
--- a/src/E13.Common.Domain/IDeletable.cs
+++ b/src/E13.Common.Domain/IDeletable.cs
@@ -8,6 +8,8 @@ public interface IDeletable : IEntity
{
string DeletedBy { get; set; }
string DeletedSource { get; set; }
- DateTime Deleted { get; set; }
+ DateTime? Deleted { get; set; }
+ public bool IsDeleted()
+ { return Deleted == null; }
}
}
diff --git a/src/E13.Common.Domain/IEntity.cs b/src/E13.Common.Domain/IEntity.cs
index 35ce738..da3253d 100644
--- a/src/E13.Common.Domain/IEntity.cs
+++ b/src/E13.Common.Domain/IEntity.cs
@@ -5,13 +5,5 @@ namespace E13.Common.Domain
public interface IEntity
{
Guid Id { get; set; }
-
- string CreatedBy { get; set; }
- string CreatedSource { get; set; }
- DateTime Created { get; set; }
-
- string ModifiedBy { get; set; }
- string ModifiedSource { get; set; }
- DateTime Modified { get; set; }
}
}
diff --git a/src/E13.Common.Domain/IModifiable.cs b/src/E13.Common.Domain/IModifiable.cs
new file mode 100644
index 0000000..964b477
--- /dev/null
+++ b/src/E13.Common.Domain/IModifiable.cs
@@ -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; }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/BaseDbContextTests.cs b/test/E13.Common.Data.Db.Tests/BaseDbContextTests.cs
new file mode 100644
index 0000000..25c5ea2
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/BaseDbContextTests.cs
@@ -0,0 +1,51 @@
+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 BaseDbContextTests
+ {
+ private TestDbContext Context;
+
+ [SetUp]
+ public void Setup()
+ {
+ var services = new ServiceCollection();
+ services.AddDbContext(o => o.UseInMemoryDatabase($"{Guid.NewGuid()}"));
+
+ Context = services.BuildServiceProvider().GetService();
+ Context.AddTestData();
+ }
+
+ ///
+ /// InMemory Data should initialize to a single entry in every table
+ ///
+ [Test]
+ public void InMemory_Baseline_OnePerTable()
+ {
+ Context.Creatables.Count().Should().Be(1);
+ Context.Modifiables.Count().Should().Be(1);
+ Context.Deletable.Count().Should().Be(1);
+ Context.Effectable.Count().Should().Be(1);
+ Context.Ownable.Count().Should().Be(1);
+ }
+
+ ///
+ /// InMemory Data should initialize with a non-empty guid for the Id
+ ///
+ [Test]
+ public void InMemory_Baseline_EmptyGuids()
+ {
+ Context.Creatables.All(e => e.Id == Guid.Empty).Should().BeFalse();
+ Context.Modifiables.All(e => e.Id == Guid.Empty).Should().BeFalse();
+ Context.Deletable.All(e => e.Id == Guid.Empty).Should().BeFalse();
+ Context.Effectable.All(e => e.Id == Guid.Empty).Should().BeFalse();
+ Context.Ownable.All(e => e.Id == Guid.Empty).Should().BeFalse();
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.cs b/test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.cs
new file mode 100644
index 0000000..9f38300
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.cs
@@ -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(o => o.UseInMemoryDatabase($"{Guid.NewGuid()}"));
+
+ Context = services.BuildServiceProvider().GetService();
+ 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));
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/E13.Common.Data.Db.Tests/BaseDbContext_IDeletableTests.cs b/test/E13.Common.Data.Db.Tests/BaseDbContext_IDeletableTests.cs
new file mode 100644
index 0000000..1bf57b3
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/BaseDbContext_IDeletableTests.cs
@@ -0,0 +1,57 @@
+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_IDeletableTests
+ {
+ private TestDbContext Context;
+
+ [SetUp]
+ public void Setup()
+ {
+ var services = new ServiceCollection();
+ services.AddDbContext(o => o.UseInMemoryDatabase($"{Guid.NewGuid()}"));
+
+ Context = services.BuildServiceProvider().GetService();
+ Context.AddTestData();
+ }
+
+ [Test]
+ public void SaveChanges_Deleting_SetsDeleted()
+ {
+ Context.Deletable.Count().Should().Be(1);
+ Context.Deletable.Count(e => e.Deleted == null).Should().Be(1);
+ var arranged = Context.Deletable.First();
+
+ Context.Deletable.Remove(arranged);
+ Context.SaveChanges();
+ var a = Context.Deletable.Count();
+
+ Context.Deletable.Count().Should().Be(1);
+ Context.Deletable.Count(e => e.Deleted == null).Should().Be(0);
+ Context.Deletable.Count(e => e.Deleted != null).Should().Be(1);
+ }
+
+ [Test]
+ public void SaveChangesForUser_Deleting_SetsDeletedBy()
+ {
+ Context.Deletable.Count().Should().Be(1);
+ Context.Deletable.Count(e => e.DeletedBy == null).Should().Be(1);
+ var arranged = Context.Deletable.First();
+
+ Context.Deletable.Remove(arranged);
+ Context.SaveChanges(nameof(SaveChangesForUser_Deleting_SetsDeletedBy));
+
+ Context.Deletable.Count().Should().Be(1);
+ Context.Deletable.Count(e => e.DeletedBy == null).Should().Be(0);
+ Context.Deletable.Count(e => e.DeletedBy == nameof(SaveChangesForUser_Deleting_SetsDeletedBy)).Should().Be(1);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/test/E13.Common.Data.Db.Tests/BaseDbContext_IModifiableTests.cs b/test/E13.Common.Data.Db.Tests/BaseDbContext_IModifiableTests.cs
new file mode 100644
index 0000000..38791b5
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/BaseDbContext_IModifiableTests.cs
@@ -0,0 +1,104 @@
+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_IModifiableTests
+ {
+ private TestDbContext Context;
+
+ [SetUp]
+ public void Setup()
+ {
+ var services = new ServiceCollection();
+ services.AddDbContext(o => o.UseInMemoryDatabase($"{Guid.NewGuid()}"));
+
+ Context = services.BuildServiceProvider().GetService();
+ Context.AddTestData();
+ }
+
+ [Test]
+ public void InitialData_ModifiedBy_Null()
+ {
+ var arranged = Context.Modifiables.First();
+
+ arranged.ModifiedBy.Should().NotBeNull();
+ }
+
+ [Test]
+ public void InitialData_Modified_Null()
+ {
+ var arranged = Context.Modifiables.First();
+
+ arranged.Modified.Should().NotBeNull();
+ }
+
+ [Test]
+ public void InitialData_ModifiedSource_Null()
+ {
+ var arranged = Context.Modifiables.First();
+
+ arranged.ModifiedSource.Should().NotBeNull();
+ }
+
+ [Test]
+ public void SaveChanges_UnspecifiedUser_ModifiedByUnknown()
+ {
+ var initial = Context.Modifiables.First();
+ initial.Text.Should().BeNull();
+
+ //act
+ initial.Text = $"{Guid.NewGuid()}";
+ Context.SaveChanges();
+
+ var assert = Context.Modifiables.First();
+ assert.ModifiedBy.Should().Be(BaseDbContext.UnknownUser);
+ }
+
+ [Test]
+ public void SaveChanges_UnspecifiedUser_ModifiedUpdates()
+ {
+ var initial = Context.Modifiables.First();
+ var arranged = initial.Modified;
+
+ //act
+ initial.Text = $"{Guid.NewGuid()}";
+ Context.SaveChanges();
+
+ var actual = Context.Modifiables.First();
+ actual.Modified.Should().BeAfter(arranged.Value);
+ }
+
+ [Test]
+ public void SaveChanges_NamedUser_UpdatesModifiedBy()
+ {
+ var arranged = Context.Modifiables.First();
+ arranged.Text.Should().BeNull();
+
+ //act
+ arranged.Text = $"{Guid.NewGuid()}";
+ Context.SaveChanges(nameof(SaveChanges_NamedUser_UpdatesModifiedBy));
+
+ var assert = Context.Modifiables.First();
+ assert.ModifiedBy.Should().Be(nameof(SaveChanges_NamedUser_UpdatesModifiedBy));
+ }
+
+ [Test]
+ public void SaveChanges_NamedUser_ModifiedUpdates()
+ {
+ var arranged = Context.Modifiables.First();
+
+ //act
+ arranged.Text = $"{Guid.NewGuid()}";
+ Context.SaveChanges(nameof(SaveChanges_NamedUser_ModifiedUpdates));
+
+ var actual = Context.Modifiables.First();
+ actual.Modified.Should().NotBeNull();
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/E13.Common.Data.Db.Tests/E13.Common.Data.Db.Tests.csproj b/test/E13.Common.Data.Db.Tests/E13.Common.Data.Db.Tests.csproj
new file mode 100644
index 0000000..e87d554
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/E13.Common.Data.Db.Tests.csproj
@@ -0,0 +1,27 @@
+
+
+
+ net5.0
+ latest
+ false
+ E13 Tech
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestCreatable.cs b/test/E13.Common.Data.Db.Tests/Sample/TestCreatable.cs
new file mode 100644
index 0000000..612f3b1
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestCreatable.cs
@@ -0,0 +1,19 @@
+using E13.Common.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestCreatable : ICreatable
+ {
+ public Guid Id { get; set; }
+ public string Text { get; set; }
+
+ public string CreatedBy { get; set; }
+ public string CreatedSource { get; set; }
+ public DateTime Created { get; set; }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs b/test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs
new file mode 100644
index 0000000..eede23f
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs
@@ -0,0 +1,48 @@
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging.Abstractions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestDbContext : BaseDbContext
+ {
+ public DbSet Creatables { get; set; }
+ public DbSet Modifiables { get; set; }
+ public DbSet Deletable { get; set; }
+ public DbSet Effectable { get; set; }
+ public DbSet Ownable { get; set; }
+
+ public TestDbContext(DbContextOptions opt)
+ : base(opt, new NullLogger())
+ { }
+
+ public void AddTestData()
+ {
+ Creatables.Add(new TestCreatable
+ {
+ Id = Guid.Empty
+ });
+ Modifiables.Add(new TestModifiable
+ {
+ Id = Guid.Empty
+ });
+ Deletable.Add(new TestDeletable
+ {
+ Id = Guid.Empty
+ });
+ Effectable.Add(new TestEffectable
+ {
+ Id = Guid.Empty
+ });
+ Ownable.Add(new TestOwnable
+ {
+ Id = Guid.Empty
+ });
+ SaveChanges();
+ }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestDeletable.cs b/test/E13.Common.Data.Db.Tests/Sample/TestDeletable.cs
new file mode 100644
index 0000000..4aac072
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestDeletable.cs
@@ -0,0 +1,17 @@
+using E13.Common.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestDeletable : IDeletable
+ {
+ public Guid Id { get; set; }
+ public string DeletedBy { get; set; }
+ public string DeletedSource { get; set; }
+ public DateTime? Deleted { get; set; }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestEffectable.cs b/test/E13.Common.Data.Db.Tests/Sample/TestEffectable.cs
new file mode 100644
index 0000000..aa10800
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestEffectable.cs
@@ -0,0 +1,17 @@
+using E13.Common.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestEffectable : IEffectable
+ {
+ public Guid Id { get; set; }
+ public string EffectiveBy { get; set; }
+ public string EffectiveSource { get; set; }
+ public DateTime Effective { get; set; }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestEntity.cs b/test/E13.Common.Data.Db.Tests/Sample/TestEntity.cs
new file mode 100644
index 0000000..b32408e
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestEntity.cs
@@ -0,0 +1,15 @@
+using E13.Common.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestEntity : IEntity
+ {
+ public Guid Id { get; set; }
+ public string Text { get; set; }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestModifiable.cs b/test/E13.Common.Data.Db.Tests/Sample/TestModifiable.cs
new file mode 100644
index 0000000..4b13fed
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestModifiable.cs
@@ -0,0 +1,19 @@
+using E13.Common.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestModifiable : IModifiable
+ {
+ public Guid Id { get; set; }
+ public string Text { get; set; }
+
+ public string ModifiedBy { get; set; }
+ public string ModifiedSource { get; set; }
+ public DateTime? Modified { get; set; }
+ }
+}
diff --git a/test/E13.Common.Data.Db.Tests/Sample/TestOwnable.cs b/test/E13.Common.Data.Db.Tests/Sample/TestOwnable.cs
new file mode 100644
index 0000000..475e152
--- /dev/null
+++ b/test/E13.Common.Data.Db.Tests/Sample/TestOwnable.cs
@@ -0,0 +1,17 @@
+using E13.Common.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace E13.Common.Data.Db.Tests.Sample
+{
+ public class TestOwnable : IOwnable
+ {
+ public Guid Id { get; set; }
+ public string OwnedBy { get; set; }
+ public string OwnedSource { get; set; }
+ public DateTime Owned { get; set; }
+ }
+}
diff --git a/test/E13.Common.Domain.Tests/E13.Common.Domain.Tests.csproj b/test/E13.Common.Domain.Tests/E13.Common.Domain.Tests.csproj
index 72027ab..1c7e1ac 100644
--- a/test/E13.Common.Domain.Tests/E13.Common.Domain.Tests.csproj
+++ b/test/E13.Common.Domain.Tests/E13.Common.Domain.Tests.csproj
@@ -1,4 +1,4 @@
-
+
net5.0
@@ -23,4 +23,5 @@
+
diff --git a/test/E13.Common.Domain.Tests/IDeletableTests.cs b/test/E13.Common.Domain.Tests/IDeletableTests.cs
new file mode 100644
index 0000000..b405bde
--- /dev/null
+++ b/test/E13.Common.Domain.Tests/IDeletableTests.cs
@@ -0,0 +1,27 @@
+using FluentAssertions.Common;
+using NUnit.Framework;
+using System;
+
+namespace E13.Common.Domain.Tests
+{
+ public class IDeletableTests
+ {
+
+ [Test]
+ public void IsDeleted_DeletedNull_False()
+ {
+ IDeletable arranged = new IDeletableSample { Deleted = null };
+
+ arranged.IsDeleted();
+ }
+ }
+
+ public class IDeletableSample : IDeletable
+ {
+ public Guid Id { get; set; }
+ public string DeletedBy { get; set; }
+ public string DeletedSource { get; set; }
+ public DateTime? Deleted { get; set; }
+
+ }
+}
\ No newline at end of file