mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
[PM-3555] Remove ClearTracker()
(#3213)
* Remove ClearTracker * Remove from CipherRepositoryTests
This commit is contained in:
parent
b2af73f00f
commit
79648b311e
@ -15,8 +15,7 @@ public class AuthRequestRepositoryTests
|
||||
[DatabaseTheory, DatabaseData]
|
||||
public async Task DeleteExpiredAsync_Works(
|
||||
IAuthRequestRepository authRequestRepository,
|
||||
IUserRepository userRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
IUserRepository userRepository)
|
||||
{
|
||||
var user = await userRepository.CreateAsync(new User
|
||||
{
|
||||
@ -54,8 +53,6 @@ public class AuthRequestRepositoryTests
|
||||
var notExpiredApprovedAdminApprovalRequest = await authRequestRepository.CreateAsync(
|
||||
CreateAuthRequest(user.Id, AuthRequestType.AdminApproval, DateTime.UtcNow.AddDays(7), true, DateTime.UtcNow.AddHours(11)));
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
var numberOfDeleted = await authRequestRepository.DeleteExpiredAsync(_userRequestExpiration, _adminRequestExpiration, _afterAdminApprovalExpiration);
|
||||
|
||||
// Ensure all the AuthRequests that should have been deleted, have been deleted.
|
||||
|
@ -10,8 +10,7 @@ public class EmergencyAccessRepositoriesTests
|
||||
{
|
||||
[DatabaseTheory, DatabaseData]
|
||||
public async Task DeleteAsync_UpdatesRevisionDate(IUserRepository userRepository,
|
||||
IEmergencyAccessRepository emergencyAccessRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
IEmergencyAccessRepository emergencyAccessRepository)
|
||||
{
|
||||
var grantorUser = await userRepository.CreateAsync(new User
|
||||
{
|
||||
@ -36,8 +35,6 @@ public class EmergencyAccessRepositoriesTests
|
||||
Status = EmergencyAccessStatusType.Confirmed,
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
await emergencyAccessRepository.DeleteAsync(emergencyAccess);
|
||||
|
||||
var updatedGrantee = await userRepository.GetByIdAsync(granteeUser.Id);
|
||||
|
@ -3,7 +3,6 @@ using Bit.Core.Enums;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Infrastructure.Dapper;
|
||||
using Bit.Infrastructure.EntityFramework;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -65,7 +64,7 @@ public class DatabaseDataAttribute : DataAttribute
|
||||
};
|
||||
dapperSqlServerCollection.AddSingleton(globalSettings);
|
||||
dapperSqlServerCollection.AddSingleton<IGlobalSettings>(globalSettings);
|
||||
dapperSqlServerCollection.AddSingleton<ITestDatabaseHelper>(_ => new DapperSqlServerTestDatabaseHelper(database));
|
||||
dapperSqlServerCollection.AddSingleton(database);
|
||||
dapperSqlServerCollection.AddDataProtection();
|
||||
yield return dapperSqlServerCollection.BuildServiceProvider();
|
||||
}
|
||||
@ -75,7 +74,7 @@ public class DatabaseDataAttribute : DataAttribute
|
||||
efCollection.AddLogging(configureLogging);
|
||||
efCollection.SetupEntityFramework(database.ConnectionString, database.Type);
|
||||
efCollection.AddPasswordManagerEFRepositories(SelfHosted);
|
||||
efCollection.AddTransient<ITestDatabaseHelper>(sp => new EfTestDatabaseHelper(sp.GetRequiredService<DatabaseContext>(), database));
|
||||
efCollection.AddSingleton(database);
|
||||
efCollection.AddDataProtection();
|
||||
yield return efCollection.BuildServiceProvider();
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ public class OrganizationUserRepositoryTests
|
||||
[DatabaseTheory, DatabaseData]
|
||||
public async Task DeleteAsync_Works(IUserRepository userRepository,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
IOrganizationUserRepository organizationUserRepository)
|
||||
{
|
||||
var user = await userRepository.CreateAsync(new User
|
||||
{
|
||||
@ -35,8 +34,6 @@ public class OrganizationUserRepositoryTests
|
||||
Status = OrganizationUserStatusType.Confirmed,
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
await organizationUserRepository.DeleteAsync(orgUser);
|
||||
|
||||
var newUser = await userRepository.GetByIdAsync(user.Id);
|
||||
@ -46,8 +43,7 @@ public class OrganizationUserRepositoryTests
|
||||
[DatabaseTheory, DatabaseData]
|
||||
public async Task DeleteManyAsync_Works(IUserRepository userRepository,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
IOrganizationUserRepository organizationUserRepository)
|
||||
{
|
||||
var user1 = await userRepository.CreateAsync(new User
|
||||
{
|
||||
@ -86,8 +82,6 @@ public class OrganizationUserRepositoryTests
|
||||
Status = OrganizationUserStatusType.Confirmed,
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
await organizationUserRepository.DeleteManyAsync(new List<Guid>
|
||||
{
|
||||
orgUser1.Id,
|
||||
|
@ -1,42 +0,0 @@
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.IntegrationTest;
|
||||
|
||||
public interface ITestDatabaseHelper
|
||||
{
|
||||
Database Info { get; }
|
||||
void ClearTracker();
|
||||
}
|
||||
|
||||
public class EfTestDatabaseHelper : ITestDatabaseHelper
|
||||
{
|
||||
private readonly DatabaseContext _databaseContext;
|
||||
|
||||
public EfTestDatabaseHelper(DatabaseContext databaseContext, Database database)
|
||||
{
|
||||
_databaseContext = databaseContext;
|
||||
Info = database;
|
||||
}
|
||||
|
||||
public Database Info { get; }
|
||||
|
||||
public void ClearTracker()
|
||||
{
|
||||
_databaseContext.ChangeTracker.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class DapperSqlServerTestDatabaseHelper : ITestDatabaseHelper
|
||||
{
|
||||
public DapperSqlServerTestDatabaseHelper(Database database)
|
||||
{
|
||||
Info = database;
|
||||
}
|
||||
|
||||
public Database Info { get; }
|
||||
|
||||
public void ClearTracker()
|
||||
{
|
||||
// There are no tracked entities in Dapper SQL Server
|
||||
}
|
||||
}
|
@ -16,8 +16,7 @@ public class CipherRepositoryTests
|
||||
[DatabaseTheory, DatabaseData]
|
||||
public async Task DeleteAsync_UpdatesUserRevisionDate(
|
||||
IUserRepository userRepository,
|
||||
ICipherRepository cipherRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
ICipherRepository cipherRepository)
|
||||
{
|
||||
var user = await userRepository.CreateAsync(new User
|
||||
{
|
||||
@ -34,8 +33,6 @@ public class CipherRepositoryTests
|
||||
Data = "", // TODO: EF does not enforce this as NOT NULL
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
await cipherRepository.DeleteAsync(cipher);
|
||||
|
||||
var deletedCipher = await cipherRepository.GetByIdAsync(cipher.Id);
|
||||
@ -52,8 +49,7 @@ public class CipherRepositoryTests
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ICollectionRepository collectionRepository,
|
||||
ICipherRepository cipherRepository,
|
||||
ICollectionCipherRepository collectionCipherRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
ICollectionCipherRepository collectionCipherRepository)
|
||||
{
|
||||
var user = await userRepository.CreateAsync(new User
|
||||
{
|
||||
@ -63,8 +59,6 @@ public class CipherRepositoryTests
|
||||
SecurityStamp = "stamp",
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
user = await userRepository.GetByIdAsync(user.Id);
|
||||
|
||||
var organization = await organizationRepository.CreateAsync(new Organization
|
||||
@ -100,8 +94,6 @@ public class CipherRepositoryTests
|
||||
},
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
await cipherRepository.CreateAsync(new CipherDetails
|
||||
@ -128,8 +120,7 @@ public class CipherRepositoryTests
|
||||
ICipherRepository cipherRepository,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IFolderRepository folderRepository,
|
||||
ITestDatabaseHelper helper)
|
||||
IFolderRepository folderRepository)
|
||||
{
|
||||
// This tests what happens when a cipher is moved into an organizations
|
||||
var user = await userRepository.CreateAsync(new User
|
||||
@ -171,8 +162,6 @@ public class CipherRepositoryTests
|
||||
UserId = user.Id,
|
||||
});
|
||||
|
||||
helper.ClearTracker();
|
||||
|
||||
// Move cipher to organization vault
|
||||
await cipherRepository.ReplaceAsync(new CipherDetails
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user