-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed end-user transactions and added unit tests
- Loading branch information
1 parent
0df7977
commit 8eb7708
Showing
3 changed files
with
100 additions
and
5 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
94 changes: 94 additions & 0 deletions
94
src/Venflow/Venflow.Tests/TransactionTests/TransactionTests.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,94 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Npgsql; | ||
using Venflow.Tests.Models; | ||
using Xunit; | ||
|
||
namespace Venflow.Tests.TransactionTests | ||
{ | ||
public class TransactionTests : TestBase | ||
{ | ||
[Fact] | ||
public async Task ReuseTransactionAsync() | ||
{ | ||
await using var transaction = await Database.BeginTransactionAsync(); | ||
|
||
Assert.Equal(transaction, await Database.BeginTransactionAsync()); | ||
} | ||
|
||
[Fact] | ||
public async Task RollbackToTransactionSavepointAsync() | ||
{ | ||
await using var transaction = await Database.BeginTransactionAsync(); | ||
|
||
await Assert.ThrowsAsync<NotImplementedException>(() => Database.People.InsertAsync(new Person { Emails = new ThrowingEmailList() })); | ||
|
||
var transactionType = transaction.GetType(); | ||
var npgsqlTransactionType = typeof(NpgsqlTransaction); | ||
|
||
Assert.False((bool)transactionType.GetProperty("IsDisposed", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(transaction)); | ||
Assert.False((bool)npgsqlTransactionType.GetProperty("IsCompleted", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(transaction.GetNpgsqlTransaction())); | ||
} | ||
|
||
private class ThrowingEmailList : IList<Email> | ||
{ | ||
public Email this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
|
||
public int Count => throw new NotImplementedException(); | ||
public bool IsReadOnly => throw new NotImplementedException(); | ||
|
||
public void Add(Email item) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public bool Contains(Email item) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void CopyTo(Email[] array, int arrayIndex) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public IEnumerator<Email> GetEnumerator() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public int IndexOf(Email item) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void Insert(int index, Email item) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public bool Remove(Email item) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void RemoveAt(int index) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} | ||
} |
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