Removes FluentAssertions library from test projects, due to licensing changes

This commit is contained in:
BinaryAlley committed 2025-02-03 00:31:15 +02:00
1 parent c1100e5398
commit d46bfae4fc
235 files changed
+4468 -4725

No files matched your search

@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
@@ -49,13 +48,13 @@ public class PermissionRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// Check if the permission was added to the context's ChangeTracker
// check if the permission was added to the context's ChangeTracker
EntityEntry<PermissionEntity>? addedPermission = _mockContext.ChangeTracker.Entries<PermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == permissionModel.Id);
addedPermission.Should().NotBeNull();
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == permissionModel.Id);
Assert.NotNull(addedPermission);
}
[Fact]
@@ -71,9 +70,9 @@ public class PermissionRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.PermissionAlreadyExists);
_mockContext.ChangeTracker.Entries<PermissionEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.PermissionAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<PermissionEntity>());
}
[Fact]
@@ -93,10 +92,10 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(3);
result.Value.Should().BeEquivalentTo(permissions);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(permissions, result.Value);
}
[Fact]
@@ -106,9 +105,9 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -130,10 +129,10 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(2);
result.Value.Select(p => p.Id).Should().BeEquivalentTo(requestedIds);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(2, result.Value.Count());
Assert.Equal(requestedIds, result.Value.Select(p => p.Id).ToList());
}
[Fact]
@@ -146,8 +145,8 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.UoW;
@@ -46,12 +45,12 @@ public class RolePermissionRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// check if the role permission was added to the context's ChangeTracker
EntityEntry<RolePermissionEntity>? addedRolePermission = _mockContext.ChangeTracker.Entries<RolePermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == rolePermissionModel.Id);
addedRolePermission.Should().NotBeNull();
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == rolePermissionModel.Id);
Assert.NotNull(addedRolePermission);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
@@ -54,13 +53,13 @@ public class RoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// Check if the role was added to the context's ChangeTracker
EntityEntry<RoleEntity>? addedRole = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == role.Id);
addedRole.Should().NotBeNull();
Assert.NotNull(addedRole);
}
[Fact]
@@ -90,9 +89,9 @@ public class RoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleAlreadyExists);
_mockContext.ChangeTracker.Entries<RoleEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
}
[Fact]
@@ -122,9 +121,9 @@ public class RoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleAlreadyExists);
_mockContext.ChangeTracker.Entries<RoleEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
}
[Fact]
@@ -156,10 +155,10 @@ public class RoleRepositoryTests
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(2);
result.Value.Should().BeEquivalentTo(roles);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(2, result.Value.Count());
Assert.Equal(roles, result.Value);
}
[Fact]
@@ -169,9 +168,9 @@ public class RoleRepositoryTests
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -193,9 +192,9 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("Admin", CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(role);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(role, result.Value);
}
[Fact]
@@ -205,8 +204,8 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("NonExistentRole", CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -224,13 +223,12 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(role.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(role, options => options
.Including(x => x.Id)
.Including(x => x.RoleName)
.Including(x => x.CreatedOnUtc)
.Including(x => x.CreatedBy));
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(role.Id, result.Value.Id);
Assert.Equal(role.RoleName, result.Value.RoleName);
Assert.Equal(role.CreatedOnUtc, result.Value.CreatedOnUtc);
Assert.Equal(role.CreatedBy, result.Value.CreatedBy);
}
[Fact]
@@ -243,8 +241,8 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -276,13 +274,13 @@ public class RoleRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
updatedEntry.Should().NotBeNull();
updatedEntry!.Entity.RoleName.Should().Be("SuperAdmin");
Assert.NotNull(updatedEntry);
Assert.Equal("SuperAdmin", updatedEntry!.Entity.RoleName);
}
[Fact]
@@ -301,8 +299,8 @@ public class RoleRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -333,14 +331,14 @@ public class RoleRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
updatedEntry.Should().NotBeNull();
updatedEntry!.Entity.RolePermissions.Should().HaveCount(1);
updatedEntry.Entity.RolePermissions.First().Should().BeEquivalentTo(newRolePermission);
Assert.NotNull(updatedEntry);
Assert.Single(updatedEntry!.Entity.RolePermissions);
Assert.Equal(newRolePermission, updatedEntry.Entity.RolePermissions.First());
}
[Fact]
@@ -362,13 +360,13 @@ public class RoleRepositoryTests
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Deleted);
Assert.False(result.IsError);
Assert.Equal(Result.Deleted, result.Value);
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
deletedEntry.Should().NotBeNull();
deletedEntry!.State.Should().Be(EntityState.Deleted);
Assert.NotNull(deletedEntry);
Assert.Equal(EntityState.Deleted, deletedEntry!.State);
}
[Fact]
@@ -381,8 +379,8 @@ public class RoleRepositoryTests
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(nonExistentId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -401,12 +399,12 @@ public class RoleRepositoryTests
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Deleted);
Assert.False(result.IsError);
Assert.Equal(Result.Deleted, result.Value);
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
deletedEntry.Should().NotBeNull();
deletedEntry!.State.Should().Be(EntityState.Deleted);
Assert.NotNull(deletedEntry);
Assert.Equal(EntityState.Deleted, deletedEntry!.State);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
@@ -50,12 +49,12 @@ public class UserRoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<UserRoleEntity>? addedUserRole = _mockContext.ChangeTracker.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == userRole.Id);
addedUserRole.Should().NotBeNull();
addedUserRole!.State.Should().Be(EntityState.Added);
Assert.NotNull(addedUserRole);
Assert.Equal(EntityState.Added, addedUserRole!.State);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.DataAccess.Core.Repositories.Books;
@@ -50,13 +49,13 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// Check if the book was added to the context's ChangeTracker
// check if the book was added to the context's ChangeTracker
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
addedBook.Should().NotBeNull();
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
Assert.NotNull(addedBook);
}
[Fact]
@@ -72,9 +71,9 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.WrittenContent.BookAlreadyExists);
_mockContext.ChangeTracker.Entries<BookEntity>().Should().HaveCount(1); // Only the existing book should be in the context}
Assert.True(result.IsError);
Assert.Equal(Errors.WrittenContent.BookAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<BookEntity>()); // only the existing book should be in the context
}
[Fact]
@@ -92,16 +91,16 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
addedBook.Should().NotBeNull();
Assert.NotNull(addedBook);
BookEntity addedBookEntity = addedBook!.Entity;
addedBookEntity.Tags.Should().HaveCount(2);
addedBookEntity.Tags.Should().Contain(t => t.Name == "Existing" && t == existingTag);
addedBookEntity.Tags.Should().Contain(t => t.Name == "New" && t != existingTag);
Assert.Equal(2, addedBookEntity.Tags.Count);
Assert.Contains(addedBookEntity.Tags, t => t.Name == "Existing" && t == existingTag);
Assert.Contains(addedBookEntity.Tags, t => t.Name == "New" && t != existingTag);
}
[Fact]
@@ -119,16 +118,16 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
addedBook.Should().NotBeNull();
Assert.NotNull(addedBook);
BookEntity addedBookEntity = addedBook!.Entity;
addedBookEntity.Genres.Should().HaveCount(2);
addedBookEntity.Genres.Should().Contain(g => g.Name == "Existing" && g == existingGenre);
addedBookEntity.Genres.Should().Contain(g => g.Name == "New" && g != existingGenre);
Assert.Equal(2, addedBookEntity.Genres.Count);
Assert.Contains(addedBookEntity.Genres, g => g.Name == "Existing" && g == existingGenre);
Assert.Contains(addedBookEntity.Genres, g => g.Name == "New" && g != existingGenre);
}
[Fact]
@@ -148,10 +147,10 @@ public class BookRepositoryTests
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(3);
result.Value.Should().BeEquivalentTo(books);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(books, result.Value);
}
[Fact]
@@ -161,9 +160,9 @@ public class BookRepositoryTests
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -181,12 +180,12 @@ public class BookRepositoryTests
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(1);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Single(result.Value);
BookEntity retrievedBook = result.Value.First();
retrievedBook.Tags.Should().HaveCount(2);
retrievedBook.Genres.Should().HaveCount(2);
retrievedBook.ISBNs.Should().HaveCount(2);
Assert.Equal(2, retrievedBook.Tags.Count);
Assert.Equal(2, retrievedBook.Genres.Count);
Assert.Equal(2, retrievedBook.ISBNs.Count);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.DataAccess.Core.Repositories.Books;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
@@ -38,7 +37,7 @@ public class RepositoryDictionaryTests
repositoryDictionary.Add<IBookRepository>(bookRepository);
// Assert
repositoryDictionary.Count.Should().Be(1);
Assert.Equal(1, repositoryDictionary.Count);
}
[Fact]
@@ -53,7 +52,7 @@ public class RepositoryDictionaryTests
repositoryDictionary.Clear();
// Assert
repositoryDictionary.Count.Should().Be(0);
Assert.Equal(0, repositoryDictionary.Count);
}
[Fact]
@@ -68,7 +67,7 @@ public class RepositoryDictionaryTests
IBookRepository actual = repositoryDictionary.Get<IBookRepository>(typeof(BookRepository));
// Assert
actual.Should().BeSameAs(expected);
Assert.Same(expected, actual);
}
[Fact]
@@ -78,8 +77,7 @@ public class RepositoryDictionaryTests
RepositoryDictionary repositoryDictionary = new();
// Act & Assert
Action act = () => repositoryDictionary.Add<IBookRepository>(null!);
act.Should().Throw<ArgumentException>().WithMessage("Value cannot be null!");
Assert.Throws<ArgumentException>(() => repositoryDictionary.Add<IBookRepository>(null!));
}
[Fact]
@@ -91,8 +89,8 @@ public class RepositoryDictionaryTests
repositoryDictionary.Add<IBookRepository>(bookRepository);
// Act & Assert
Action act = () => repositoryDictionary.Add<IBookRepository>(bookRepository);
act.Should().Throw<ArgumentException>().WithMessage("Duplicate values are not allowed!");
ArgumentException exception = Assert.Throws<ArgumentException>(() => repositoryDictionary.Add<IBookRepository>(bookRepository));
Assert.Equal("Duplicate values are not allowed!", exception.Message);
}
[Fact]
@@ -103,7 +101,7 @@ public class RepositoryDictionaryTests
RepositoryDictionary repositoryDictionary = new();
// Act & Assert
Action act = () => repositoryDictionary.Add(nonRepository);
act.Should().Throw<ArgumentException>().WithMessage("Value must implement IRepository interface!");
ArgumentException exception = Assert.Throws<ArgumentException>(() => repositoryDictionary.Add(nonRepository));
Assert.Equal("Value must implement IRepository interface!", exception.Message);
}
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Time;
@@ -36,8 +35,8 @@ public class RepositoryFactoryTests
IBookRepository result = repositoryFactory.CreateRepository<IBookRepository>();
// Assert
result.Should().NotBeNull();
result.Should().BeAssignableTo<IBookRepository>();
Assert.NotNull(result);
Assert.IsAssignableFrom<IBookRepository>(result);
}
[Fact]
@@ -50,7 +49,10 @@ public class RepositoryFactoryTests
RepositoryFactory repositoryFactory = new(serviceProvider);
// Act & Assert
Action act = () => repositoryFactory.CreateRepository<IUnregisteredRepository>();
act.Should().Throw<InvalidOperationException>().WithMessage("No service for type 'Lumina.DataAccess.UnitTests.Core.Repositories.Common.Factory.Fixtures.IUnregisteredRepository' has been registered.");
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(
() => repositoryFactory.CreateRepository<IUnregisteredRepository>());
Assert.Equal(
"No service for type 'Lumina.DataAccess.UnitTests.Core.Repositories.Common.Factory.Fixtures.IUnregisteredRepository' has been registered.",
exception.Message);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.DataAccess.Core.Repositories.Users;
@@ -53,12 +52,12 @@ public class UserRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<UserEntity>? addedUser = _mockContext.ChangeTracker.Entries<UserEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == userModel.Id);
addedUser.Should().NotBeNull();
Assert.NotNull(addedUser);
}
[Fact]
@@ -74,9 +73,9 @@ public class UserRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Users.UserAlreadyExists);
_mockContext.ChangeTracker.Entries<UserEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Users.UserAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<UserEntity>());
}
[Fact]
@@ -96,10 +95,10 @@ public class UserRepositoryTests
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(3);
result.Value.Should().BeEquivalentTo(users);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(users, result.Value);
}
[Fact]
@@ -109,9 +108,9 @@ public class UserRepositoryTests
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -126,9 +125,9 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync(userModel.Username, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(userModel);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(userModel, result.Value);
}
[Fact]
@@ -138,8 +137,8 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync("nonexistent", CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -170,14 +169,14 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
UserEntity? modifiedUser = await _mockContext.Users.FirstOrDefaultAsync(u => u.Username == existingUser.Username);
modifiedUser.Should().NotBeNull();
modifiedUser!.Password.Should().Be(updatedUser.Password);
modifiedUser.TempPassword.Should().Be(updatedUser.TempPassword);
modifiedUser.TotpSecret.Should().Be(updatedUser.TotpSecret);
Assert.NotNull(modifiedUser);
Assert.Equal(updatedUser.Password, modifiedUser.Password);
Assert.Equal(updatedUser.TempPassword, modifiedUser.TempPassword);
Assert.Equal(updatedUser.TotpSecret, modifiedUser.TotpSecret);
}
[Fact]
@@ -190,8 +189,8 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Users.UserDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
}
[Fact]
@@ -206,15 +205,14 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(userModel.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(userModel, options => options
.Including(x => x.Id)
.Including(x => x.Username)
.Including(x => x.Password)
.Including(x => x.Libraries)
.Including(x => x.UserPermissions)
.Including(x => x.UserRole));
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(userModel.Id, result.Value.Id);
Assert.Equal(userModel.Username, result.Value.Username);
Assert.Equal(userModel.Password, result.Value.Password);
Assert.Equal(userModel.Libraries, result.Value.Libraries);
Assert.Equal(userModel.UserPermissions, result.Value.UserPermissions);
Assert.Equal(userModel.UserRole, result.Value.UserRole);
}
[Fact]
@@ -227,8 +225,8 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -273,16 +271,16 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
UserEntity? modifiedUser = await _mockContext.Users
.Include(u => u.UserPermissions)
.ThenInclude(up => up.Permission)
.FirstOrDefaultAsync(u => u.Username == existingUser.Username);
modifiedUser.Should().NotBeNull();
modifiedUser!.UserPermissions.Should().HaveCount(1);
modifiedUser.UserPermissions.First().Permission.PermissionName.Should().Be(newPermission.PermissionName);
Assert.NotNull(modifiedUser);
Assert.Single(modifiedUser.UserPermissions);
Assert.Equal(newPermission.PermissionName, modifiedUser.UserPermissions.First().Permission.PermissionName);
}
[Fact]
@@ -338,20 +336,20 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserPermissionEntity>? removedPermission = _mockContext.ChangeTracker
.Entries<UserPermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Deleted);
removedPermission.Should().NotBeNull();
removedPermission!.Entity.PermissionId.Should().Be(oldPermission.Id);
Assert.NotNull(removedPermission);
Assert.Equal(oldPermission.Id, removedPermission.Entity.PermissionId);
EntityEntry<UserPermissionEntity>? addedPermission = _mockContext.ChangeTracker
.Entries<UserPermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Added);
addedPermission.Should().NotBeNull();
addedPermission!.Entity.PermissionId.Should().Be(newPermission.Id);
Assert.NotNull(addedPermission);
Assert.Equal(newPermission.Id, addedPermission.Entity.PermissionId);
}
[Fact]
@@ -441,22 +439,22 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Deleted);
removedRole.Should().NotBeNull();
removedRole!.Entity.RoleId.Should().Be(oldRole.Id);
Assert.NotNull(removedRole);
Assert.Equal(oldRole.Id, removedRole.Entity.RoleId);
EntityEntry<UserRoleEntity>? addedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added);
addedRole.Should().NotBeNull();
addedRole!.Entity.UserId.Should().Be(existingUser.Id);
addedRole.Entity.RoleId.Should().Be(newRole.Id);
addedRole.Entity.Role.Should().Be(newRole);
Assert.NotNull(addedRole);
Assert.Equal(existingUser.Id, addedRole.Entity.UserId);
Assert.Equal(newRole.Id, addedRole.Entity.RoleId);
Assert.Equal(newRole, addedRole.Entity.Role);
}
[Fact]
@@ -501,18 +499,18 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Deleted);
removedRole.Should().NotBeNull();
removedRole!.Entity.Should().Be(oldUserRole);
Assert.NotNull(removedRole);
Assert.Equal(oldUserRole, removedRole.Entity);
EntityEntry<UserRoleEntity>? addedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added);
addedRole.Should().BeNull();
Assert.Null(addedRole);
}
}