Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip(Liquid.Repository.EntityFramework): Update Liquid framework for net8.0. #236

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -11,7 +10,7 @@
/// <seealso cref="LiquidException" />
[Serializable]
[ExcludeFromCodeCoverage]
public class DatabaseDoesNotExistException : LiquidException

Check warning on line 13 in src/Liquid.Repository.EntityFramework/Exceptions/DatabaseDoesNotExistException.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Update this implementation of 'ISerializable' to conform to the recommended serialization pattern. Add a 'protected' constructor 'DatabaseDoesNotExistException(SerializationInfo, StreamingContext)'. (https://rules.sonarsource.com/csharp/RSPEC-3925)

Check warning on line 13 in src/Liquid.Repository.EntityFramework/Exceptions/DatabaseDoesNotExistException.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Update this implementation of 'ISerializable' to conform to the recommended serialization pattern. Add a 'protected' constructor 'DatabaseDoesNotExistException(SerializationInfo, StreamingContext)'. (https://rules.sonarsource.com/csharp/RSPEC-3925)

Check warning on line 13 in src/Liquid.Repository.EntityFramework/Exceptions/DatabaseDoesNotExistException.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Update this implementation of 'ISerializable' to conform to the recommended serialization pattern. Add a 'protected' constructor 'DatabaseDoesNotExistException(SerializationInfo, StreamingContext)'. (https://rules.sonarsource.com/csharp/RSPEC-3925)
{
///<inheritdoc/>
public DatabaseDoesNotExistException()
Expand All @@ -30,10 +29,5 @@
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
Loading