mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Replaces ErrorOr library with a custom implementation.
This commit is contained in:
1 parent
8fe90a4dde
commit
3b772d68ca
436 files changed
+4234
-3922
No files matched your search
+15
-15
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
@@ -45,10 +45,10 @@ public class PermissionRepositoryTests
|
||||
PermissionEntity permissionModel = _permissionEntityFixture.CreatePermissionModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
// check if the permission was added to the context's ChangeTracker
|
||||
@@ -67,10 +67,10 @@ public class PermissionRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.PermissionAlreadyExists, result.FirstError);
|
||||
Assert.Single(_mockContext.ChangeTracker.Entries<PermissionEntity>());
|
||||
}
|
||||
@@ -89,10 +89,10 @@ public class PermissionRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(3, result.Value.Count());
|
||||
Assert.Equal(permissions, result.Value);
|
||||
@@ -102,10 +102,10 @@ public class PermissionRepositoryTests
|
||||
public async Task GetAllAsync_WhenNoPermissionsExist_ShouldReturnEmptyList()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Empty(result.Value);
|
||||
}
|
||||
@@ -123,16 +123,16 @@ public class PermissionRepositoryTests
|
||||
_mockContext.Permissions.AddRange(permissions);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
List<Guid> requestedIds = permissions.Take(2).Select(p => p.Id).ToList();
|
||||
List<Guid> requestedIds = [.. permissions.Take(2).Select(p => p.Id)];
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
|
||||
Result<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(2, result.Value.Count());
|
||||
Assert.Equal(requestedIds, result.Value.Select(p => p.Id).ToList());
|
||||
Assert.Equal(requestedIds, [.. result.Value.Select(p => p.Id)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -142,10 +142,10 @@ public class PermissionRepositoryTests
|
||||
List<Guid> requestedIds = [Guid.NewGuid(), Guid.NewGuid()];
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
|
||||
Result<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Empty(result.Value);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -42,10 +42,10 @@ public class RolePermissionRepositoryTests
|
||||
RolePermissionEntity rolePermissionModel = _rolePermissionEntityFixture.CreateRolePermissionModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
// check if the role permission was added to the context's ChangeTracker
|
||||
|
||||
+31
-32
@@ -1,12 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
@@ -50,10 +49,10 @@ public class RoleRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
// Check if the role was added to the context's ChangeTracker
|
||||
@@ -86,10 +85,10 @@ public class RoleRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
|
||||
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
|
||||
}
|
||||
@@ -118,10 +117,10 @@ public class RoleRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
|
||||
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
|
||||
}
|
||||
@@ -152,10 +151,10 @@ public class RoleRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(2, result.Value.Count());
|
||||
Assert.Equal(roles, result.Value);
|
||||
@@ -165,10 +164,10 @@ public class RoleRepositoryTests
|
||||
public async Task GetAllAsync_WhenNoRolesExist_ShouldReturnEmptyList()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Empty(result.Value);
|
||||
}
|
||||
@@ -189,10 +188,10 @@ public class RoleRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("Admin", CancellationToken.None);
|
||||
Result<RoleEntity?> result = await _sut.GetByNameAsync("Admin", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(role, result.Value);
|
||||
}
|
||||
@@ -201,10 +200,10 @@ public class RoleRepositoryTests
|
||||
public async Task GetByNameAsync_WhenRoleDoesNotExist_ShouldReturnNull()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("NonExistentRole", CancellationToken.None);
|
||||
Result<RoleEntity?> result = await _sut.GetByNameAsync("NonExistentRole", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
@@ -220,10 +219,10 @@ public class RoleRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(role.Id, CancellationToken.None);
|
||||
Result<RoleEntity?> result = await _sut.GetByIdAsync(role.Id, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(role.Id, result.Value.Id);
|
||||
Assert.Equal(role.RoleName, result.Value.RoleName);
|
||||
@@ -238,10 +237,10 @@ public class RoleRepositoryTests
|
||||
Guid nonExistentId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
|
||||
Result<RoleEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
@@ -271,10 +270,10 @@ public class RoleRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
|
||||
@@ -296,10 +295,10 @@ public class RoleRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
@@ -328,10 +327,10 @@ public class RoleRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
|
||||
@@ -357,10 +356,10 @@ public class RoleRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
|
||||
Result<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
|
||||
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
|
||||
@@ -376,10 +375,10 @@ public class RoleRepositoryTests
|
||||
Guid nonExistentId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(nonExistentId, CancellationToken.None);
|
||||
Result<Deleted> result = await _sut.DeleteByIdAsync(nonExistentId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
@@ -396,10 +395,10 @@ public class RoleRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
|
||||
Result<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
|
||||
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
|
||||
|
||||
+3
-7
@@ -1,16 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -46,10 +42,10 @@ public class UserRoleRepositoryTests
|
||||
UserRoleEntity userRole = _userRoleEntityFixture.CreateUserRoleModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
EntityEntry<UserRoleEntity>? addedUserRole = _mockContext.ChangeTracker.Entries<UserRoleEntity>()
|
||||
|
||||
+30
-30
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.DataAccess.Core.Repositories.Books;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
@@ -47,10 +47,10 @@ public class BookRepositoryTests
|
||||
BookEntity bookModel = _bookEntityFixture.CreateBookModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
// check if the book was added to the context's ChangeTracker
|
||||
@@ -69,10 +69,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.WrittenContent.BookAlreadyExists, result.FirstError);
|
||||
Assert.Single(_mockContext.ChangeTracker.Entries<BookEntity>()); // only the existing book should be in the context
|
||||
}
|
||||
@@ -89,10 +89,10 @@ public class BookRepositoryTests
|
||||
bookModel.Tags = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
|
||||
@@ -116,10 +116,10 @@ public class BookRepositoryTests
|
||||
bookModel.Genres = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
|
||||
@@ -145,10 +145,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(3, result.Value.Count());
|
||||
Assert.Equal(books, result.Value);
|
||||
@@ -158,10 +158,10 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenNoBooksExist_ShouldReturnEmptyList()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Empty(result.Value);
|
||||
}
|
||||
@@ -178,10 +178,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Single(result.Value);
|
||||
BookEntity retrievedBook = result.Value.First();
|
||||
@@ -203,10 +203,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
|
||||
Result<IEnumerable<BookEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
BookEntity retrievedBook = Assert.Single(result.Value);
|
||||
Assert.Equal(bookOfLibrary.Id, retrievedBook.Id);
|
||||
}
|
||||
@@ -220,10 +220,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, book.Path, CancellationToken.None);
|
||||
Result<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, book.Path, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(book.Id, result.Value!.Id);
|
||||
}
|
||||
|
||||
@@ -236,10 +236,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, "/books/non-existent.epub", CancellationToken.None);
|
||||
Result<BookEntity?> result = await _sut.GetByPathAsync(book.LibraryId, "/books/non-existent.epub", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
@@ -267,10 +267,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, null, 10, CancellationToken.None);
|
||||
Result<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, null, 10, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(2, result.Value.Count);
|
||||
Assert.Contains(result.Value, book => book.Id == pendingBook.Id);
|
||||
Assert.Contains(result.Value, book => book.Id == failedBook.Id);
|
||||
@@ -291,10 +291,10 @@ public class BookRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, firstBook.Path, 10, CancellationToken.None);
|
||||
Result<IReadOnlyList<BookEntity>> result = await _sut.GetBooksNeedingMetadataAsync(libraryId, firstBook.Path, 10, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
BookEntity retrievedBook = Assert.Single(result.Value);
|
||||
Assert.Equal(secondBook.Id, retrievedBook.Id);
|
||||
}
|
||||
@@ -310,10 +310,10 @@ public class BookRepositoryTests
|
||||
book.Title = "Updated Title";
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
BookEntity? retrievedBook = await _mockContext.Books.FindAsync(book.Id);
|
||||
Assert.Equal("Updated Title", retrievedBook!.Title);
|
||||
@@ -326,10 +326,10 @@ public class BookRepositoryTests
|
||||
BookEntity book = _bookEntityFixture.CreateBookModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.WrittenContent.BookNotFound, result.FirstError);
|
||||
}
|
||||
}
|
||||
+9
-10
@@ -1,11 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.DataAccess.Core.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -44,10 +43,10 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<System.Collections.Generic.IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
|
||||
Result<System.Collections.Generic.IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> result = await _sut.GetByLibraryIdAsync(libraryId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
LibraryMetadataProviderConfigurationEntity retrievedConfiguration = Assert.Single(result.Value);
|
||||
Assert.Equal(configurationOfLibrary.PluginId, retrievedConfiguration.PluginId);
|
||||
}
|
||||
@@ -61,10 +60,10 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<LibraryMetadataProviderConfigurationEntity?> result = await _sut.GetByLibraryAndPluginIdAsync(configuration.LibraryId, configuration.PluginId, CancellationToken.None);
|
||||
Result<LibraryMetadataProviderConfigurationEntity?> result = await _sut.GetByLibraryAndPluginIdAsync(configuration.LibraryId, configuration.PluginId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(configuration.Id, result.Value!.Id);
|
||||
}
|
||||
|
||||
@@ -75,11 +74,11 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpsertAsync(configuration, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpsertAsync(configuration, CancellationToken.None);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Single(_mockContext.LibraryMetadataProviderConfigurations);
|
||||
}
|
||||
|
||||
@@ -95,11 +94,11 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
updatedConfiguration.IsEnabled = true;
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpsertAsync(updatedConfiguration, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpsertAsync(updatedConfiguration, CancellationToken.None);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
LibraryMetadataProviderConfigurationEntity retrievedConfiguration = _mockContext.LibraryMetadataProviderConfigurations.Single();
|
||||
Assert.Equal(5, retrievedConfiguration.Rank);
|
||||
Assert.True(retrievedConfiguration.IsEnabled);
|
||||
|
||||
+12
-13
@@ -1,12 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.DataAccess.Core.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -43,10 +42,10 @@ public class PluginRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<PluginEntity?> result = await _sut.GetByIdAsync(plugin.Id, CancellationToken.None);
|
||||
Result<PluginEntity?> result = await _sut.GetByIdAsync(plugin.Id, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(plugin.Id, result.Value!.Id);
|
||||
}
|
||||
|
||||
@@ -57,11 +56,11 @@ public class PluginRepositoryTests
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpsertAsync(plugin, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpsertAsync(plugin, CancellationToken.None);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Single(_mockContext.Plugins);
|
||||
}
|
||||
|
||||
@@ -79,11 +78,11 @@ public class PluginRepositoryTests
|
||||
updatedPlugin.SettingsJson = null; // the stored settings must be preserved
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpsertAsync(updatedPlugin, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpsertAsync(updatedPlugin, CancellationToken.None);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
PluginEntity retrievedPlugin = _mockContext.Plugins.Single();
|
||||
Assert.Equal("Updated Name", retrievedPlugin.Name);
|
||||
Assert.Equal("""{"preferredLanguage":"en"}""", retrievedPlugin.SettingsJson);
|
||||
@@ -98,11 +97,11 @@ public class PluginRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateSettingsAsync(plugin.Id, """{"preferredLanguage":"fr"}""", CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateSettingsAsync(plugin.Id, """{"preferredLanguage":"fr"}""", CancellationToken.None);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("""{"preferredLanguage":"fr"}""", _mockContext.Plugins.Single().SettingsJson);
|
||||
}
|
||||
|
||||
@@ -110,10 +109,10 @@ public class PluginRepositoryTests
|
||||
public async Task UpdateSettingsAsync_WhenPluginDoesNotExist_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateSettingsAsync(Guid.NewGuid(), null, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateSettingsAsync(Guid.NewGuid(), null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Plugins.PluginNotFound, result.FirstError);
|
||||
}
|
||||
}
|
||||
+30
-30
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.DataAccess.Core.Repositories.Users;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
@@ -49,10 +49,10 @@ public class UserRepositoryTests
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
EntityEntry<UserEntity>? addedUser = _mockContext.ChangeTracker.Entries<UserEntity>()
|
||||
@@ -70,10 +70,10 @@ public class UserRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
|
||||
Result<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Users.UserAlreadyExists, result.FirstError);
|
||||
Assert.Single(_mockContext.ChangeTracker.Entries<UserEntity>());
|
||||
}
|
||||
@@ -92,10 +92,10 @@ public class UserRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(3, result.Value.Count());
|
||||
Assert.Equal(users, result.Value);
|
||||
@@ -105,10 +105,10 @@ public class UserRepositoryTests
|
||||
public async Task GetAllAsync_WhenNoUsersExist_ShouldReturnEmptyList()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
Result<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Empty(result.Value);
|
||||
}
|
||||
@@ -122,10 +122,10 @@ public class UserRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync(userModel.Username, CancellationToken.None);
|
||||
Result<UserEntity?> result = await _sut.GetByUsernameAsync(userModel.Username, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(userModel, result.Value);
|
||||
}
|
||||
@@ -134,10 +134,10 @@ public class UserRepositoryTests
|
||||
public async Task GetByUsernameAsync_WhenUserDoesNotExist_ShouldReturnNull()
|
||||
{
|
||||
// Act
|
||||
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync("nonexistent", CancellationToken.None);
|
||||
Result<UserEntity?> result = await _sut.GetByUsernameAsync("nonexistent", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
@@ -166,10 +166,10 @@ public class UserRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
UserEntity? modifiedUser = await _mockContext.Users.FirstOrDefaultAsync(u => u.Username == existingUser.Username);
|
||||
@@ -186,10 +186,10 @@ public class UserRepositoryTests
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
|
||||
}
|
||||
|
||||
@@ -202,10 +202,10 @@ public class UserRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(userModel.Id, CancellationToken.None);
|
||||
Result<UserEntity?> result = await _sut.GetByIdAsync(userModel.Id, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(userModel.Id, result.Value.Id);
|
||||
Assert.Equal(userModel.Username, result.Value.Username);
|
||||
@@ -222,10 +222,10 @@ public class UserRepositoryTests
|
||||
Guid nonExistentId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
|
||||
Result<UserEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
@@ -268,10 +268,10 @@ public class UserRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
UserEntity? modifiedUser = await _mockContext.Users
|
||||
@@ -333,10 +333,10 @@ public class UserRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
EntityEntry<UserPermissionEntity>? removedPermission = _mockContext.ChangeTracker
|
||||
@@ -436,10 +436,10 @@ public class UserRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
|
||||
@@ -496,10 +496,10 @@ public class UserRepositoryTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
|
||||
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
@@ -9,6 +8,7 @@ using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.DataAccess.Core.Seed;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -58,10 +58,10 @@ public class DataSeedServiceTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
await _mockPermissionRepository
|
||||
@@ -86,10 +86,10 @@ public class DataSeedServiceTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -132,10 +132,10 @@ public class DataSeedServiceTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
await mockRoleRepository
|
||||
@@ -164,10 +164,10 @@ public class DataSeedServiceTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -247,10 +247,10 @@ public class DataSeedServiceTests
|
||||
mockRolePermissionRepository.InsertAsync(Arg.Any<RolePermissionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
await mockRolePermissionRepository
|
||||
@@ -278,10 +278,10 @@ public class DataSeedServiceTests
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.AdminAccountNotFound, result.FirstError);
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -304,10 +304,10 @@ public class DataSeedServiceTests
|
||||
mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -335,10 +335,10 @@ public class DataSeedServiceTests
|
||||
mockRolePermissionRepository.InsertAsync(Arg.Any<RolePermissionEntity>(), Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -359,10 +359,10 @@ public class DataSeedServiceTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -392,10 +392,10 @@ public class DataSeedServiceTests
|
||||
mockUserRoleRepository.InsertAsync(Arg.Any<UserRoleEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
|
||||
await mockUserRoleRepository
|
||||
@@ -424,10 +424,10 @@ public class DataSeedServiceTests
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.AdminRoleNotFound, result.FirstError);
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -449,10 +449,10 @@ public class DataSeedServiceTests
|
||||
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.AdminAccountNotFound, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -481,10 +481,10 @@ public class DataSeedServiceTests
|
||||
mockUserRoleRepository.InsertAsync(Arg.Any<UserRoleEntity>(), Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -505,10 +505,10 @@ public class DataSeedServiceTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -532,10 +532,10 @@ public class DataSeedServiceTests
|
||||
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
|
||||
Reference in new issue
Block a user