-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved ChangeTracker feeding. Improved ConnectionString retrieval f…
…or NpgSql (#68) * Improved ChangeTracker feeding. Improved ConnectionString retrieval for NpgSql. * Updated linq2db version. * Increased library version to 3.7.0
- Loading branch information
Showing
24 changed files
with
723 additions
and
9 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
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
105 changes: 105 additions & 0 deletions
105
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/AAA.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,105 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public class Unit | ||
{ | ||
|
||
} | ||
|
||
public static class ExceptionExtensions | ||
{ | ||
public static Unit Throw(this Exception e) => throw e; | ||
} | ||
|
||
public static class AAA | ||
{ | ||
public static ArrangeResult<T, Unit> Arrange<T>(this T @object, Action<T> action) | ||
{ | ||
action(@object); | ||
return new ArrangeResult<T, Unit>(@object, default); | ||
} | ||
|
||
public static ArrangeResult<T, Unit> Arrange<T>(T @object) | ||
=> new ArrangeResult<T, Unit>(@object, default); | ||
|
||
public static ArrangeResult<T, TMock> Arrange<T, TMock>(this TMock mock, Func<TMock, T> @object) | ||
=> new ArrangeResult<T, TMock>(@object(mock), mock); | ||
|
||
public static ActResult<T, TMock> Act<T, TMock>(this ArrangeResult<T, TMock> arrange, Action<T> act) | ||
{ | ||
try | ||
{ | ||
act(arrange.Object); | ||
return new ActResult<T, TMock>(arrange.Object, arrange.Mock, default); | ||
} | ||
catch (Exception e) | ||
{ | ||
return new ActResult<T, TMock>(arrange.Object, arrange.Mock, e); | ||
} | ||
} | ||
|
||
public static ActResult<TResult, TMock> Act<T, TMock, TResult>(this ArrangeResult<T, TMock> arrange, Func<T, TResult> act) | ||
{ | ||
try | ||
{ | ||
return new ActResult<TResult, TMock>(act(arrange.Object), arrange.Mock, default); | ||
} | ||
catch (Exception e) | ||
{ | ||
return new ActResult<TResult, TMock>(default, arrange.Mock, e); | ||
} | ||
} | ||
|
||
public static void Assert<T, TMock>(this ActResult<T, TMock> act, Action<T> assert) | ||
{ | ||
act.Exception?.Throw(); | ||
assert(act.Object); | ||
} | ||
|
||
public static void Assert<T, TMock>(this ActResult<T, TMock> act, Action<T, TMock> assert) | ||
{ | ||
act.Exception?.Throw(); | ||
assert(act.Object, act.Mock); | ||
} | ||
|
||
public static Task<ArrangeResult<T, Unit>> ArrangeAsync<T>(T @object) | ||
=> Task.FromResult(new ArrangeResult<T, Unit>(@object, default)); | ||
|
||
public static async Task<ActResult<TResult, TMock>> Act<T, TMock, TResult>(this Task<ArrangeResult<T, TMock>> arrange, Func<T, Task<TResult>> act) | ||
{ | ||
var a = await arrange; | ||
try | ||
{ | ||
return new ActResult<TResult, TMock>(await act(a.Object), a.Mock, default); | ||
} | ||
catch (Exception e) | ||
{ | ||
return new ActResult<TResult, TMock>(default, a.Mock, e); | ||
} | ||
} | ||
|
||
public static async Task Assert<T, TMock>(this Task<ActResult<T, TMock>> act, Func<T, Task> assert) | ||
{ | ||
var result = await act; | ||
await assert(result.Object); | ||
} | ||
|
||
public readonly struct ArrangeResult<T, TMock> | ||
{ | ||
internal ArrangeResult(T @object, TMock mock) => (Object, Mock) = (@object, mock); | ||
internal T Object { get; } | ||
internal TMock Mock { get; } | ||
} | ||
|
||
public readonly struct ActResult<T, TMock> | ||
{ | ||
internal ActResult(T @object, TMock mock, Exception exception) | ||
=> (Object, Mock, Exception) = (@object, mock, exception); | ||
internal T Object { get; } | ||
internal TMock Mock { get; } | ||
internal Exception Exception { get; } | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/Child.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,10 @@ | ||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public sealed class Child : IHasWriteableId<Child, long> | ||
{ | ||
public Id<Child, long> Id { get; set; } | ||
public Id<Entity, long> ParentId { get; set; } | ||
public string Name { get; set; } | ||
public Entity Parent { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/DataContextExtensions.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,12 @@ | ||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public static class DataContextExtensions | ||
{ | ||
public static Id<T, long> Insert<T>(this IDataContext context, T item) | ||
where T : IHasWriteableId<T, long> | ||
{ | ||
item.Id = context.InsertWithInt64Identity(item).AsId<T>(); | ||
return item.Id; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/Detail.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 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public sealed class Detail : IHasWriteableId<Detail, long> | ||
{ | ||
public Id<Detail, long> Id { get; set; } | ||
public Id<Entity, long> MasterId { get; set; } | ||
public string Name { get; set; } | ||
public Entity Master { get; set; } | ||
public IEnumerable<SubDetail> Details { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/Entity.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,14 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public sealed class Entity : IHasWriteableId<Entity, long> | ||
{ | ||
public Id<Entity, long> Id { get; set; } | ||
public string Name { get; set; } | ||
|
||
public IEnumerable<Detail> Details { get; set; } | ||
public IEnumerable<Child> Children { get; set; } | ||
public IEnumerable<Entity2Item> Items { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/Entity2Item.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,15 @@ | ||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public sealed class Entity2Item | ||
{ | ||
public Id<Entity, long> EntityId { get; set; } | ||
public Entity Entity { get; set; } | ||
public Id<Item, long> ItemId { get; set; } | ||
|
||
public Entity2Item() | ||
{ | ||
} | ||
|
||
public Item Item { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/IHasId.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,12 @@ | ||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public interface IHasId<T, TId> where T: IHasId<T, TId> | ||
{ | ||
Id<T, TId> Id { get; } | ||
} | ||
|
||
public interface IHasWriteableId<T, TId> : IHasId<T, TId> where T: IHasWriteableId<T, TId> | ||
{ | ||
new Id<T, TId> Id { get; set; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/Id.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,28 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests | ||
{ | ||
public static class Id | ||
{ | ||
public static Id<T, long> AsId<T>(this long id) where T : IHasId<T, long> => id.AsId<T, long>(); | ||
|
||
public static Id<T, TId> AsId<T, TId>(this TId id) where T : IHasId<T, TId> | ||
=> new Id<T, TId>(id); | ||
} | ||
|
||
public readonly struct Id<T, TId> where T : IHasId<T, TId> | ||
{ | ||
internal Id(TId value) => Value = value; | ||
TId Value { get; } | ||
|
||
public static implicit operator TId (in Id<T, TId> id) => id.Value; | ||
public static bool operator == (Id<T, TId> left, Id<T, TId> right) | ||
=> EqualityComparer<TId>.Default.Equals(left.Value, right.Value); | ||
public static bool operator != (Id<T, TId> left, Id<T, TId> right) => !(left == right); | ||
|
||
public override string ToString() => $"{typeof(T).Name}({Value})"; | ||
public bool Equals(Id<T, TId> other) => EqualityComparer<TId>.Default.Equals(Value, other.Value); | ||
public override bool Equals(object obj) => obj is Id<T, TId> other && Equals(other); | ||
public override int GetHashCode() => EqualityComparer<TId>.Default.GetHashCode(Value); | ||
} | ||
} |
Oops, something went wrong.