-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add EntityFrameworkCore test project
- Loading branch information
1 parent
a553175
commit 29c2a41
Showing
11 changed files
with
5,669 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,3 +181,4 @@ UpgradeLog*.htm | |
|
||
# Microsoft Fakes | ||
FakesAssemblies/ | ||
/.vs |
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,47 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
#if EF_CORE | ||
using Microsoft.EntityFrameworkCore; | ||
using EntityFrameworkCore.Triggers; | ||
#else | ||
using EntityFramework.Triggers; | ||
using System.Data.Entity; | ||
using System.Data.Entity.Migrations; | ||
#endif | ||
|
||
namespace Tests { | ||
public class InternalContext : DbContext { | ||
// public override Int32 SaveChanges() { | ||
// return base.SaveChanges(); | ||
// } | ||
//#if !NET40 | ||
// public override Task<Int32> SaveChangesAsync(CancellationToken cancellationToken) { | ||
// return base.SaveChangesAsync(cancellationToken); | ||
// } | ||
//#endif | ||
} | ||
|
||
internal sealed class Configuration : DbMigrationsConfiguration<Context> { | ||
public Configuration() { | ||
AutomaticMigrationsEnabled = true; | ||
AutomaticMigrationDataLossAllowed = true; | ||
} | ||
} | ||
|
||
public class Context : DbContext { | ||
public Context() : base("Triggers.Tests") { } | ||
|
||
public DbSet<Person> People { get; set; } | ||
public DbSet<Thing> Things { get; set; } | ||
|
||
public override Int32 SaveChanges() { | ||
return this.SaveChangesWithTriggers(); | ||
} | ||
|
||
public override Task<Int32> SaveChangesAsync(CancellationToken cancellationToken) { | ||
return this.SaveChangesWithTriggersAsync(cancellationToken); | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using EntityFramework.Triggers; | ||
|
||
namespace Tests { | ||
public abstract class EntityWithInsertTracking : ITriggerable { | ||
public DateTime Inserted { get; private set; } | ||
public Int32 Number { get; private set; } | ||
static EntityWithInsertTracking() { | ||
Triggers<EntityWithInsertTracking>.Inserting += e => e.Entity.Inserted = DateTime.UtcNow; | ||
Triggers<EntityWithInsertTracking>.Inserting += e => e.Entity.Number = 42; | ||
} | ||
} | ||
public abstract class EntityWithTracking : EntityWithInsertTracking { | ||
public DateTime Updated { get; private set; } | ||
protected EntityWithTracking() { | ||
this.Triggers().Inserting += e => e.Entity.Updated = DateTime.UtcNow; | ||
this.Triggers().Updating += e => e.Entity.Updated = DateTime.UtcNow; | ||
} | ||
} | ||
} |
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,14 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using EntityFramework.Triggers; | ||
|
||
namespace Tests { | ||
public class Person : EntityWithTracking, ITriggerable { | ||
[Key] | ||
public virtual Int64 Id { get; private set; } | ||
public String FirstName { get; set; } | ||
[Required] | ||
public String LastName { get; set; } | ||
public Boolean IsMarkedDeleted { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("TestsCore")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("d74abcc8-4776-4f0f-892e-9c0ca63b9b7f")] |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>d74abcc8-4776-4f0f-892e-9c0ca63b9b7f</ProjectGuid> | ||
<RootNamespace>TestsCore</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
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,8 @@ | ||
using System; | ||
|
||
namespace Tests { | ||
public class Thing { | ||
public Int64 Id { get; private set; } | ||
public String Value { get; set; } | ||
} | ||
} |
Oops, something went wrong.