Skip to content

Commit

Permalink
wip(Liquid.Repository.EntityFramework): Update Liquid framework for n…
Browse files Browse the repository at this point in the history
…et8.
  • Loading branch information
lucianareginalino committed Jun 18, 2024
1 parent 00ba329 commit 0adc61b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Liquid.Core.Exceptions;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace Liquid.Repository.EntityFramework.Exceptions
{
Expand Down Expand Up @@ -30,10 +29,5 @@ public DatabaseDoesNotExistException()
public DatabaseDoesNotExistException(string message, Exception innerException) : base(message, innerException)
{
}

///<inheritdoc/>
protected DatabaseDoesNotExistException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageId>Liquid.Repository.EntityFramework</PackageId>
<Version>6.0.0</Version>
<Version>8.0.0-alpha-01</Version>
<Authors>Avanade Brazil</Authors>
<Company>Avanade Inc.</Company>
<Product>Liquid - Modern Application Framework</Product>
Expand All @@ -18,7 +18,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.31" />
<PackageReference Include="Liquid.Core" Version="8.0.0-alpha-04" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
</ItemGroup>

<ItemGroup>
Expand All @@ -27,9 +28,4 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Liquid.Core\Liquid.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using NSubstitute;
using NUnit.Framework;

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Xunit;

namespace Liquid.Repository.EntityFramework.Tests
{
Expand All @@ -15,8 +16,8 @@ public class EntityFrameworkDataContextTests
private DbContext _client;
private DatabaseFacade _database;

[SetUp]
protected void SetContext()

public EntityFrameworkDataContextTests()
{

_client = Substitute.For<DbContext>();
Expand All @@ -28,61 +29,61 @@ protected void SetContext()
_sut = new EntityFrameworkDataContext<DbContext>(_client);
}

[Test]
[Fact]
public async Task StartTransactionAsync_WhenClientExecutedSucessfuly_Success()
{
await _sut.StartTransactionAsync();

await _client.Database.Received(1).BeginTransactionAsync();
}

[Test]
public void StartTransactionAsync_WhenClientThrow_ThrowException()
[Fact]
public async Task StartTransactionAsync_WhenClientThrow_ThrowException()
{
_database.When(o => o.BeginTransactionAsync()).Do((call) => throw new Exception());

var task = _sut.StartTransactionAsync();

Assert.ThrowsAsync<Exception>(() => task);
await Assert.ThrowsAsync<Exception>(() => task);
}

[Test]
[Fact]
public async Task CommitAsync_WhenClientExecutedSucessfuly_Success()
{
await _sut.CommitAsync();

await _client.Database.Received(1).CommitTransactionAsync();
}

[Test]
public void CommitAsync_WhenClientExcept_ThrowException()
[Fact]
public async Task CommitAsync_WhenClientExcept_ThrowException()
{
_database.When(o => o.CommitTransactionAsync()).Do((call) => throw new Exception());

var task = _sut.CommitAsync();

Assert.ThrowsAsync<Exception>(() => task);
await Assert.ThrowsAsync<Exception>(() => task);
}

[Test]
[Fact]
public async Task RollbackTransactionAsync_WhenClientExecutedSucessfuly_Success()
{
await _sut.RollbackTransactionAsync();

await _client.Database.Received(1).RollbackTransactionAsync();
}

[Test]
public void RollbackTransactionAsync_WhenClientExcept_ThrowException()
[Fact]
public async Task RollbackTransactionAsync_WhenClientExcept_ThrowException()
{
_database.When(o => o.RollbackTransactionAsync()).Do((call) => throw new Exception());

var task = _sut.RollbackTransactionAsync();

Assert.ThrowsAsync<Exception>(() => task);
await Assert.ThrowsAsync<Exception>(() => task);
}

[Test]
[Fact]
public void Verify_Dispose()
{
_sut.Dispose();
Expand All @@ -93,31 +94,31 @@ public void Verify_Dispose()
_sut.Dispose();
}

[Test]
[Fact]
public void Verify_Dispose_Except()
{
_client.When(o => o.Dispose()).Do((call) => throw new Exception());

Assert.Throws<Exception>(() => _sut.Dispose());
}

[Test]
[Fact]
public void EntityFrameworkDataContext_WhenCreated_DbContextIsValid()
{
Assert.IsNotNull(_sut.DbClient);
Assert.IsInstanceOf<DbContext>(_sut.DbClient);
Assert.NotNull(_sut.DbClient);
Assert.IsAssignableFrom<DbContext>(_sut.DbClient);
}

[Test]
[Fact]
public void EntityFrameworkDataContext_WhenCreatedWithoutDbContext_ThrowException()
{
Assert.Throws<ArgumentNullException>(() => new EntityFrameworkDataContext<DbContext>(null));
}

[Test]
[Fact]
public void EntityFrameworkDataContext_IdIsAlwaysNull()
{
Assert.IsNull(_sut.Id);
Assert.Null(_sut.Id);
}
}
}
Loading

0 comments on commit 0adc61b

Please sign in to comment.