Skip to content

Commit

Permalink
add EntityFrameworkCore test project
Browse files Browse the repository at this point in the history
  • Loading branch information
NickStrupat committed Sep 13, 2016
1 parent a553175 commit 29c2a41
Show file tree
Hide file tree
Showing 11 changed files with 5,669 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ UpgradeLog*.htm

# Microsoft Fakes
FakesAssemblies/
/.vs
12 changes: 12 additions & 0 deletions EntityFramework.Triggers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.NET40", "Tests.NET40\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Triggers", "EntityFrameworkCore.Triggers\EntityFrameworkCore.Triggers.csproj", "{3D1630FD-C5EB-4F63-80F0-2335E94AB6D5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "EntityFrameworkCore.Triggers.NETCore", "EntityFrameworkCore.Triggers.NETCore\EntityFrameworkCore.Triggers.NETCore.xproj", "{CDD4F32D-14A6-4A6C-BDC2-9152FC7A2786}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestsCore", "TestsCore\TestsCore.xproj", "{D74ABCC8-4776-4F0F-892E-9C0CA63B9B7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -52,6 +56,14 @@ Global
{3D1630FD-C5EB-4F63-80F0-2335E94AB6D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D1630FD-C5EB-4F63-80F0-2335E94AB6D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D1630FD-C5EB-4F63-80F0-2335E94AB6D5}.Release|Any CPU.Build.0 = Release|Any CPU
{CDD4F32D-14A6-4A6C-BDC2-9152FC7A2786}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDD4F32D-14A6-4A6C-BDC2-9152FC7A2786}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDD4F32D-14A6-4A6C-BDC2-9152FC7A2786}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDD4F32D-14A6-4A6C-BDC2-9152FC7A2786}.Release|Any CPU.Build.0 = Release|Any CPU
{D74ABCC8-4776-4F0F-892E-9C0CA63B9B7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D74ABCC8-4776-4F0F-892E-9C0CA63B9B7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D74ABCC8-4776-4F0F-892E-9C0CA63B9B7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D74ABCC8-4776-4F0F-892E-9C0CA63B9B7F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
47 changes: 47 additions & 0 deletions TestsCore/Context.cs
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);
}
}
}
20 changes: 20 additions & 0 deletions TestsCore/Entity.cs
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;
}
}
}
14 changes: 14 additions & 0 deletions TestsCore/Person.cs
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; }
}
}
19 changes: 19 additions & 0 deletions TestsCore/Properties/AssemblyInfo.cs
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")]
21 changes: 21 additions & 0 deletions TestsCore/TestsCore.xproj
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>
8 changes: 8 additions & 0 deletions TestsCore/Thing.cs
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; }
}
}
Loading

0 comments on commit 29c2a41

Please sign in to comment.