mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d
. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a
.
This commit is contained in:
@ -9,183 +9,184 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class CipherRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[Theory(Skip = "Run ad-hoc"), EfUserCipherAutoData]
|
||||
public async void RefreshDb(List<EfRepo.CipherRepository> suts)
|
||||
public class CipherRepositoryTests
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[Theory(Skip = "Run ad-hoc"), EfUserCipherAutoData]
|
||||
public async void RefreshDb(List<EfRepo.CipherRepository> suts)
|
||||
{
|
||||
await sut.RefreshDb();
|
||||
}
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org,
|
||||
CipherCompare equalityComparer, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var savedCiphers = new List<Cipher>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
cipher.UserId = efUser.Id;
|
||||
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
await sut.RefreshDb();
|
||||
}
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org,
|
||||
CipherCompare equalityComparer, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var savedCiphers = new List<Cipher>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
cipher.OrganizationId = efOrg.Id;
|
||||
}
|
||||
cipher.UserId = efUser.Id;
|
||||
|
||||
var postEfCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedCipher = await sut.GetByIdAsync(postEfCipher.Id);
|
||||
savedCiphers.Add(savedCipher);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
cipher.UserId = sqlUser.Id;
|
||||
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
{
|
||||
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
cipher.OrganizationId = sqlOrg.Id;
|
||||
}
|
||||
|
||||
var sqlCipher = await sqlCipherRepo.CreateAsync(cipher);
|
||||
var savedSqlCipher = await sqlCipherRepo.GetByIdAsync(sqlCipher.Id);
|
||||
savedCiphers.Add(savedSqlCipher);
|
||||
|
||||
var distinctItems = savedCiphers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserCipherAutoData]
|
||||
public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos)
|
||||
{
|
||||
var bumpedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
cipher.UserId = efUser.Id;
|
||||
cipher.OrganizationId = null;
|
||||
|
||||
var postEfCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var bumpedUser = await efUserRepos[i].GetByIdAsync(efUser.Id);
|
||||
bumpedUsers.Add(bumpedUser);
|
||||
}
|
||||
|
||||
Assert.True(bumpedUsers.All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString()));
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationCipherAutoData]
|
||||
public async void CreateAsync_BumpsOrgUserAccountRevisionDates(Cipher cipher, List<User> users,
|
||||
List<OrganizationUser> orgUsers, Collection collection, Organization org, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
List<EfRepo.OrganizationUserRepository> efOrgUserRepos, List<EfRepo.CollectionRepository> efCollectionRepos)
|
||||
{
|
||||
var savedCiphers = new List<Cipher>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUsers = await efUserRepos[i].CreateMany(users);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
efOrgRepos[i].ClearChangeTracking();
|
||||
|
||||
cipher.OrganizationId = efOrg.Id;
|
||||
|
||||
collection.OrganizationId = efOrg.Id;
|
||||
var efCollection = await efCollectionRepos[i].CreateAsync(collection);
|
||||
efCollectionRepos[i].ClearChangeTracking();
|
||||
|
||||
IEnumerable<object>[] lists = { efUsers, orgUsers };
|
||||
var maxOrgUsers = lists.Min(l => l.Count());
|
||||
|
||||
orgUsers = orgUsers.Take(maxOrgUsers).ToList();
|
||||
efUsers = efUsers.Take(maxOrgUsers).ToList();
|
||||
|
||||
for (var j = 0; j < maxOrgUsers; j++)
|
||||
{
|
||||
orgUsers[j].OrganizationId = efOrg.Id;
|
||||
orgUsers[j].UserId = efUsers[j].Id;
|
||||
}
|
||||
|
||||
orgUsers = await efOrgUserRepos[i].CreateMany(orgUsers);
|
||||
|
||||
var selectionReadOnlyList = new List<SelectionReadOnly>();
|
||||
orgUsers.ForEach(ou => selectionReadOnlyList.Add(new SelectionReadOnly() { Id = ou.Id }));
|
||||
|
||||
await efCollectionRepos[i].UpdateUsersAsync(efCollection.Id, selectionReadOnlyList);
|
||||
efCollectionRepos[i].ClearChangeTracking();
|
||||
|
||||
foreach (var ou in orgUsers)
|
||||
{
|
||||
var collectionUser = new CollectionUser()
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
{
|
||||
CollectionId = efCollection.Id,
|
||||
OrganizationUserId = ou.Id
|
||||
};
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
cipher.OrganizationId = efOrg.Id;
|
||||
}
|
||||
|
||||
var postEfCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedCipher = await sut.GetByIdAsync(postEfCipher.Id);
|
||||
savedCiphers.Add(savedCipher);
|
||||
}
|
||||
|
||||
cipher.UserId = null;
|
||||
var postEfCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipher);
|
||||
var modifiedUsers = await sut.Run(query).ToListAsync();
|
||||
Assert.True(modifiedUsers
|
||||
.All(u => u.AccountRevisionDate.ToShortDateString() ==
|
||||
DateTime.UtcNow.ToShortDateString()));
|
||||
}
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData]
|
||||
public async void DeleteAsync_CipherIsDeleted(
|
||||
Cipher cipher,
|
||||
User user,
|
||||
Organization org,
|
||||
List<EfRepo.CipherRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos
|
||||
)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
efOrgRepos[i].ClearChangeTracking();
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
cipher.UserId = sqlUser.Id;
|
||||
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
{
|
||||
cipher.OrganizationId = postEfOrg.Id;
|
||||
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
cipher.OrganizationId = sqlOrg.Id;
|
||||
}
|
||||
cipher.UserId = postEfUser.Id;
|
||||
|
||||
await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
var sqlCipher = await sqlCipherRepo.CreateAsync(cipher);
|
||||
var savedSqlCipher = await sqlCipherRepo.GetByIdAsync(sqlCipher.Id);
|
||||
savedCiphers.Add(savedSqlCipher);
|
||||
|
||||
await sut.DeleteAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
var distinctItems = savedCiphers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var savedCipher = await sut.GetByIdAsync(cipher.Id);
|
||||
Assert.True(savedCipher == null);
|
||||
[CiSkippedTheory, EfUserCipherAutoData]
|
||||
public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos)
|
||||
{
|
||||
var bumpedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
cipher.UserId = efUser.Id;
|
||||
cipher.OrganizationId = null;
|
||||
|
||||
var postEfCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var bumpedUser = await efUserRepos[i].GetByIdAsync(efUser.Id);
|
||||
bumpedUsers.Add(bumpedUser);
|
||||
}
|
||||
|
||||
Assert.True(bumpedUsers.All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString()));
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationCipherAutoData]
|
||||
public async void CreateAsync_BumpsOrgUserAccountRevisionDates(Cipher cipher, List<User> users,
|
||||
List<OrganizationUser> orgUsers, Collection collection, Organization org, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
List<EfRepo.OrganizationUserRepository> efOrgUserRepos, List<EfRepo.CollectionRepository> efCollectionRepos)
|
||||
{
|
||||
var savedCiphers = new List<Cipher>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUsers = await efUserRepos[i].CreateMany(users);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
efOrgRepos[i].ClearChangeTracking();
|
||||
|
||||
cipher.OrganizationId = efOrg.Id;
|
||||
|
||||
collection.OrganizationId = efOrg.Id;
|
||||
var efCollection = await efCollectionRepos[i].CreateAsync(collection);
|
||||
efCollectionRepos[i].ClearChangeTracking();
|
||||
|
||||
IEnumerable<object>[] lists = { efUsers, orgUsers };
|
||||
var maxOrgUsers = lists.Min(l => l.Count());
|
||||
|
||||
orgUsers = orgUsers.Take(maxOrgUsers).ToList();
|
||||
efUsers = efUsers.Take(maxOrgUsers).ToList();
|
||||
|
||||
for (var j = 0; j < maxOrgUsers; j++)
|
||||
{
|
||||
orgUsers[j].OrganizationId = efOrg.Id;
|
||||
orgUsers[j].UserId = efUsers[j].Id;
|
||||
}
|
||||
|
||||
orgUsers = await efOrgUserRepos[i].CreateMany(orgUsers);
|
||||
|
||||
var selectionReadOnlyList = new List<SelectionReadOnly>();
|
||||
orgUsers.ForEach(ou => selectionReadOnlyList.Add(new SelectionReadOnly() { Id = ou.Id }));
|
||||
|
||||
await efCollectionRepos[i].UpdateUsersAsync(efCollection.Id, selectionReadOnlyList);
|
||||
efCollectionRepos[i].ClearChangeTracking();
|
||||
|
||||
foreach (var ou in orgUsers)
|
||||
{
|
||||
var collectionUser = new CollectionUser()
|
||||
{
|
||||
CollectionId = efCollection.Id,
|
||||
OrganizationUserId = ou.Id
|
||||
};
|
||||
}
|
||||
|
||||
cipher.UserId = null;
|
||||
var postEfCipher = await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipher);
|
||||
var modifiedUsers = await sut.Run(query).ToListAsync();
|
||||
Assert.True(modifiedUsers
|
||||
.All(u => u.AccountRevisionDate.ToShortDateString() ==
|
||||
DateTime.UtcNow.ToShortDateString()));
|
||||
}
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData]
|
||||
public async void DeleteAsync_CipherIsDeleted(
|
||||
Cipher cipher,
|
||||
User user,
|
||||
Organization org,
|
||||
List<EfRepo.CipherRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos
|
||||
)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
efOrgRepos[i].ClearChangeTracking();
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
efUserRepos[i].ClearChangeTracking();
|
||||
|
||||
if (cipher.OrganizationId.HasValue)
|
||||
{
|
||||
cipher.OrganizationId = postEfOrg.Id;
|
||||
}
|
||||
cipher.UserId = postEfUser.Id;
|
||||
|
||||
await sut.CreateAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(cipher);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedCipher = await sut.GetByIdAsync(cipher.Id);
|
||||
Assert.True(savedCipher == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,44 +6,45 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class CollectionRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfCollectionAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Collection collection,
|
||||
Organization organization,
|
||||
CollectionCompare equalityComparer,
|
||||
List<EfRepo.CollectionRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrganizationRepos,
|
||||
SqlRepo.CollectionRepository sqlCollectionRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo
|
||||
)
|
||||
public class CollectionRepositoryTests
|
||||
{
|
||||
var savedCollections = new List<Collection>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfCollectionAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Collection collection,
|
||||
Organization organization,
|
||||
CollectionCompare equalityComparer,
|
||||
List<EfRepo.CollectionRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrganizationRepos,
|
||||
SqlRepo.CollectionRepository sqlCollectionRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
var savedCollections = new List<Collection>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
collection.OrganizationId = efOrganization.Id;
|
||||
var postEfCollection = await sut.CreateAsync(collection);
|
||||
sut.ClearChangeTracking();
|
||||
collection.OrganizationId = efOrganization.Id;
|
||||
var postEfCollection = await sut.CreateAsync(collection);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedCollection = await sut.GetByIdAsync(postEfCollection.Id);
|
||||
savedCollections.Add(savedCollection);
|
||||
var savedCollection = await sut.GetByIdAsync(postEfCollection.Id);
|
||||
savedCollections.Add(savedCollection);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
collection.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var sqlCollection = await sqlCollectionRepo.CreateAsync(collection);
|
||||
var savedSqlCollection = await sqlCollectionRepo.GetByIdAsync(sqlCollection.Id);
|
||||
savedCollections.Add(savedSqlCollection);
|
||||
|
||||
var distinctItems = savedCollections.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
collection.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var sqlCollection = await sqlCollectionRepo.CreateAsync(collection);
|
||||
var savedSqlCollection = await sqlCollectionRepo.GetByIdAsync(sqlCollection.Id);
|
||||
savedCollections.Add(savedSqlCollection);
|
||||
|
||||
var distinctItems = savedCollections.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -6,41 +6,42 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class DeviceRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfDeviceAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(Device device, User user,
|
||||
DeviceCompare equalityComparer, List<EfRepo.DeviceRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, SqlRepo.DeviceRepository sqlDeviceRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
public class DeviceRepositoryTests
|
||||
{
|
||||
var savedDevices = new List<Device>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfDeviceAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(Device device, User user,
|
||||
DeviceCompare equalityComparer, List<EfRepo.DeviceRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, SqlRepo.DeviceRepository sqlDeviceRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedDevices = new List<Device>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
device.UserId = efUser.Id;
|
||||
sut.ClearChangeTracking();
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
device.UserId = efUser.Id;
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var postEfDevice = await sut.CreateAsync(device);
|
||||
sut.ClearChangeTracking();
|
||||
var postEfDevice = await sut.CreateAsync(device);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedDevice = await sut.GetByIdAsync(postEfDevice.Id);
|
||||
savedDevices.Add(savedDevice);
|
||||
var savedDevice = await sut.GetByIdAsync(postEfDevice.Id);
|
||||
savedDevices.Add(savedDevice);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
device.UserId = sqlUser.Id;
|
||||
|
||||
var sqlDevice = await sqlDeviceRepo.CreateAsync(device);
|
||||
var savedSqlDevice = await sqlDeviceRepo.GetByIdAsync(sqlDevice.Id);
|
||||
savedDevices.Add(savedSqlDevice);
|
||||
|
||||
var distinctItems = savedDevices.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
device.UserId = sqlUser.Id;
|
||||
|
||||
var sqlDevice = await sqlDeviceRepo.CreateAsync(device);
|
||||
var savedSqlDevice = await sqlDeviceRepo.GetByIdAsync(sqlDevice.Id);
|
||||
savedDevices.Add(savedSqlDevice);
|
||||
|
||||
var distinctItems = savedDevices.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,53 +6,54 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class EmergencyAccessRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfEmergencyAccessAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
EmergencyAccess emergencyAccess,
|
||||
List<User> users,
|
||||
EmergencyAccessCompare equalityComparer,
|
||||
List<EfRepo.EmergencyAccessRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.EmergencyAccessRepository sqlEmergencyAccessRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo
|
||||
)
|
||||
public class EmergencyAccessRepositoryTests
|
||||
{
|
||||
var savedEmergencyAccesss = new List<EmergencyAccess>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfEmergencyAccessAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
EmergencyAccess emergencyAccess,
|
||||
List<User> users,
|
||||
EmergencyAccessCompare equalityComparer,
|
||||
List<EfRepo.EmergencyAccessRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.EmergencyAccessRepository sqlEmergencyAccessRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedEmergencyAccesss = new List<EmergencyAccess>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
for (int j = 0; j < users.Count; j++)
|
||||
{
|
||||
users[j] = await efUserRepos[i].CreateAsync(users[j]);
|
||||
}
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
emergencyAccess.GrantorId = users[0].Id;
|
||||
emergencyAccess.GranteeId = users[0].Id;
|
||||
var postEfEmergencyAccess = await sut.CreateAsync(emergencyAccess);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEmergencyAccess = await sut.GetByIdAsync(postEfEmergencyAccess.Id);
|
||||
savedEmergencyAccesss.Add(savedEmergencyAccess);
|
||||
}
|
||||
|
||||
for (int j = 0; j < users.Count; j++)
|
||||
{
|
||||
users[j] = await efUserRepos[i].CreateAsync(users[j]);
|
||||
users[j] = await sqlUserRepo.CreateAsync(users[j]);
|
||||
}
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
emergencyAccess.GrantorId = users[0].Id;
|
||||
emergencyAccess.GranteeId = users[0].Id;
|
||||
var postEfEmergencyAccess = await sut.CreateAsync(emergencyAccess);
|
||||
sut.ClearChangeTracking();
|
||||
var sqlEmergencyAccess = await sqlEmergencyAccessRepo.CreateAsync(emergencyAccess);
|
||||
var savedSqlEmergencyAccess = await sqlEmergencyAccessRepo.GetByIdAsync(sqlEmergencyAccess.Id);
|
||||
savedEmergencyAccesss.Add(savedSqlEmergencyAccess);
|
||||
|
||||
var savedEmergencyAccess = await sut.GetByIdAsync(postEfEmergencyAccess.Id);
|
||||
savedEmergencyAccesss.Add(savedEmergencyAccess);
|
||||
var distinctItems = savedEmergencyAccesss.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
for (int j = 0; j < users.Count; j++)
|
||||
{
|
||||
users[j] = await sqlUserRepo.CreateAsync(users[j]);
|
||||
}
|
||||
|
||||
emergencyAccess.GrantorId = users[0].Id;
|
||||
emergencyAccess.GranteeId = users[0].Id;
|
||||
var sqlEmergencyAccess = await sqlEmergencyAccessRepo.CreateAsync(emergencyAccess);
|
||||
var savedSqlEmergencyAccess = await sqlEmergencyAccessRepo.GetByIdAsync(sqlEmergencyAccess.Id);
|
||||
savedEmergencyAccesss.Add(savedSqlEmergencyAccess);
|
||||
|
||||
var distinctItems = savedEmergencyAccesss.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class CipherCompare : IEqualityComparer<Cipher>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Cipher x, Cipher y)
|
||||
public class CipherCompare : IEqualityComparer<Cipher>
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Data == y.Data &&
|
||||
x.Favorites == y.Favorites &&
|
||||
x.Attachments == y.Attachments;
|
||||
}
|
||||
public bool Equals(Cipher x, Cipher y)
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Data == y.Data &&
|
||||
x.Favorites == y.Favorites &&
|
||||
x.Attachments == y.Attachments;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Cipher obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Cipher obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class CollectionCompare : IEqualityComparer<Collection>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Collection x, Collection y)
|
||||
public class CollectionCompare : IEqualityComparer<Collection>
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.ExternalId == y.ExternalId;
|
||||
}
|
||||
public bool Equals(Collection x, Collection y)
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.ExternalId == y.ExternalId;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Collection obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Collection obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class DeviceCompare : IEqualityComparer<Device>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Device x, Device y)
|
||||
public class DeviceCompare : IEqualityComparer<Device>
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.Type == y.Type &&
|
||||
x.Identifier == y.Identifier &&
|
||||
x.PushToken == y.PushToken;
|
||||
}
|
||||
public bool Equals(Device x, Device y)
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.Type == y.Type &&
|
||||
x.Identifier == y.Identifier &&
|
||||
x.PushToken == y.PushToken;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Device obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Device obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class EmergencyAccessCompare : IEqualityComparer<EmergencyAccess>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(EmergencyAccess x, EmergencyAccess y)
|
||||
public class EmergencyAccessCompare : IEqualityComparer<EmergencyAccess>
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.KeyEncrypted == y.KeyEncrypted &&
|
||||
x.Type == y.Type &&
|
||||
x.Status == y.Status &&
|
||||
x.WaitTimeDays == y.WaitTimeDays &&
|
||||
x.RecoveryInitiatedDate == y.RecoveryInitiatedDate &&
|
||||
x.LastNotificationDate == y.LastNotificationDate;
|
||||
}
|
||||
public bool Equals(EmergencyAccess x, EmergencyAccess y)
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.KeyEncrypted == y.KeyEncrypted &&
|
||||
x.Type == y.Type &&
|
||||
x.Status == y.Status &&
|
||||
x.WaitTimeDays == y.WaitTimeDays &&
|
||||
x.RecoveryInitiatedDate == y.RecoveryInitiatedDate &&
|
||||
x.LastNotificationDate == y.LastNotificationDate;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] EmergencyAccess obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] EmergencyAccess obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class EventCompare : IEqualityComparer<Event>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Event x, Event y)
|
||||
public class EventCompare : IEqualityComparer<Event>
|
||||
{
|
||||
return x.Date.ToShortDateString() == y.Date.ToShortDateString() &&
|
||||
x.Type == y.Type &&
|
||||
x.IpAddress == y.IpAddress;
|
||||
}
|
||||
public bool Equals(Event x, Event y)
|
||||
{
|
||||
return x.Date.ToShortDateString() == y.Date.ToShortDateString() &&
|
||||
x.Type == y.Type &&
|
||||
x.IpAddress == y.IpAddress;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Event obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Event obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class FolderCompare : IEqualityComparer<Folder>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Folder x, Folder y)
|
||||
public class FolderCompare : IEqualityComparer<Folder>
|
||||
{
|
||||
return x.Name == y.Name;
|
||||
}
|
||||
public bool Equals(Folder x, Folder y)
|
||||
{
|
||||
return x.Name == y.Name;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Folder obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Folder obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,25 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class GrantCompare : IEqualityComparer<Grant>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Grant x, Grant y)
|
||||
public class GrantCompare : IEqualityComparer<Grant>
|
||||
{
|
||||
return x.Key == y.Key &&
|
||||
x.Type == y.Type &&
|
||||
x.SubjectId == y.SubjectId &&
|
||||
x.ClientId == y.ClientId &&
|
||||
x.Description == y.Description &&
|
||||
x.ExpirationDate == y.ExpirationDate &&
|
||||
x.ConsumedDate == y.ConsumedDate &&
|
||||
x.Data == y.Data;
|
||||
}
|
||||
public bool Equals(Grant x, Grant y)
|
||||
{
|
||||
return x.Key == y.Key &&
|
||||
x.Type == y.Type &&
|
||||
x.SubjectId == y.SubjectId &&
|
||||
x.ClientId == y.ClientId &&
|
||||
x.Description == y.Description &&
|
||||
x.ExpirationDate == y.ExpirationDate &&
|
||||
x.ConsumedDate == y.ConsumedDate &&
|
||||
x.Data == y.Data;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Grant obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Grant obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class GroupCompare : IEqualityComparer<Group>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Group x, Group y)
|
||||
public class GroupCompare : IEqualityComparer<Group>
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.AccessAll == y.AccessAll &&
|
||||
x.ExternalId == y.ExternalId;
|
||||
}
|
||||
public bool Equals(Group x, Group y)
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.AccessAll == y.AccessAll &&
|
||||
x.ExternalId == y.ExternalId;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Group obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Group obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class InstallationCompare : IEqualityComparer<Installation>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Installation x, Installation y)
|
||||
public class InstallationCompare : IEqualityComparer<Installation>
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.Key == y.Key &&
|
||||
x.Enabled == y.Enabled;
|
||||
}
|
||||
public bool Equals(Installation x, Installation y)
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.Key == y.Key &&
|
||||
x.Enabled == y.Enabled;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Installation obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Installation obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +1,54 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class OrganizationCompare : IEqualityComparer<Organization>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Organization x, Organization y)
|
||||
public class OrganizationCompare : IEqualityComparer<Organization>
|
||||
{
|
||||
var a = x.ExpirationDate.ToString();
|
||||
var b = y.ExpirationDate.ToString();
|
||||
return x.Identifier.Equals(y.Identifier) &&
|
||||
x.Name.Equals(y.Name) &&
|
||||
x.BusinessName.Equals(y.BusinessName) &&
|
||||
x.BusinessAddress1.Equals(y.BusinessAddress1) &&
|
||||
x.BusinessAddress2.Equals(y.BusinessAddress2) &&
|
||||
x.BusinessAddress3.Equals(y.BusinessAddress3) &&
|
||||
x.BusinessCountry.Equals(y.BusinessCountry) &&
|
||||
x.BusinessTaxNumber.Equals(y.BusinessTaxNumber) &&
|
||||
x.BillingEmail.Equals(y.BillingEmail) &&
|
||||
x.Plan.Equals(y.Plan) &&
|
||||
x.PlanType.Equals(y.PlanType) &&
|
||||
x.Seats.Equals(y.Seats) &&
|
||||
x.MaxCollections.Equals(y.MaxCollections) &&
|
||||
x.UsePolicies.Equals(y.UsePolicies) &&
|
||||
x.UseSso.Equals(y.UseSso) &&
|
||||
x.UseKeyConnector.Equals(y.UseKeyConnector) &&
|
||||
x.UseScim.Equals(y.UseScim) &&
|
||||
x.UseGroups.Equals(y.UseGroups) &&
|
||||
x.UseDirectory.Equals(y.UseDirectory) &&
|
||||
x.UseEvents.Equals(y.UseEvents) &&
|
||||
x.UseTotp.Equals(y.UseTotp) &&
|
||||
x.Use2fa.Equals(y.Use2fa) &&
|
||||
x.UseApi.Equals(y.UseApi) &&
|
||||
x.SelfHost.Equals(y.SelfHost) &&
|
||||
x.UsersGetPremium.Equals(y.UsersGetPremium) &&
|
||||
x.Storage.Equals(y.Storage) &&
|
||||
x.MaxStorageGb.Equals(y.MaxStorageGb) &&
|
||||
x.Gateway.Equals(y.Gateway) &&
|
||||
x.GatewayCustomerId.Equals(y.GatewayCustomerId) &&
|
||||
x.GatewaySubscriptionId.Equals(y.GatewaySubscriptionId) &&
|
||||
x.ReferenceData.Equals(y.ReferenceData) &&
|
||||
x.Enabled.Equals(y.Enabled) &&
|
||||
x.LicenseKey.Equals(y.LicenseKey) &&
|
||||
x.TwoFactorProviders.Equals(y.TwoFactorProviders) &&
|
||||
x.ExpirationDate.ToString().Equals(y.ExpirationDate.ToString());
|
||||
}
|
||||
public bool Equals(Organization x, Organization y)
|
||||
{
|
||||
var a = x.ExpirationDate.ToString();
|
||||
var b = y.ExpirationDate.ToString();
|
||||
return x.Identifier.Equals(y.Identifier) &&
|
||||
x.Name.Equals(y.Name) &&
|
||||
x.BusinessName.Equals(y.BusinessName) &&
|
||||
x.BusinessAddress1.Equals(y.BusinessAddress1) &&
|
||||
x.BusinessAddress2.Equals(y.BusinessAddress2) &&
|
||||
x.BusinessAddress3.Equals(y.BusinessAddress3) &&
|
||||
x.BusinessCountry.Equals(y.BusinessCountry) &&
|
||||
x.BusinessTaxNumber.Equals(y.BusinessTaxNumber) &&
|
||||
x.BillingEmail.Equals(y.BillingEmail) &&
|
||||
x.Plan.Equals(y.Plan) &&
|
||||
x.PlanType.Equals(y.PlanType) &&
|
||||
x.Seats.Equals(y.Seats) &&
|
||||
x.MaxCollections.Equals(y.MaxCollections) &&
|
||||
x.UsePolicies.Equals(y.UsePolicies) &&
|
||||
x.UseSso.Equals(y.UseSso) &&
|
||||
x.UseKeyConnector.Equals(y.UseKeyConnector) &&
|
||||
x.UseScim.Equals(y.UseScim) &&
|
||||
x.UseGroups.Equals(y.UseGroups) &&
|
||||
x.UseDirectory.Equals(y.UseDirectory) &&
|
||||
x.UseEvents.Equals(y.UseEvents) &&
|
||||
x.UseTotp.Equals(y.UseTotp) &&
|
||||
x.Use2fa.Equals(y.Use2fa) &&
|
||||
x.UseApi.Equals(y.UseApi) &&
|
||||
x.SelfHost.Equals(y.SelfHost) &&
|
||||
x.UsersGetPremium.Equals(y.UsersGetPremium) &&
|
||||
x.Storage.Equals(y.Storage) &&
|
||||
x.MaxStorageGb.Equals(y.MaxStorageGb) &&
|
||||
x.Gateway.Equals(y.Gateway) &&
|
||||
x.GatewayCustomerId.Equals(y.GatewayCustomerId) &&
|
||||
x.GatewaySubscriptionId.Equals(y.GatewaySubscriptionId) &&
|
||||
x.ReferenceData.Equals(y.ReferenceData) &&
|
||||
x.Enabled.Equals(y.Enabled) &&
|
||||
x.LicenseKey.Equals(y.LicenseKey) &&
|
||||
x.TwoFactorProviders.Equals(y.TwoFactorProviders) &&
|
||||
x.ExpirationDate.ToString().Equals(y.ExpirationDate.ToString());
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Organization obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Organization obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class OrganizationSponsorshipCompare : IEqualityComparer<OrganizationSponsorship>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(OrganizationSponsorship x, OrganizationSponsorship y)
|
||||
public class OrganizationSponsorshipCompare : IEqualityComparer<OrganizationSponsorship>
|
||||
{
|
||||
return x.SponsoringOrganizationId.Equals(y.SponsoringOrganizationId) &&
|
||||
x.SponsoringOrganizationUserId.Equals(y.SponsoringOrganizationUserId) &&
|
||||
x.SponsoredOrganizationId.Equals(y.SponsoredOrganizationId) &&
|
||||
x.OfferedToEmail.Equals(y.OfferedToEmail) &&
|
||||
x.ToDelete.Equals(y.ToDelete) &&
|
||||
x.ValidUntil.ToString().Equals(y.ValidUntil.ToString());
|
||||
}
|
||||
public bool Equals(OrganizationSponsorship x, OrganizationSponsorship y)
|
||||
{
|
||||
return x.SponsoringOrganizationId.Equals(y.SponsoringOrganizationId) &&
|
||||
x.SponsoringOrganizationUserId.Equals(y.SponsoringOrganizationUserId) &&
|
||||
x.SponsoredOrganizationId.Equals(y.SponsoredOrganizationId) &&
|
||||
x.OfferedToEmail.Equals(y.OfferedToEmail) &&
|
||||
x.ToDelete.Equals(y.ToDelete) &&
|
||||
x.ValidUntil.ToString().Equals(y.ValidUntil.ToString());
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] OrganizationSponsorship obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] OrganizationSponsorship obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class OrganizationUserCompare : IEqualityComparer<OrganizationUser>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(OrganizationUser x, OrganizationUser y)
|
||||
public class OrganizationUserCompare : IEqualityComparer<OrganizationUser>
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.Status == y.Status &&
|
||||
x.Type == y.Type &&
|
||||
x.AccessAll == y.AccessAll &&
|
||||
x.ExternalId == y.ExternalId &&
|
||||
x.Permissions == y.Permissions;
|
||||
}
|
||||
public bool Equals(OrganizationUser x, OrganizationUser y)
|
||||
{
|
||||
return x.Email == y.Email &&
|
||||
x.Status == y.Status &&
|
||||
x.Type == y.Type &&
|
||||
x.AccessAll == y.AccessAll &&
|
||||
x.ExternalId == y.ExternalId &&
|
||||
x.Permissions == y.Permissions;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] OrganizationUser obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] OrganizationUser obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,29 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class PolicyCompare : IEqualityComparer<Policy>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Policy x, Policy y)
|
||||
public class PolicyCompare : IEqualityComparer<Policy>
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Data == y.Data &&
|
||||
x.Enabled == y.Enabled;
|
||||
public bool Equals(Policy x, Policy y)
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Data == y.Data &&
|
||||
x.Enabled == y.Enabled;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Policy obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Policy obj)
|
||||
public class PolicyCompareIncludingOrganization : PolicyCompare
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class PolicyCompareIncludingOrganization : PolicyCompare
|
||||
{
|
||||
public new bool Equals(Policy x, Policy y)
|
||||
{
|
||||
return base.Equals(x, y) &&
|
||||
x.OrganizationId == y.OrganizationId;
|
||||
public new bool Equals(Policy x, Policy y)
|
||||
{
|
||||
return base.Equals(x, y) &&
|
||||
x.OrganizationId == y.OrganizationId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,27 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class SendCompare : IEqualityComparer<Send>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Send x, Send y)
|
||||
public class SendCompare : IEqualityComparer<Send>
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Data == y.Data &&
|
||||
x.Key == y.Key &&
|
||||
x.Password == y.Password &&
|
||||
x.MaxAccessCount == y.MaxAccessCount &&
|
||||
x.AccessCount == y.AccessCount &&
|
||||
x.ExpirationDate?.ToShortDateString() == y.ExpirationDate?.ToShortDateString() &&
|
||||
x.DeletionDate.ToShortDateString() == y.DeletionDate.ToShortDateString() &&
|
||||
x.Disabled == y.Disabled &&
|
||||
x.HideEmail == y.HideEmail;
|
||||
}
|
||||
public bool Equals(Send x, Send y)
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Data == y.Data &&
|
||||
x.Key == y.Key &&
|
||||
x.Password == y.Password &&
|
||||
x.MaxAccessCount == y.MaxAccessCount &&
|
||||
x.AccessCount == y.AccessCount &&
|
||||
x.ExpirationDate?.ToShortDateString() == y.ExpirationDate?.ToShortDateString() &&
|
||||
x.DeletionDate.ToShortDateString() == y.DeletionDate.ToShortDateString() &&
|
||||
x.Disabled == y.Disabled &&
|
||||
x.HideEmail == y.HideEmail;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Send obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Send obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class SsoConfigCompare : IEqualityComparer<SsoConfig>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(SsoConfig x, SsoConfig y)
|
||||
public class SsoConfigCompare : IEqualityComparer<SsoConfig>
|
||||
{
|
||||
return x.Enabled == y.Enabled &&
|
||||
x.OrganizationId == y.OrganizationId &&
|
||||
x.Data == y.Data;
|
||||
}
|
||||
public bool Equals(SsoConfig x, SsoConfig y)
|
||||
{
|
||||
return x.Enabled == y.Enabled &&
|
||||
x.OrganizationId == y.OrganizationId &&
|
||||
x.Data == y.Data;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] SsoConfig obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] SsoConfig obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class SsoUserCompare : IEqualityComparer<SsoUser>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(SsoUser x, SsoUser y)
|
||||
public class SsoUserCompare : IEqualityComparer<SsoUser>
|
||||
{
|
||||
return x.ExternalId == y.ExternalId;
|
||||
}
|
||||
public bool Equals(SsoUser x, SsoUser y)
|
||||
{
|
||||
return x.ExternalId == y.ExternalId;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] SsoUser obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] SsoUser obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,22 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class TaxRateCompare : IEqualityComparer<TaxRate>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(TaxRate x, TaxRate y)
|
||||
public class TaxRateCompare : IEqualityComparer<TaxRate>
|
||||
{
|
||||
return x.Country == y.Country &&
|
||||
x.State == y.State &&
|
||||
x.PostalCode == y.PostalCode &&
|
||||
x.Rate == y.Rate &&
|
||||
x.Active == y.Active;
|
||||
}
|
||||
public bool Equals(TaxRate x, TaxRate y)
|
||||
{
|
||||
return x.Country == y.Country &&
|
||||
x.State == y.State &&
|
||||
x.PostalCode == y.PostalCode &&
|
||||
x.Rate == y.Rate &&
|
||||
x.Active == y.Active;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] TaxRate obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] TaxRate obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class TransactionCompare : IEqualityComparer<Transaction>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(Transaction x, Transaction y)
|
||||
public class TransactionCompare : IEqualityComparer<Transaction>
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Amount == y.Amount &&
|
||||
x.Refunded == y.Refunded &&
|
||||
x.Details == y.Details &&
|
||||
x.PaymentMethodType == y.PaymentMethodType &&
|
||||
x.Gateway == y.Gateway &&
|
||||
x.GatewayId == y.GatewayId;
|
||||
}
|
||||
public bool Equals(Transaction x, Transaction y)
|
||||
{
|
||||
return x.Type == y.Type &&
|
||||
x.Amount == y.Amount &&
|
||||
x.Refunded == y.Refunded &&
|
||||
x.Details == y.Details &&
|
||||
x.PaymentMethodType == y.PaymentMethodType &&
|
||||
x.Gateway == y.Gateway &&
|
||||
x.GatewayId == y.GatewayId;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Transaction obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] Transaction obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,40 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class UserCompare : IEqualityComparer<User>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(User x, User y)
|
||||
public class UserCompare : IEqualityComparer<User>
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.Email == y.Email &&
|
||||
x.EmailVerified == y.EmailVerified &&
|
||||
x.MasterPassword == y.MasterPassword &&
|
||||
x.MasterPasswordHint == y.MasterPasswordHint &&
|
||||
x.Culture == y.Culture &&
|
||||
x.SecurityStamp == y.SecurityStamp &&
|
||||
x.TwoFactorProviders == y.TwoFactorProviders &&
|
||||
x.TwoFactorRecoveryCode == y.TwoFactorRecoveryCode &&
|
||||
x.EquivalentDomains == y.EquivalentDomains &&
|
||||
x.Key == y.Key &&
|
||||
x.PublicKey == y.PublicKey &&
|
||||
x.PrivateKey == y.PrivateKey &&
|
||||
x.Premium == y.Premium &&
|
||||
x.Storage == y.Storage &&
|
||||
x.MaxStorageGb == y.MaxStorageGb &&
|
||||
x.Gateway == y.Gateway &&
|
||||
x.GatewayCustomerId == y.GatewayCustomerId &&
|
||||
x.ReferenceData == y.ReferenceData &&
|
||||
x.LicenseKey == y.LicenseKey &&
|
||||
x.ApiKey == y.ApiKey &&
|
||||
x.Kdf == y.Kdf &&
|
||||
x.KdfIterations == y.KdfIterations;
|
||||
}
|
||||
public bool Equals(User x, User y)
|
||||
{
|
||||
return x.Name == y.Name &&
|
||||
x.Email == y.Email &&
|
||||
x.EmailVerified == y.EmailVerified &&
|
||||
x.MasterPassword == y.MasterPassword &&
|
||||
x.MasterPasswordHint == y.MasterPasswordHint &&
|
||||
x.Culture == y.Culture &&
|
||||
x.SecurityStamp == y.SecurityStamp &&
|
||||
x.TwoFactorProviders == y.TwoFactorProviders &&
|
||||
x.TwoFactorRecoveryCode == y.TwoFactorRecoveryCode &&
|
||||
x.EquivalentDomains == y.EquivalentDomains &&
|
||||
x.Key == y.Key &&
|
||||
x.PublicKey == y.PublicKey &&
|
||||
x.PrivateKey == y.PrivateKey &&
|
||||
x.Premium == y.Premium &&
|
||||
x.Storage == y.Storage &&
|
||||
x.MaxStorageGb == y.MaxStorageGb &&
|
||||
x.Gateway == y.Gateway &&
|
||||
x.GatewayCustomerId == y.GatewayCustomerId &&
|
||||
x.ReferenceData == y.ReferenceData &&
|
||||
x.LicenseKey == y.LicenseKey &&
|
||||
x.ApiKey == y.ApiKey &&
|
||||
x.Kdf == y.Kdf &&
|
||||
x.KdfIterations == y.KdfIterations;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] User obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] User obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
|
||||
|
||||
public class UserKdfInformationCompare : IEqualityComparer<UserKdfInformation>
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers
|
||||
{
|
||||
public bool Equals(UserKdfInformation x, UserKdfInformation y)
|
||||
public class UserKdfInformationCompare : IEqualityComparer<UserKdfInformation>
|
||||
{
|
||||
return x.Kdf == y.Kdf &&
|
||||
x.KdfIterations == y.KdfIterations;
|
||||
}
|
||||
public bool Equals(UserKdfInformation x, UserKdfInformation y)
|
||||
{
|
||||
return x.Kdf == y.Kdf &&
|
||||
x.KdfIterations == y.KdfIterations;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] UserKdfInformation obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
public int GetHashCode([DisallowNull] UserKdfInformation obj)
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,43 +6,44 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class FolderRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfFolderAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Folder folder,
|
||||
User user,
|
||||
FolderCompare equalityComparer,
|
||||
List<EfRepo.FolderRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.FolderRepository sqlFolderRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
public class FolderRepositoryTests
|
||||
{
|
||||
var savedFolders = new List<Folder>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfFolderAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Folder folder,
|
||||
User user,
|
||||
FolderCompare equalityComparer,
|
||||
List<EfRepo.FolderRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.FolderRepository sqlFolderRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedFolders = new List<Folder>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
folder.UserId = efUser.Id;
|
||||
var postEfFolder = await sut.CreateAsync(folder);
|
||||
sut.ClearChangeTracking();
|
||||
folder.UserId = efUser.Id;
|
||||
var postEfFolder = await sut.CreateAsync(folder);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedFolder = await sut.GetByIdAsync(folder.Id);
|
||||
savedFolders.Add(savedFolder);
|
||||
var savedFolder = await sut.GetByIdAsync(folder.Id);
|
||||
savedFolders.Add(savedFolder);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
|
||||
folder.UserId = sqlUser.Id;
|
||||
var sqlFolder = await sqlFolderRepo.CreateAsync(folder);
|
||||
savedFolders.Add(await sqlFolderRepo.GetByIdAsync(sqlFolder.Id));
|
||||
|
||||
var distinctItems = savedFolders.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
|
||||
folder.UserId = sqlUser.Id;
|
||||
var sqlFolder = await sqlFolderRepo.CreateAsync(folder);
|
||||
savedFolders.Add(await sqlFolderRepo.GetByIdAsync(sqlFolder.Id));
|
||||
|
||||
var distinctItems = savedFolders.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -6,33 +6,34 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class InstallationRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfInstallationAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Installation installation,
|
||||
InstallationCompare equalityComparer,
|
||||
List<EfRepo.InstallationRepository> suts,
|
||||
SqlRepo.InstallationRepository sqlInstallationRepo
|
||||
)
|
||||
public class InstallationRepositoryTests
|
||||
{
|
||||
var savedInstallations = new List<Installation>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfInstallationAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Installation installation,
|
||||
InstallationCompare equalityComparer,
|
||||
List<EfRepo.InstallationRepository> suts,
|
||||
SqlRepo.InstallationRepository sqlInstallationRepo
|
||||
)
|
||||
{
|
||||
var postEfInstallation = await sut.CreateAsync(installation);
|
||||
sut.ClearChangeTracking();
|
||||
var savedInstallations = new List<Installation>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfInstallation = await sut.CreateAsync(installation);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedInstallation = await sut.GetByIdAsync(postEfInstallation.Id);
|
||||
savedInstallations.Add(savedInstallation);
|
||||
var savedInstallation = await sut.GetByIdAsync(postEfInstallation.Id);
|
||||
savedInstallations.Add(savedInstallation);
|
||||
}
|
||||
|
||||
var sqlInstallation = await sqlInstallationRepo.CreateAsync(installation);
|
||||
var savedSqlInstallation = await sqlInstallationRepo.GetByIdAsync(sqlInstallation.Id);
|
||||
savedInstallations.Add(savedSqlInstallation);
|
||||
|
||||
var distinctItems = savedInstallations.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlInstallation = await sqlInstallationRepo.CreateAsync(installation);
|
||||
var savedSqlInstallation = await sqlInstallationRepo.GetByIdAsync(sqlInstallation.Id);
|
||||
savedInstallations.Add(savedSqlInstallation);
|
||||
|
||||
var distinctItems = savedInstallations.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -7,143 +7,144 @@ using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Organization = Bit.Core.Entities.Organization;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class OrganizationRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
public class OrganizationRepositoryTests
|
||||
{
|
||||
var savedOrganizations = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var postEfOrganization = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
var savedOrganizations = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfOrganization = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedOrganization = await sut.GetByIdAsync(organization.Id);
|
||||
savedOrganizations.Add(savedOrganization);
|
||||
var savedOrganization = await sut.GetByIdAsync(organization.Id);
|
||||
savedOrganizations.Add(savedOrganization);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
savedOrganizations.Add(await sqlOrganizationRepo.GetByIdAsync(sqlOrganization.Id));
|
||||
|
||||
var distinctItems = savedOrganizations.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
savedOrganizations.Add(await sqlOrganizationRepo.GetByIdAsync(sqlOrganization.Id));
|
||||
|
||||
var distinctItems = savedOrganizations.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(Organization postOrganization,
|
||||
Organization replaceOrganization, SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
OrganizationCompare equalityComparer, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var savedOrganizations = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(Organization postOrganization,
|
||||
Organization replaceOrganization, SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
OrganizationCompare equalityComparer, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var postEfOrganization = await sut.CreateAsync(postOrganization);
|
||||
sut.ClearChangeTracking();
|
||||
var savedOrganizations = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfOrganization = await sut.CreateAsync(postOrganization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
replaceOrganization.Id = postEfOrganization.Id;
|
||||
await sut.ReplaceAsync(replaceOrganization);
|
||||
sut.ClearChangeTracking();
|
||||
replaceOrganization.Id = postEfOrganization.Id;
|
||||
await sut.ReplaceAsync(replaceOrganization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedOrganization = await sut.GetByIdAsync(replaceOrganization.Id);
|
||||
savedOrganizations.Add(replacedOrganization);
|
||||
var replacedOrganization = await sut.GetByIdAsync(replaceOrganization.Id);
|
||||
savedOrganizations.Add(replacedOrganization);
|
||||
}
|
||||
|
||||
var postSqlOrganization = await sqlOrganizationRepo.CreateAsync(postOrganization);
|
||||
replaceOrganization.Id = postSqlOrganization.Id;
|
||||
await sqlOrganizationRepo.ReplaceAsync(replaceOrganization);
|
||||
savedOrganizations.Add(await sqlOrganizationRepo.GetByIdAsync(replaceOrganization.Id));
|
||||
|
||||
var distinctItems = savedOrganizations.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlOrganization = await sqlOrganizationRepo.CreateAsync(postOrganization);
|
||||
replaceOrganization.Id = postSqlOrganization.Id;
|
||||
await sqlOrganizationRepo.ReplaceAsync(replaceOrganization);
|
||||
savedOrganizations.Add(await sqlOrganizationRepo.GetByIdAsync(replaceOrganization.Id));
|
||||
|
||||
var distinctItems = savedOrganizations.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var postEfOrganization = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfOrganization = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfOrganization = await sut.GetByIdAsync(postEfOrganization.Id);
|
||||
sut.ClearChangeTracking();
|
||||
Assert.True(savedEfOrganization != null);
|
||||
var savedEfOrganization = await sut.GetByIdAsync(postEfOrganization.Id);
|
||||
sut.ClearChangeTracking();
|
||||
Assert.True(savedEfOrganization != null);
|
||||
|
||||
await sut.DeleteAsync(savedEfOrganization);
|
||||
sut.ClearChangeTracking();
|
||||
await sut.DeleteAsync(savedEfOrganization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
savedEfOrganization = await sut.GetByIdAsync(savedEfOrganization.Id);
|
||||
Assert.True(savedEfOrganization == null);
|
||||
savedEfOrganization = await sut.GetByIdAsync(savedEfOrganization.Id);
|
||||
Assert.True(savedEfOrganization == null);
|
||||
}
|
||||
|
||||
var postSqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
var savedSqlOrganization = await sqlOrganizationRepo.GetByIdAsync(postSqlOrganization.Id);
|
||||
Assert.True(savedSqlOrganization != null);
|
||||
|
||||
await sqlOrganizationRepo.DeleteAsync(postSqlOrganization);
|
||||
savedSqlOrganization = await sqlOrganizationRepo.GetByIdAsync(postSqlOrganization.Id);
|
||||
Assert.True(savedSqlOrganization == null);
|
||||
}
|
||||
|
||||
var postSqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
var savedSqlOrganization = await sqlOrganizationRepo.GetByIdAsync(postSqlOrganization.Id);
|
||||
Assert.True(savedSqlOrganization != null);
|
||||
|
||||
await sqlOrganizationRepo.DeleteAsync(postSqlOrganization);
|
||||
savedSqlOrganization = await sqlOrganizationRepo.GetByIdAsync(postSqlOrganization.Id);
|
||||
Assert.True(savedSqlOrganization == null);
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetByIdentifierAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var returnedOrgs = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetByIdentifierAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var postEfOrg = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
var returnedOrgs = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfOrg = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var returnedOrg = await sut.GetByIdentifierAsync(postEfOrg.Identifier.ToUpperInvariant());
|
||||
returnedOrgs.Add(returnedOrg);
|
||||
var returnedOrg = await sut.GetByIdentifierAsync(postEfOrg.Identifier.ToUpperInvariant());
|
||||
returnedOrgs.Add(returnedOrg);
|
||||
}
|
||||
|
||||
var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
returnedOrgs.Add(await sqlOrganizationRepo.GetByIdentifierAsync(postSqlOrg.Identifier.ToUpperInvariant()));
|
||||
|
||||
var distinctItems = returnedOrgs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
returnedOrgs.Add(await sqlOrganizationRepo.GetByIdentifierAsync(postSqlOrg.Identifier.ToUpperInvariant()));
|
||||
|
||||
var distinctItems = returnedOrgs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetManyByEnabledAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var returnedOrgs = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetManyByEnabledAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var postEfOrg = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
var returnedOrgs = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfOrg = await sut.CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var efReturnedOrgs = await sut.GetManyByEnabledAsync();
|
||||
returnedOrgs.Concat(efReturnedOrgs);
|
||||
var efReturnedOrgs = await sut.GetManyByEnabledAsync();
|
||||
returnedOrgs.Concat(efReturnedOrgs);
|
||||
}
|
||||
|
||||
var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
returnedOrgs.Concat(await sqlOrganizationRepo.GetManyByEnabledAsync());
|
||||
|
||||
Assert.True(returnedOrgs.All(o => o.Enabled));
|
||||
}
|
||||
|
||||
var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
returnedOrgs.Concat(await sqlOrganizationRepo.GetManyByEnabledAsync());
|
||||
|
||||
Assert.True(returnedOrgs.All(o => o.Enabled));
|
||||
}
|
||||
|
||||
// testing data matches here would require manipulating all organization abilities in the db
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetManyAbilitiesAsync_Works(SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var list = new List<OrganizationAbility>();
|
||||
foreach (var sut in suts)
|
||||
// testing data matches here would require manipulating all organization abilities in the db
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetManyAbilitiesAsync_Works(SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
list.Concat(await sut.GetManyAbilitiesAsync());
|
||||
}
|
||||
var list = new List<OrganizationAbility>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
list.Concat(await sut.GetManyAbilitiesAsync());
|
||||
}
|
||||
|
||||
list.Concat(await sqlOrganizationRepo.GetManyAbilitiesAsync());
|
||||
Assert.True(list.All(x => x.GetType() == typeof(OrganizationAbility)));
|
||||
list.Concat(await sqlOrganizationRepo.GetManyAbilitiesAsync());
|
||||
Assert.True(list.All(x => x.GetType() == typeof(OrganizationAbility)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,126 +6,127 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class OrganizationSponsorshipRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfOrganizationSponsorshipAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
OrganizationSponsorship organizationSponsorship, Organization sponsoringOrg,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
|
||||
OrganizationSponsorshipCompare equalityComparer,
|
||||
List<EfRepo.OrganizationSponsorshipRepository> suts)
|
||||
public class OrganizationSponsorshipRepositoryTests
|
||||
{
|
||||
organizationSponsorship.SponsoredOrganizationId = null;
|
||||
|
||||
var savedOrganizationSponsorships = new List<OrganizationSponsorship>();
|
||||
foreach (var (sut, orgRepo) in suts.Zip(efOrgRepos))
|
||||
[CiSkippedTheory, EfOrganizationSponsorshipAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
OrganizationSponsorship organizationSponsorship, Organization sponsoringOrg,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
|
||||
OrganizationSponsorshipCompare equalityComparer,
|
||||
List<EfRepo.OrganizationSponsorshipRepository> suts)
|
||||
{
|
||||
var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);
|
||||
sut.ClearChangeTracking();
|
||||
organizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
organizationSponsorship.SponsoredOrganizationId = null;
|
||||
|
||||
await sut.CreateAsync(organizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
var savedOrganizationSponsorships = new List<OrganizationSponsorship>();
|
||||
foreach (var (sut, orgRepo) in suts.Zip(efOrgRepos))
|
||||
{
|
||||
var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);
|
||||
sut.ClearChangeTracking();
|
||||
organizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
|
||||
var savedOrganizationSponsorship = await sut.GetByIdAsync(organizationSponsorship.Id);
|
||||
savedOrganizationSponsorships.Add(savedOrganizationSponsorship);
|
||||
await sut.CreateAsync(organizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedOrganizationSponsorship = await sut.GetByIdAsync(organizationSponsorship.Id);
|
||||
savedOrganizationSponsorships.Add(savedOrganizationSponsorship);
|
||||
}
|
||||
|
||||
var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);
|
||||
organizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;
|
||||
|
||||
var sqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.CreateAsync(organizationSponsorship);
|
||||
savedOrganizationSponsorships.Add(await sqlOrganizationSponsorshipRepo.GetByIdAsync(sqlOrganizationSponsorship.Id));
|
||||
|
||||
var distinctItems = savedOrganizationSponsorships.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);
|
||||
organizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;
|
||||
|
||||
var sqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.CreateAsync(organizationSponsorship);
|
||||
savedOrganizationSponsorships.Add(await sqlOrganizationSponsorshipRepo.GetByIdAsync(sqlOrganizationSponsorship.Id));
|
||||
|
||||
var distinctItems = savedOrganizationSponsorships.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationSponsorshipAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(OrganizationSponsorship postOrganizationSponsorship,
|
||||
OrganizationSponsorship replaceOrganizationSponsorship, Organization sponsoringOrg,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
|
||||
OrganizationSponsorshipCompare equalityComparer, List<EfRepo.OrganizationSponsorshipRepository> suts)
|
||||
{
|
||||
postOrganizationSponsorship.SponsoredOrganizationId = null;
|
||||
replaceOrganizationSponsorship.SponsoredOrganizationId = null;
|
||||
|
||||
var savedOrganizationSponsorships = new List<OrganizationSponsorship>();
|
||||
foreach (var (sut, orgRepo) in suts.Zip(efOrgRepos))
|
||||
[CiSkippedTheory, EfOrganizationSponsorshipAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(OrganizationSponsorship postOrganizationSponsorship,
|
||||
OrganizationSponsorship replaceOrganizationSponsorship, Organization sponsoringOrg,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
|
||||
OrganizationSponsorshipCompare equalityComparer, List<EfRepo.OrganizationSponsorshipRepository> suts)
|
||||
{
|
||||
var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);
|
||||
sut.ClearChangeTracking();
|
||||
postOrganizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
replaceOrganizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
postOrganizationSponsorship.SponsoredOrganizationId = null;
|
||||
replaceOrganizationSponsorship.SponsoredOrganizationId = null;
|
||||
|
||||
var postEfOrganizationSponsorship = await sut.CreateAsync(postOrganizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
var savedOrganizationSponsorships = new List<OrganizationSponsorship>();
|
||||
foreach (var (sut, orgRepo) in suts.Zip(efOrgRepos))
|
||||
{
|
||||
var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);
|
||||
sut.ClearChangeTracking();
|
||||
postOrganizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
replaceOrganizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
|
||||
replaceOrganizationSponsorship.Id = postEfOrganizationSponsorship.Id;
|
||||
await sut.ReplaceAsync(replaceOrganizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
var postEfOrganizationSponsorship = await sut.CreateAsync(postOrganizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedOrganizationSponsorship = await sut.GetByIdAsync(replaceOrganizationSponsorship.Id);
|
||||
savedOrganizationSponsorships.Add(replacedOrganizationSponsorship);
|
||||
replaceOrganizationSponsorship.Id = postEfOrganizationSponsorship.Id;
|
||||
await sut.ReplaceAsync(replaceOrganizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedOrganizationSponsorship = await sut.GetByIdAsync(replaceOrganizationSponsorship.Id);
|
||||
savedOrganizationSponsorships.Add(replacedOrganizationSponsorship);
|
||||
}
|
||||
|
||||
var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);
|
||||
postOrganizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;
|
||||
|
||||
var postSqlOrganization = await sqlOrganizationSponsorshipRepo.CreateAsync(postOrganizationSponsorship);
|
||||
replaceOrganizationSponsorship.Id = postSqlOrganization.Id;
|
||||
await sqlOrganizationSponsorshipRepo.ReplaceAsync(replaceOrganizationSponsorship);
|
||||
savedOrganizationSponsorships.Add(await sqlOrganizationSponsorshipRepo.GetByIdAsync(replaceOrganizationSponsorship.Id));
|
||||
|
||||
var distinctItems = savedOrganizationSponsorships.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);
|
||||
postOrganizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;
|
||||
|
||||
var postSqlOrganization = await sqlOrganizationSponsorshipRepo.CreateAsync(postOrganizationSponsorship);
|
||||
replaceOrganizationSponsorship.Id = postSqlOrganization.Id;
|
||||
await sqlOrganizationSponsorshipRepo.ReplaceAsync(replaceOrganizationSponsorship);
|
||||
savedOrganizationSponsorships.Add(await sqlOrganizationSponsorshipRepo.GetByIdAsync(replaceOrganizationSponsorship.Id));
|
||||
|
||||
var distinctItems = savedOrganizationSponsorships.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationSponsorshipAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(OrganizationSponsorship organizationSponsorship,
|
||||
Organization sponsoringOrg,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
|
||||
List<EfRepo.OrganizationSponsorshipRepository> suts)
|
||||
{
|
||||
organizationSponsorship.SponsoredOrganizationId = null;
|
||||
|
||||
foreach (var (sut, orgRepo) in suts.Zip(efOrgRepos))
|
||||
[CiSkippedTheory, EfOrganizationSponsorshipAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(OrganizationSponsorship organizationSponsorship,
|
||||
Organization sponsoringOrg,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
|
||||
List<EfRepo.OrganizationSponsorshipRepository> suts)
|
||||
{
|
||||
var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);
|
||||
sut.ClearChangeTracking();
|
||||
organizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
organizationSponsorship.SponsoredOrganizationId = null;
|
||||
|
||||
var postEfOrganizationSponsorship = await sut.CreateAsync(organizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var (sut, orgRepo) in suts.Zip(efOrgRepos))
|
||||
{
|
||||
var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);
|
||||
sut.ClearChangeTracking();
|
||||
organizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;
|
||||
|
||||
var savedEfOrganizationSponsorship = await sut.GetByIdAsync(postEfOrganizationSponsorship.Id);
|
||||
sut.ClearChangeTracking();
|
||||
Assert.True(savedEfOrganizationSponsorship != null);
|
||||
var postEfOrganizationSponsorship = await sut.CreateAsync(organizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfOrganizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrganizationSponsorship = await sut.GetByIdAsync(postEfOrganizationSponsorship.Id);
|
||||
sut.ClearChangeTracking();
|
||||
Assert.True(savedEfOrganizationSponsorship != null);
|
||||
|
||||
savedEfOrganizationSponsorship = await sut.GetByIdAsync(savedEfOrganizationSponsorship.Id);
|
||||
Assert.True(savedEfOrganizationSponsorship == null);
|
||||
await sut.DeleteAsync(savedEfOrganizationSponsorship);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
savedEfOrganizationSponsorship = await sut.GetByIdAsync(savedEfOrganizationSponsorship.Id);
|
||||
Assert.True(savedEfOrganizationSponsorship == null);
|
||||
}
|
||||
|
||||
var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);
|
||||
organizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;
|
||||
|
||||
var postSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.CreateAsync(organizationSponsorship);
|
||||
var savedSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.GetByIdAsync(postSqlOrganizationSponsorship.Id);
|
||||
Assert.True(savedSqlOrganizationSponsorship != null);
|
||||
|
||||
await sqlOrganizationSponsorshipRepo.DeleteAsync(postSqlOrganizationSponsorship);
|
||||
savedSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.GetByIdAsync(postSqlOrganizationSponsorship.Id);
|
||||
Assert.True(savedSqlOrganizationSponsorship == null);
|
||||
}
|
||||
|
||||
var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);
|
||||
organizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;
|
||||
|
||||
var postSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.CreateAsync(organizationSponsorship);
|
||||
var savedSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.GetByIdAsync(postSqlOrganizationSponsorship.Id);
|
||||
Assert.True(savedSqlOrganizationSponsorship != null);
|
||||
|
||||
await sqlOrganizationSponsorshipRepo.DeleteAsync(postSqlOrganizationSponsorship);
|
||||
savedSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.GetByIdAsync(postSqlOrganizationSponsorship.Id);
|
||||
Assert.True(savedSqlOrganizationSponsorship == null);
|
||||
}
|
||||
}
|
||||
|
@ -7,141 +7,142 @@ using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using OrganizationUser = Bit.Core.Entities.OrganizationUser;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class OrganizationUserRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(OrganizationUser orgUser, User user, Organization org,
|
||||
OrganizationUserCompare equalityComparer, List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
public class OrganizationUserRepositoryTests
|
||||
{
|
||||
var savedOrgUsers = new List<OrganizationUser>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(OrganizationUser orgUser, User user, Organization org,
|
||||
OrganizationUserCompare equalityComparer, List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var savedOrgUsers = new List<OrganizationUser>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
orgUser.UserId = postEfUser.Id;
|
||||
orgUser.OrganizationId = postEfOrg.Id;
|
||||
var postEfOrgUser = await sut.CreateAsync(orgUser);
|
||||
sut.ClearChangeTracking();
|
||||
orgUser.UserId = postEfUser.Id;
|
||||
orgUser.OrganizationId = postEfOrg.Id;
|
||||
var postEfOrgUser = await sut.CreateAsync(orgUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedOrgUser = await sut.GetByIdAsync(postEfOrgUser.Id);
|
||||
savedOrgUsers.Add(savedOrgUser);
|
||||
var savedOrgUser = await sut.GetByIdAsync(postEfOrgUser.Id);
|
||||
savedOrgUsers.Add(savedOrgUser);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var postSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
orgUser.UserId = postSqlUser.Id;
|
||||
orgUser.OrganizationId = postSqlOrg.Id;
|
||||
var sqlOrgUser = await sqlOrgUserRepo.CreateAsync(orgUser);
|
||||
|
||||
var savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(sqlOrgUser.Id);
|
||||
savedOrgUsers.Add(savedSqlOrgUser);
|
||||
|
||||
var distinctItems = savedOrgUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var postSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
orgUser.UserId = postSqlUser.Id;
|
||||
orgUser.OrganizationId = postSqlOrg.Id;
|
||||
var sqlOrgUser = await sqlOrgUserRepo.CreateAsync(orgUser);
|
||||
|
||||
var savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(sqlOrgUser.Id);
|
||||
savedOrgUsers.Add(savedSqlOrgUser);
|
||||
|
||||
var distinctItems = savedOrgUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(
|
||||
OrganizationUser postOrgUser,
|
||||
OrganizationUser replaceOrgUser,
|
||||
User user,
|
||||
Organization org,
|
||||
OrganizationUserCompare equalityComparer,
|
||||
List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
var savedOrgUsers = new List<OrganizationUser>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(
|
||||
OrganizationUser postOrgUser,
|
||||
OrganizationUser replaceOrgUser,
|
||||
User user,
|
||||
Organization org,
|
||||
OrganizationUserCompare equalityComparer,
|
||||
List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var savedOrgUsers = new List<OrganizationUser>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
postOrgUser.UserId = replaceOrgUser.UserId = postEfUser.Id;
|
||||
postOrgUser.OrganizationId = replaceOrgUser.OrganizationId = postEfOrg.Id;
|
||||
var postEfOrgUser = await sut.CreateAsync(postOrgUser);
|
||||
sut.ClearChangeTracking();
|
||||
postOrgUser.UserId = replaceOrgUser.UserId = postEfUser.Id;
|
||||
postOrgUser.OrganizationId = replaceOrgUser.OrganizationId = postEfOrg.Id;
|
||||
var postEfOrgUser = await sut.CreateAsync(postOrgUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
replaceOrgUser.Id = postOrgUser.Id;
|
||||
await sut.ReplaceAsync(replaceOrgUser);
|
||||
sut.ClearChangeTracking();
|
||||
replaceOrgUser.Id = postOrgUser.Id;
|
||||
await sut.ReplaceAsync(replaceOrgUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedOrganizationUser = await sut.GetByIdAsync(replaceOrgUser.Id);
|
||||
savedOrgUsers.Add(replacedOrganizationUser);
|
||||
var replacedOrganizationUser = await sut.GetByIdAsync(replaceOrgUser.Id);
|
||||
savedOrgUsers.Add(replacedOrganizationUser);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var postSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
postOrgUser.UserId = replaceOrgUser.UserId = postSqlUser.Id;
|
||||
postOrgUser.OrganizationId = replaceOrgUser.OrganizationId = postSqlOrg.Id;
|
||||
var postSqlOrgUser = await sqlOrgUserRepo.CreateAsync(postOrgUser);
|
||||
|
||||
replaceOrgUser.Id = postSqlOrgUser.Id;
|
||||
await sqlOrgUserRepo.ReplaceAsync(replaceOrgUser);
|
||||
|
||||
var replacedSqlUser = await sqlOrgUserRepo.GetByIdAsync(replaceOrgUser.Id);
|
||||
|
||||
var distinctItems = savedOrgUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var postSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
postOrgUser.UserId = replaceOrgUser.UserId = postSqlUser.Id;
|
||||
postOrgUser.OrganizationId = replaceOrgUser.OrganizationId = postSqlOrg.Id;
|
||||
var postSqlOrgUser = await sqlOrgUserRepo.CreateAsync(postOrgUser);
|
||||
|
||||
replaceOrgUser.Id = postSqlOrgUser.Id;
|
||||
await sqlOrgUserRepo.ReplaceAsync(replaceOrgUser);
|
||||
|
||||
var replacedSqlUser = await sqlOrgUserRepo.GetByIdAsync(replaceOrgUser.Id);
|
||||
|
||||
var distinctItems = savedOrgUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(OrganizationUser orgUser, User user, Organization org, List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(OrganizationUser orgUser, User user, Organization org, List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var postEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
orgUser.UserId = postEfUser.Id;
|
||||
orgUser.OrganizationId = postEfOrg.Id;
|
||||
var postEfOrgUser = await sut.CreateAsync(orgUser);
|
||||
sut.ClearChangeTracking();
|
||||
orgUser.UserId = postEfUser.Id;
|
||||
orgUser.OrganizationId = postEfOrg.Id;
|
||||
var postEfOrgUser = await sut.CreateAsync(orgUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfOrgUser = await sut.GetByIdAsync(postEfOrgUser.Id);
|
||||
Assert.True(savedEfOrgUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrgUser = await sut.GetByIdAsync(postEfOrgUser.Id);
|
||||
Assert.True(savedEfOrgUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfOrgUser);
|
||||
sut.ClearChangeTracking();
|
||||
await sut.DeleteAsync(savedEfOrgUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
savedEfOrgUser = await sut.GetByIdAsync(savedEfOrgUser.Id);
|
||||
Assert.True(savedEfOrgUser == null);
|
||||
savedEfOrgUser = await sut.GetByIdAsync(savedEfOrgUser.Id);
|
||||
Assert.True(savedEfOrgUser == null);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var postSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
orgUser.UserId = postSqlUser.Id;
|
||||
orgUser.OrganizationId = postSqlOrg.Id;
|
||||
var postSqlOrgUser = await sqlOrgUserRepo.CreateAsync(orgUser);
|
||||
|
||||
var savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(postSqlOrgUser.Id);
|
||||
Assert.True(savedSqlOrgUser != null);
|
||||
|
||||
await sqlOrgUserRepo.DeleteAsync(postSqlOrgUser);
|
||||
savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(postSqlOrgUser.Id);
|
||||
Assert.True(savedSqlOrgUser == null);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var postSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
orgUser.UserId = postSqlUser.Id;
|
||||
orgUser.OrganizationId = postSqlOrg.Id;
|
||||
var postSqlOrgUser = await sqlOrgUserRepo.CreateAsync(orgUser);
|
||||
|
||||
var savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(postSqlOrgUser.Id);
|
||||
Assert.True(savedSqlOrgUser != null);
|
||||
|
||||
await sqlOrgUserRepo.DeleteAsync(postSqlOrgUser);
|
||||
savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(postSqlOrgUser.Id);
|
||||
Assert.True(savedSqlOrgUser == null);
|
||||
}
|
||||
}
|
||||
|
@ -12,184 +12,185 @@ using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Policy = Bit.Core.Entities.Policy;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class PolicyRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfPolicyAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Policy policy,
|
||||
Organization organization,
|
||||
PolicyCompare equalityComparer,
|
||||
List<EfRepo.PolicyRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrganizationRepos,
|
||||
SqlRepo.PolicyRepository sqlPolicyRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo
|
||||
)
|
||||
public class PolicyRepositoryTests
|
||||
{
|
||||
var savedPolicys = new List<Policy>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfPolicyAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Policy policy,
|
||||
Organization organization,
|
||||
PolicyCompare equalityComparer,
|
||||
List<EfRepo.PolicyRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrganizationRepos,
|
||||
SqlRepo.PolicyRepository sqlPolicyRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedPolicys = new List<Policy>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
policy.OrganizationId = efOrganization.Id;
|
||||
var postEfPolicy = await sut.CreateAsync(policy);
|
||||
sut.ClearChangeTracking();
|
||||
policy.OrganizationId = efOrganization.Id;
|
||||
var postEfPolicy = await sut.CreateAsync(policy);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedPolicy = await sut.GetByIdAsync(postEfPolicy.Id);
|
||||
savedPolicys.Add(savedPolicy);
|
||||
var savedPolicy = await sut.GetByIdAsync(postEfPolicy.Id);
|
||||
savedPolicys.Add(savedPolicy);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
|
||||
policy.OrganizationId = sqlOrganization.Id;
|
||||
var sqlPolicy = await sqlPolicyRepo.CreateAsync(policy);
|
||||
var savedSqlPolicy = await sqlPolicyRepo.GetByIdAsync(sqlPolicy.Id);
|
||||
savedPolicys.Add(savedSqlPolicy);
|
||||
|
||||
var distinctItems = savedPolicys.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
||||
[CiSkippedTheory]
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, true, true, false)] // Ordinary user
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Invited, true, true, true, false)] // Invited user
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.Owner, false, OrganizationUserStatusType.Confirmed, false, true, true, false)] // Owner
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.Admin, false, OrganizationUserStatusType.Confirmed, false, true, true, false)] // Admin
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, true, OrganizationUserStatusType.Confirmed, false, true, true, false)] // canManagePolicies
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, true, true, true)] // Provider
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, false, true, false)] // Policy disabled
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, true, false, false)] // No policy of Type
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Invited, false, true, true, false)] // User not minStatus
|
||||
|
||||
policy.OrganizationId = sqlOrganization.Id;
|
||||
var sqlPolicy = await sqlPolicyRepo.CreateAsync(policy);
|
||||
var savedSqlPolicy = await sqlPolicyRepo.GetByIdAsync(sqlPolicy.Id);
|
||||
savedPolicys.Add(savedSqlPolicy);
|
||||
public async void GetManyByTypeApplicableToUser_Works_DataMatches(
|
||||
// Inline data
|
||||
OrganizationUserType userType,
|
||||
bool canManagePolicies,
|
||||
OrganizationUserStatusType orgUserStatus,
|
||||
bool includeInvited,
|
||||
bool policyEnabled,
|
||||
bool policySameType,
|
||||
bool isProvider,
|
||||
|
||||
var distinctItems = savedPolicys.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
// Auto data - models
|
||||
Policy policy,
|
||||
User user,
|
||||
Organization organization,
|
||||
OrganizationUser orgUser,
|
||||
Provider provider,
|
||||
ProviderOrganization providerOrganization,
|
||||
ProviderUser providerUser,
|
||||
PolicyCompareIncludingOrganization equalityComparer,
|
||||
|
||||
[CiSkippedTheory]
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, true, true, false)] // Ordinary user
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Invited, true, true, true, false)] // Invited user
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.Owner, false, OrganizationUserStatusType.Confirmed, false, true, true, false)] // Owner
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.Admin, false, OrganizationUserStatusType.Confirmed, false, true, true, false)] // Admin
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, true, OrganizationUserStatusType.Confirmed, false, true, true, false)] // canManagePolicies
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, true, true, true)] // Provider
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, false, true, false)] // Policy disabled
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Confirmed, false, true, false, false)] // No policy of Type
|
||||
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Invited, false, true, true, false)] // User not minStatus
|
||||
// Auto data - EF repos
|
||||
List<EfRepo.PolicyRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepository,
|
||||
List<EfRepo.OrganizationRepository> efOrganizationRepository,
|
||||
List<EfRepo.OrganizationUserRepository> efOrganizationUserRepository,
|
||||
List<EfRepo.ProviderRepository> efProviderRepository,
|
||||
List<EfRepo.ProviderOrganizationRepository> efProviderOrganizationRepository,
|
||||
List<EfRepo.ProviderUserRepository> efProviderUserRepository,
|
||||
|
||||
public async void GetManyByTypeApplicableToUser_Works_DataMatches(
|
||||
// Inline data
|
||||
OrganizationUserType userType,
|
||||
bool canManagePolicies,
|
||||
OrganizationUserStatusType orgUserStatus,
|
||||
bool includeInvited,
|
||||
bool policyEnabled,
|
||||
bool policySameType,
|
||||
bool isProvider,
|
||||
|
||||
// Auto data - models
|
||||
Policy policy,
|
||||
User user,
|
||||
Organization organization,
|
||||
OrganizationUser orgUser,
|
||||
Provider provider,
|
||||
ProviderOrganization providerOrganization,
|
||||
ProviderUser providerUser,
|
||||
PolicyCompareIncludingOrganization equalityComparer,
|
||||
|
||||
// Auto data - EF repos
|
||||
List<EfRepo.PolicyRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepository,
|
||||
List<EfRepo.OrganizationRepository> efOrganizationRepository,
|
||||
List<EfRepo.OrganizationUserRepository> efOrganizationUserRepository,
|
||||
List<EfRepo.ProviderRepository> efProviderRepository,
|
||||
List<EfRepo.ProviderOrganizationRepository> efProviderOrganizationRepository,
|
||||
List<EfRepo.ProviderUserRepository> efProviderUserRepository,
|
||||
|
||||
// Auto data - SQL repos
|
||||
SqlRepo.PolicyRepository sqlPolicyRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.ProviderRepository sqlProviderRepo,
|
||||
SqlRepo.OrganizationUserRepository sqlOrganizationUserRepo,
|
||||
SqlRepo.ProviderOrganizationRepository sqlProviderOrganizationRepo,
|
||||
SqlRepo.ProviderUserRepository sqlProviderUserRepo
|
||||
)
|
||||
{
|
||||
// Combine EF and SQL repos into one list per type
|
||||
var policyRepos = suts.ToList<IPolicyRepository>();
|
||||
policyRepos.Add(sqlPolicyRepo);
|
||||
var userRepos = efUserRepository.ToList<IUserRepository>();
|
||||
userRepos.Add(sqlUserRepo);
|
||||
var orgRepos = efOrganizationRepository.ToList<IOrganizationRepository>();
|
||||
orgRepos.Add(sqlOrganizationRepo);
|
||||
var orgUserRepos = efOrganizationUserRepository.ToList<IOrganizationUserRepository>();
|
||||
orgUserRepos.Add(sqlOrganizationUserRepo);
|
||||
var providerRepos = efProviderRepository.ToList<IProviderRepository>();
|
||||
providerRepos.Add(sqlProviderRepo);
|
||||
var providerOrgRepos = efProviderOrganizationRepository.ToList<IProviderOrganizationRepository>();
|
||||
providerOrgRepos.Add(sqlProviderOrganizationRepo);
|
||||
var providerUserRepos = efProviderUserRepository.ToList<IProviderUserRepository>();
|
||||
providerUserRepos.Add(sqlProviderUserRepo);
|
||||
|
||||
// Arrange data
|
||||
var savedPolicyType = PolicyType.SingleOrg;
|
||||
var queriedPolicyType = policySameType ? savedPolicyType : PolicyType.DisableSend;
|
||||
|
||||
orgUser.Type = userType;
|
||||
orgUser.Status = orgUserStatus;
|
||||
var permissionsData = new Permissions { ManagePolicies = canManagePolicies };
|
||||
orgUser.Permissions = JsonSerializer.Serialize(permissionsData, new JsonSerializerOptions
|
||||
// Auto data - SQL repos
|
||||
SqlRepo.PolicyRepository sqlPolicyRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo,
|
||||
SqlRepo.ProviderRepository sqlProviderRepo,
|
||||
SqlRepo.OrganizationUserRepository sqlOrganizationUserRepo,
|
||||
SqlRepo.ProviderOrganizationRepository sqlProviderOrganizationRepo,
|
||||
SqlRepo.ProviderUserRepository sqlProviderUserRepo
|
||||
)
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
// Combine EF and SQL repos into one list per type
|
||||
var policyRepos = suts.ToList<IPolicyRepository>();
|
||||
policyRepos.Add(sqlPolicyRepo);
|
||||
var userRepos = efUserRepository.ToList<IUserRepository>();
|
||||
userRepos.Add(sqlUserRepo);
|
||||
var orgRepos = efOrganizationRepository.ToList<IOrganizationRepository>();
|
||||
orgRepos.Add(sqlOrganizationRepo);
|
||||
var orgUserRepos = efOrganizationUserRepository.ToList<IOrganizationUserRepository>();
|
||||
orgUserRepos.Add(sqlOrganizationUserRepo);
|
||||
var providerRepos = efProviderRepository.ToList<IProviderRepository>();
|
||||
providerRepos.Add(sqlProviderRepo);
|
||||
var providerOrgRepos = efProviderOrganizationRepository.ToList<IProviderOrganizationRepository>();
|
||||
providerOrgRepos.Add(sqlProviderOrganizationRepo);
|
||||
var providerUserRepos = efProviderUserRepository.ToList<IProviderUserRepository>();
|
||||
providerUserRepos.Add(sqlProviderUserRepo);
|
||||
|
||||
policy.Enabled = policyEnabled;
|
||||
policy.Type = savedPolicyType;
|
||||
// Arrange data
|
||||
var savedPolicyType = PolicyType.SingleOrg;
|
||||
var queriedPolicyType = policySameType ? savedPolicyType : PolicyType.DisableSend;
|
||||
|
||||
var results = new List<Policy>();
|
||||
|
||||
foreach (var policyRepo in policyRepos)
|
||||
{
|
||||
var i = policyRepos.IndexOf(policyRepo);
|
||||
|
||||
// Seed database
|
||||
var savedUser = await userRepos[i].CreateAsync(user);
|
||||
var savedOrg = await orgRepos[i].CreateAsync(organization);
|
||||
|
||||
// Invited orgUsers are not associated with an account yet, so they are identified by Email not UserId
|
||||
if (orgUserStatus == OrganizationUserStatusType.Invited)
|
||||
orgUser.Type = userType;
|
||||
orgUser.Status = orgUserStatus;
|
||||
var permissionsData = new Permissions { ManagePolicies = canManagePolicies };
|
||||
orgUser.Permissions = JsonSerializer.Serialize(permissionsData, new JsonSerializerOptions
|
||||
{
|
||||
orgUser.Email = savedUser.Email;
|
||||
orgUser.UserId = null;
|
||||
}
|
||||
else
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
|
||||
policy.Enabled = policyEnabled;
|
||||
policy.Type = savedPolicyType;
|
||||
|
||||
var results = new List<Policy>();
|
||||
|
||||
foreach (var policyRepo in policyRepos)
|
||||
{
|
||||
orgUser.UserId = savedUser.Id;
|
||||
var i = policyRepos.IndexOf(policyRepo);
|
||||
|
||||
// Seed database
|
||||
var savedUser = await userRepos[i].CreateAsync(user);
|
||||
var savedOrg = await orgRepos[i].CreateAsync(organization);
|
||||
|
||||
// Invited orgUsers are not associated with an account yet, so they are identified by Email not UserId
|
||||
if (orgUserStatus == OrganizationUserStatusType.Invited)
|
||||
{
|
||||
orgUser.Email = savedUser.Email;
|
||||
orgUser.UserId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
orgUser.UserId = savedUser.Id;
|
||||
}
|
||||
|
||||
orgUser.OrganizationId = savedOrg.Id;
|
||||
await orgUserRepos[i].CreateAsync(orgUser);
|
||||
|
||||
if (isProvider)
|
||||
{
|
||||
var savedProvider = await providerRepos[i].CreateAsync(provider);
|
||||
|
||||
providerOrganization.OrganizationId = savedOrg.Id;
|
||||
providerOrganization.ProviderId = savedProvider.Id;
|
||||
await providerOrgRepos[i].CreateAsync(providerOrganization);
|
||||
|
||||
providerUser.UserId = savedUser.Id;
|
||||
providerUser.ProviderId = savedProvider.Id;
|
||||
await providerUserRepos[i].CreateAsync(providerUser);
|
||||
}
|
||||
|
||||
policy.OrganizationId = savedOrg.Id;
|
||||
await policyRepo.CreateAsync(policy);
|
||||
if (suts.Contains(policyRepo))
|
||||
{
|
||||
(policyRepo as EfRepo.BaseEntityFrameworkRepository).ClearChangeTracking();
|
||||
}
|
||||
|
||||
var minStatus = includeInvited ? OrganizationUserStatusType.Invited : OrganizationUserStatusType.Accepted;
|
||||
|
||||
// Act
|
||||
var result = await policyRepo.GetManyByTypeApplicableToUserIdAsync(savedUser.Id, queriedPolicyType, minStatus);
|
||||
results.Add(result.FirstOrDefault());
|
||||
}
|
||||
|
||||
orgUser.OrganizationId = savedOrg.Id;
|
||||
await orgUserRepos[i].CreateAsync(orgUser);
|
||||
// Assert
|
||||
var distinctItems = results.Distinct(equalityComparer);
|
||||
|
||||
if (isProvider)
|
||||
{
|
||||
var savedProvider = await providerRepos[i].CreateAsync(provider);
|
||||
|
||||
providerOrganization.OrganizationId = savedOrg.Id;
|
||||
providerOrganization.ProviderId = savedProvider.Id;
|
||||
await providerOrgRepos[i].CreateAsync(providerOrganization);
|
||||
|
||||
providerUser.UserId = savedUser.Id;
|
||||
providerUser.ProviderId = savedProvider.Id;
|
||||
await providerUserRepos[i].CreateAsync(providerUser);
|
||||
}
|
||||
|
||||
policy.OrganizationId = savedOrg.Id;
|
||||
await policyRepo.CreateAsync(policy);
|
||||
if (suts.Contains(policyRepo))
|
||||
{
|
||||
(policyRepo as EfRepo.BaseEntityFrameworkRepository).ClearChangeTracking();
|
||||
}
|
||||
|
||||
var minStatus = includeInvited ? OrganizationUserStatusType.Invited : OrganizationUserStatusType.Accepted;
|
||||
|
||||
// Act
|
||||
var result = await policyRepo.GetManyByTypeApplicableToUserIdAsync(savedUser.Id, queriedPolicyType, minStatus);
|
||||
results.Add(result.FirstOrDefault());
|
||||
Assert.True(results.All(r => r == null) ||
|
||||
!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
// Assert
|
||||
var distinctItems = results.Distinct(equalityComparer);
|
||||
|
||||
Assert.True(results.All(r => r == null) ||
|
||||
!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -6,59 +6,60 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class SendRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfUserSendAutoData, EfOrganizationSendAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Send send,
|
||||
User user,
|
||||
Organization org,
|
||||
SendCompare equalityComparer,
|
||||
List<EfRepo.SendRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SendRepository sqlSendRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
public class SendRepositoryTests
|
||||
{
|
||||
var savedSends = new List<Send>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserSendAutoData, EfOrganizationSendAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Send send,
|
||||
User user,
|
||||
Organization org,
|
||||
SendCompare equalityComparer,
|
||||
List<EfRepo.SendRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SendRepository sqlSendRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedSends = new List<Send>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
if (send.OrganizationId.HasValue)
|
||||
{
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
send.OrganizationId = efOrg.Id;
|
||||
}
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
send.UserId = efUser.Id;
|
||||
var postEfSend = await sut.CreateAsync(send);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedSend = await sut.GetByIdAsync(postEfSend.Id);
|
||||
savedSends.Add(savedSend);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
if (send.OrganizationId.HasValue)
|
||||
{
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
send.OrganizationId = efOrg.Id;
|
||||
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
send.OrganizationId = sqlOrg.Id;
|
||||
}
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
send.UserId = efUser.Id;
|
||||
var postEfSend = await sut.CreateAsync(send);
|
||||
sut.ClearChangeTracking();
|
||||
send.UserId = sqlUser.Id;
|
||||
var sqlSend = await sqlSendRepo.CreateAsync(send);
|
||||
var savedSqlSend = await sqlSendRepo.GetByIdAsync(sqlSend.Id);
|
||||
savedSends.Add(savedSqlSend);
|
||||
|
||||
var savedSend = await sut.GetByIdAsync(postEfSend.Id);
|
||||
savedSends.Add(savedSend);
|
||||
var distinctItems = savedSends.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
if (send.OrganizationId.HasValue)
|
||||
{
|
||||
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
send.OrganizationId = sqlOrg.Id;
|
||||
}
|
||||
|
||||
send.UserId = sqlUser.Id;
|
||||
var sqlSend = await sqlSendRepo.CreateAsync(send);
|
||||
var savedSqlSend = await sqlSendRepo.GetByIdAsync(sqlSend.Id);
|
||||
savedSends.Add(savedSqlSend);
|
||||
|
||||
var distinctItems = savedSends.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -6,221 +6,222 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class SsoConfigRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
public class SsoConfigRepositoryTests
|
||||
{
|
||||
var savedSsoConfigs = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedSsoConfigs = new List<SsoConfig>();
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdAsync(ssoConfig.Id);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
savedSsoConfigs.Add(savedEfSsoConfig);
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdAsync(ssoConfig.Id);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
savedSsoConfigs.Add(savedEfSsoConfig);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var sqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(sqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
savedSsoConfigs.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = savedSsoConfigs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var sqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(sqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
savedSsoConfigs.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = savedSsoConfigs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(SsoConfig postSsoConfig, SsoConfig replaceSsoConfig,
|
||||
Organization org, SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var savedSsoConfigs = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(SsoConfig postSsoConfig, SsoConfig replaceSsoConfig,
|
||||
Organization org, SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedSsoConfigs = new List<SsoConfig>();
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
postSsoConfig.OrganizationId = replaceSsoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(postSsoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
replaceSsoConfig.Id = postEfSsoConfig.Id;
|
||||
savedSsoConfigs.Add(postEfSsoConfig);
|
||||
await sut.ReplaceAsync(replaceSsoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
postSsoConfig.OrganizationId = replaceSsoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(postSsoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedSsoConfig = await sut.GetByIdAsync(replaceSsoConfig.Id);
|
||||
Assert.True(replacedSsoConfig != null);
|
||||
savedSsoConfigs.Add(replacedSsoConfig);
|
||||
replaceSsoConfig.Id = postEfSsoConfig.Id;
|
||||
savedSsoConfigs.Add(postEfSsoConfig);
|
||||
await sut.ReplaceAsync(replaceSsoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedSsoConfig = await sut.GetByIdAsync(replaceSsoConfig.Id);
|
||||
Assert.True(replacedSsoConfig != null);
|
||||
savedSsoConfigs.Add(replacedSsoConfig);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
postSsoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(postSsoConfig);
|
||||
replaceSsoConfig.Id = postSqlSsoConfig.Id;
|
||||
savedSsoConfigs.Add(postSqlSsoConfig);
|
||||
|
||||
await sqlSsoConfigRepo.ReplaceAsync(replaceSsoConfig);
|
||||
var replacedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(replaceSsoConfig.Id);
|
||||
Assert.True(replacedSqlSsoConfig != null);
|
||||
savedSsoConfigs.Add(replacedSqlSsoConfig);
|
||||
|
||||
var distinctItems = savedSsoConfigs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(2).Any());
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
postSsoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(postSsoConfig);
|
||||
replaceSsoConfig.Id = postSqlSsoConfig.Id;
|
||||
savedSsoConfigs.Add(postSqlSsoConfig);
|
||||
|
||||
await sqlSsoConfigRepo.ReplaceAsync(replaceSsoConfig);
|
||||
var replacedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(replaceSsoConfig.Id);
|
||||
Assert.True(replacedSqlSsoConfig != null);
|
||||
savedSsoConfigs.Add(replacedSqlSsoConfig);
|
||||
|
||||
var distinctItems = savedSsoConfigs.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(2).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoConfig = await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdAsync(postEfSsoConfig.Id);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfSsoConfig = await sut.GetByIdAsync(postEfSsoConfig.Id);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfSsoConfig);
|
||||
var deletedEfSsoConfig = await sut.GetByIdAsync(savedEfSsoConfig.Id);
|
||||
Assert.True(deletedEfSsoConfig == null);
|
||||
await sut.DeleteAsync(savedEfSsoConfig);
|
||||
var deletedEfSsoConfig = await sut.GetByIdAsync(savedEfSsoConfig.Id);
|
||||
Assert.True(deletedEfSsoConfig == null);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
|
||||
await sqlSsoConfigRepo.DeleteAsync(savedSqlSsoConfig);
|
||||
savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig == null);
|
||||
}
|
||||
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
|
||||
await sqlSsoConfigRepo.DeleteAsync(savedSqlSsoConfig);
|
||||
savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);
|
||||
Assert.True(savedSqlSsoConfig == null);
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetByOrganizationIdAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var returnedList = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetByOrganizationIdAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var returnedList = new List<SsoConfig>();
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfUser = await sut.GetByOrganizationIdAsync(savedEfOrg.Id);
|
||||
Assert.True(savedEfUser != null);
|
||||
returnedList.Add(savedEfUser);
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfUser = await sut.GetByOrganizationIdAsync(savedEfOrg.Id);
|
||||
Assert.True(savedEfUser != null);
|
||||
returnedList.Add(savedEfUser);
|
||||
}
|
||||
|
||||
var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = savedSqlOrg.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByOrganizationIdAsync(ssoConfig.OrganizationId);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
returnedList.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = savedSqlOrg.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByOrganizationIdAsync(ssoConfig.OrganizationId);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
returnedList.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetByIdentifierAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var returnedList = new List<SsoConfig>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetByIdentifierAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var returnedList = new List<SsoConfig>();
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdentifierAsync(org.Identifier);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
returnedList.Add(savedEfSsoConfig);
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoConfig = await sut.GetByIdentifierAsync(org.Identifier);
|
||||
Assert.True(savedEfSsoConfig != null);
|
||||
returnedList.Add(savedEfSsoConfig);
|
||||
}
|
||||
|
||||
var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = savedSqlOrg.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdentifierAsync(org.Identifier);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
returnedList.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoConfig.OrganizationId = savedSqlOrg.Id;
|
||||
|
||||
var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);
|
||||
|
||||
var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdentifierAsync(org.Identifier);
|
||||
Assert.True(savedSqlSsoConfig != null);
|
||||
returnedList.Add(savedSqlSsoConfig);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
// Testing that data matches here would involve manipulating all SsoConfig records in the db
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetManyByRevisionNotBeforeDate_Works(SsoConfig ssoConfig, DateTime notBeforeDate,
|
||||
Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
// Testing that data matches here would involve manipulating all SsoConfig records in the db
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetManyByRevisionNotBeforeDate_Works(SsoConfig ssoConfig, DateTime notBeforeDate,
|
||||
Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
ssoConfig.OrganizationId = savedEfOrg.Id;
|
||||
await sut.CreateAsync(ssoConfig);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var returnedEfSsoConfigs = await sut.GetManyByRevisionNotBeforeDate(notBeforeDate);
|
||||
Assert.True(returnedEfSsoConfigs.All(sc => sc.RevisionDate >= notBeforeDate));
|
||||
var returnedEfSsoConfigs = await sut.GetManyByRevisionNotBeforeDate(notBeforeDate);
|
||||
Assert.True(returnedEfSsoConfigs.All(sc => sc.RevisionDate >= notBeforeDate));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,181 +6,182 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class SsoUserRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(SsoUser ssoUser, User user, Organization org,
|
||||
SsoUserCompare equalityComparer, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
public class SsoUserRepositoryTests
|
||||
{
|
||||
var createdSsoUsers = new List<SsoUser>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(SsoUser ssoUser, User user, Organization org,
|
||||
SsoUserCompare equalityComparer, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var createdSsoUsers = new List<SsoUser>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = efUser.Id;
|
||||
ssoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
ssoUser.UserId = efUser.Id;
|
||||
ssoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedSsoUser = await sut.GetByIdAsync(ssoUser.Id);
|
||||
createdSsoUsers.Add(savedSsoUser);
|
||||
var savedSsoUser = await sut.GetByIdAsync(ssoUser.Id);
|
||||
createdSsoUsers.Add(savedSsoUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
var sqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
|
||||
createdSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(sqlSsoUser.Id));
|
||||
|
||||
var distinctSsoUsers = createdSsoUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctSsoUsers.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
var sqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
|
||||
createdSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(sqlSsoUser.Id));
|
||||
|
||||
var distinctSsoUsers = createdSsoUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctSsoUsers.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(SsoUser postSsoUser, SsoUser replaceSsoUser,
|
||||
Organization org, User user, SsoUserCompare equalityComparer,
|
||||
List<EfRepo.SsoUserRepository> suts, List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedSsoUsers = new List<SsoUser>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(SsoUser postSsoUser, SsoUser replaceSsoUser,
|
||||
Organization org, User user, SsoUserCompare equalityComparer,
|
||||
List<EfRepo.SsoUserRepository> suts, List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var savedSsoUsers = new List<SsoUser>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
postSsoUser.UserId = efUser.Id;
|
||||
postSsoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(postSsoUser);
|
||||
sut.ClearChangeTracking();
|
||||
postSsoUser.UserId = efUser.Id;
|
||||
postSsoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(postSsoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
replaceSsoUser.Id = postEfSsoUser.Id;
|
||||
replaceSsoUser.UserId = postEfSsoUser.UserId;
|
||||
replaceSsoUser.OrganizationId = postEfSsoUser.OrganizationId;
|
||||
await sut.ReplaceAsync(replaceSsoUser);
|
||||
sut.ClearChangeTracking();
|
||||
replaceSsoUser.Id = postEfSsoUser.Id;
|
||||
replaceSsoUser.UserId = postEfSsoUser.UserId;
|
||||
replaceSsoUser.OrganizationId = postEfSsoUser.OrganizationId;
|
||||
await sut.ReplaceAsync(replaceSsoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedSsoUser = await sut.GetByIdAsync(replaceSsoUser.Id);
|
||||
savedSsoUsers.Add(replacedSsoUser);
|
||||
var replacedSsoUser = await sut.GetByIdAsync(replaceSsoUser.Id);
|
||||
savedSsoUsers.Add(replacedSsoUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
postSsoUser.UserId = sqlUser.Id;
|
||||
postSsoUser.OrganizationId = sqlOrganization.Id;
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(postSsoUser);
|
||||
|
||||
replaceSsoUser.Id = postSqlSsoUser.Id;
|
||||
replaceSsoUser.UserId = postSqlSsoUser.UserId;
|
||||
replaceSsoUser.OrganizationId = postSqlSsoUser.OrganizationId;
|
||||
await sqlSsoUserRepo.ReplaceAsync(replaceSsoUser);
|
||||
|
||||
savedSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(replaceSsoUser.Id));
|
||||
|
||||
var distinctItems = savedSsoUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
postSsoUser.UserId = sqlUser.Id;
|
||||
postSsoUser.OrganizationId = sqlOrganization.Id;
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(postSsoUser);
|
||||
|
||||
replaceSsoUser.Id = postSqlSsoUser.Id;
|
||||
replaceSsoUser.UserId = postSqlSsoUser.UserId;
|
||||
replaceSsoUser.OrganizationId = postSqlSsoUser.OrganizationId;
|
||||
await sqlSsoUserRepo.ReplaceAsync(replaceSsoUser);
|
||||
|
||||
savedSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(replaceSsoUser.Id));
|
||||
|
||||
var distinctItems = savedSsoUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoUser ssoUser, Organization org, User user, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoUser ssoUser, Organization org, User user, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = savedEfUser.Id;
|
||||
ssoUser.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
ssoUser.UserId = savedEfUser.Id;
|
||||
ssoUser.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoUser = await sut.GetByIdAsync(postEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfSsoUser = await sut.GetByIdAsync(postEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfSsoUser);
|
||||
savedEfSsoUser = await sut.GetByIdAsync(savedEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser == null);
|
||||
await sut.DeleteAsync(savedEfSsoUser);
|
||||
savedEfSsoUser = await sut.GetByIdAsync(savedEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser == null);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
var savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser != null);
|
||||
|
||||
await sqlSsoUserRepo.DeleteAsync(savedSqlSsoUser);
|
||||
savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser == null);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
var savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser != null);
|
||||
|
||||
await sqlSsoUserRepo.DeleteAsync(savedSqlSsoUser);
|
||||
savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser == null);
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_UserIdOrganizationId_Works_DataMatches(SsoUser ssoUser,
|
||||
User user, Organization org, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_UserIdOrganizationId_Works_DataMatches(SsoUser ssoUser,
|
||||
User user, Organization org, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var savedEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = savedEfUser.Id;
|
||||
ssoUser.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
ssoUser.UserId = savedEfUser.Id;
|
||||
ssoUser.OrganizationId = savedEfOrg.Id;
|
||||
var postEfSsoUser = await sut.CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfSsoUser = await sut.GetByIdAsync(postEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfSsoUser = await sut.GetByIdAsync(postEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfSsoUser.UserId, savedEfSsoUser.OrganizationId);
|
||||
sut.ClearChangeTracking();
|
||||
await sut.DeleteAsync(savedEfSsoUser.UserId, savedEfSsoUser.OrganizationId);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
savedEfSsoUser = await sut.GetByIdAsync(savedEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser == null);
|
||||
savedEfSsoUser = await sut.GetByIdAsync(savedEfSsoUser.Id);
|
||||
Assert.True(savedEfSsoUser == null);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
var savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser != null);
|
||||
|
||||
await sqlSsoUserRepo.DeleteAsync(savedSqlSsoUser.UserId, savedSqlSsoUser.OrganizationId);
|
||||
savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser == null);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
var savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser != null);
|
||||
|
||||
await sqlSsoUserRepo.DeleteAsync(savedSqlSsoUser.UserId, savedSqlSsoUser.OrganizationId);
|
||||
savedSqlSsoUser = await sqlSsoUserRepo.GetByIdAsync(postSqlSsoUser.Id);
|
||||
Assert.True(savedSqlSsoUser == null);
|
||||
}
|
||||
}
|
||||
|
@ -6,34 +6,35 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class TaxRateRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfTaxRateAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
TaxRate taxRate,
|
||||
TaxRateCompare equalityComparer,
|
||||
List<EfRepo.TaxRateRepository> suts,
|
||||
SqlRepo.TaxRateRepository sqlTaxRateRepo
|
||||
)
|
||||
public class TaxRateRepositoryTests
|
||||
{
|
||||
var savedTaxRates = new List<TaxRate>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfTaxRateAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
TaxRate taxRate,
|
||||
TaxRateCompare equalityComparer,
|
||||
List<EfRepo.TaxRateRepository> suts,
|
||||
SqlRepo.TaxRateRepository sqlTaxRateRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfTaxRate = await sut.CreateAsync(taxRate);
|
||||
sut.ClearChangeTracking();
|
||||
var savedTaxRates = new List<TaxRate>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var postEfTaxRate = await sut.CreateAsync(taxRate);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedTaxRate = await sut.GetByIdAsync(postEfTaxRate.Id);
|
||||
savedTaxRates.Add(savedTaxRate);
|
||||
var savedTaxRate = await sut.GetByIdAsync(postEfTaxRate.Id);
|
||||
savedTaxRates.Add(savedTaxRate);
|
||||
}
|
||||
|
||||
var sqlTaxRate = await sqlTaxRateRepo.CreateAsync(taxRate);
|
||||
var savedSqlTaxRate = await sqlTaxRateRepo.GetByIdAsync(sqlTaxRate.Id);
|
||||
savedTaxRates.Add(savedSqlTaxRate);
|
||||
|
||||
var distinctItems = savedTaxRates.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlTaxRate = await sqlTaxRateRepo.CreateAsync(taxRate);
|
||||
var savedSqlTaxRate = await sqlTaxRateRepo.GetByIdAsync(sqlTaxRate.Id);
|
||||
savedTaxRates.Add(savedSqlTaxRate);
|
||||
|
||||
var distinctItems = savedTaxRates.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -6,58 +6,59 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class TransactionRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
|
||||
[CiSkippedTheory, EfUserTransactionAutoData, EfOrganizationTransactionAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Transaction transaction,
|
||||
User user,
|
||||
Organization org,
|
||||
TransactionCompare equalityComparer,
|
||||
List<EfRepo.TransactionRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.TransactionRepository sqlTransactionRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
public class TransactionRepositoryTests
|
||||
{
|
||||
var savedTransactions = new List<Transaction>();
|
||||
foreach (var sut in suts)
|
||||
|
||||
[CiSkippedTheory, EfUserTransactionAutoData, EfOrganizationTransactionAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
Transaction transaction,
|
||||
User user,
|
||||
Organization org,
|
||||
TransactionCompare equalityComparer,
|
||||
List<EfRepo.TransactionRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.TransactionRepository sqlTransactionRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
var savedTransactions = new List<Transaction>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
var efUser = await efUserRepos[i].CreateAsync(user);
|
||||
if (transaction.OrganizationId.HasValue)
|
||||
{
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
transaction.OrganizationId = efOrg.Id;
|
||||
}
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
transaction.UserId = efUser.Id;
|
||||
var postEfTransaction = await sut.CreateAsync(transaction);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedTransaction = await sut.GetByIdAsync(postEfTransaction.Id);
|
||||
savedTransactions.Add(savedTransaction);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
if (transaction.OrganizationId.HasValue)
|
||||
{
|
||||
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
||||
transaction.OrganizationId = efOrg.Id;
|
||||
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
transaction.OrganizationId = sqlOrg.Id;
|
||||
}
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
transaction.UserId = efUser.Id;
|
||||
var postEfTransaction = await sut.CreateAsync(transaction);
|
||||
sut.ClearChangeTracking();
|
||||
transaction.UserId = sqlUser.Id;
|
||||
var sqlTransaction = await sqlTransactionRepo.CreateAsync(transaction);
|
||||
var savedSqlTransaction = await sqlTransactionRepo.GetByIdAsync(sqlTransaction.Id);
|
||||
savedTransactions.Add(savedSqlTransaction);
|
||||
|
||||
var savedTransaction = await sut.GetByIdAsync(postEfTransaction.Id);
|
||||
savedTransactions.Add(savedTransaction);
|
||||
var distinctItems = savedTransactions.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
if (transaction.OrganizationId.HasValue)
|
||||
{
|
||||
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
||||
transaction.OrganizationId = sqlOrg.Id;
|
||||
}
|
||||
|
||||
transaction.UserId = sqlUser.Id;
|
||||
var sqlTransaction = await sqlTransactionRepo.CreateAsync(transaction);
|
||||
var savedSqlTransaction = await sqlTransactionRepo.GetByIdAsync(sqlTransaction.Id);
|
||||
savedTransactions.Add(savedSqlTransaction);
|
||||
|
||||
var distinctItems = savedTransactions.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
@ -7,283 +7,284 @@ using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
|
||||
|
||||
public class UserRepositoryTests
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
|
||||
{
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
User user, UserCompare equalityComparer,
|
||||
List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo
|
||||
)
|
||||
public class UserRepositoryTests
|
||||
{
|
||||
var savedUsers = new List<User>();
|
||||
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void CreateAsync_Works_DataMatches(
|
||||
User user, UserCompare equalityComparer,
|
||||
List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo
|
||||
)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
var savedUsers = new List<User>();
|
||||
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
|
||||
var savedUser = await sut.GetByIdAsync(postEfUser.Id);
|
||||
savedUsers.Add(savedUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedUser = await sut.GetByIdAsync(postEfUser.Id);
|
||||
savedUsers.Add(savedUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
savedUsers.Add(await sqlUserRepo.GetByIdAsync(sqlUser.Id));
|
||||
|
||||
var distinctItems = savedUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
savedUsers.Add(await sqlUserRepo.GetByIdAsync(sqlUser.Id));
|
||||
|
||||
var distinctItems = savedUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(User postUser, User replaceUser,
|
||||
UserCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void ReplaceAsync_Works_DataMatches(User postUser, User replaceUser,
|
||||
UserCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(postUser);
|
||||
replaceUser.Id = postEfUser.Id;
|
||||
await sut.ReplaceAsync(replaceUser);
|
||||
var replacedUser = await sut.GetByIdAsync(replaceUser.Id);
|
||||
savedUsers.Add(replacedUser);
|
||||
var savedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(postUser);
|
||||
replaceUser.Id = postEfUser.Id;
|
||||
await sut.ReplaceAsync(replaceUser);
|
||||
var replacedUser = await sut.GetByIdAsync(replaceUser.Id);
|
||||
savedUsers.Add(replacedUser);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(postUser);
|
||||
replaceUser.Id = postSqlUser.Id;
|
||||
await sqlUserRepo.ReplaceAsync(replaceUser);
|
||||
savedUsers.Add(await sqlUserRepo.GetByIdAsync(replaceUser.Id));
|
||||
|
||||
var distinctItems = savedUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(postUser);
|
||||
replaceUser.Id = postSqlUser.Id;
|
||||
await sqlUserRepo.ReplaceAsync(replaceUser);
|
||||
savedUsers.Add(await sqlUserRepo.GetByIdAsync(replaceUser.Id));
|
||||
|
||||
var distinctItems = savedUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(User user, List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(User user, List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var savedEfUser = await sut.GetByIdAsync(postEfUser.Id);
|
||||
Assert.True(savedEfUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
var savedEfUser = await sut.GetByIdAsync(postEfUser.Id);
|
||||
Assert.True(savedEfUser != null);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.DeleteAsync(savedEfUser);
|
||||
sut.ClearChangeTracking();
|
||||
await sut.DeleteAsync(savedEfUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
savedEfUser = await sut.GetByIdAsync(savedEfUser.Id);
|
||||
Assert.True(savedEfUser == null);
|
||||
savedEfUser = await sut.GetByIdAsync(savedEfUser.Id);
|
||||
Assert.True(savedEfUser == null);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var savedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);
|
||||
Assert.True(savedSqlUser != null);
|
||||
|
||||
await sqlUserRepo.DeleteAsync(postSqlUser);
|
||||
savedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);
|
||||
Assert.True(savedSqlUser == null);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var savedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);
|
||||
Assert.True(savedSqlUser != null);
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetByEmailAsync_Works_DataMatches(User user, UserCompare equalityComparer,
|
||||
List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var savedUser = await sut.GetByEmailAsync(postEfUser.Email.ToUpperInvariant());
|
||||
savedUsers.Add(savedUser);
|
||||
}
|
||||
|
||||
await sqlUserRepo.DeleteAsync(postSqlUser);
|
||||
savedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);
|
||||
Assert.True(savedSqlUser == null);
|
||||
}
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
savedUsers.Add(await sqlUserRepo.GetByEmailAsync(postSqlUser.Email.ToUpperInvariant()));
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetByEmailAsync_Works_DataMatches(User user, UserCompare equalityComparer,
|
||||
var distinctItems = savedUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetKdfInformationByEmailAsync_Works_DataMatches(User user,
|
||||
UserKdfInformationCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedKdfInformation = new List<UserKdfInformation>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var kdfInformation = await sut.GetKdfInformationByEmailAsync(postEfUser.Email.ToUpperInvariant());
|
||||
savedKdfInformation.Add(kdfInformation);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlKdfInformation = await sqlUserRepo.GetKdfInformationByEmailAsync(postSqlUser.Email);
|
||||
savedKdfInformation.Add(sqlKdfInformation);
|
||||
|
||||
var distinctItems = savedKdfInformation.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void SearchAsync_Works_DataMatches(User user, int skip, int take,
|
||||
UserCompare equalityCompare, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var searchedEfUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var searchedEfUsersCollection = await sut.SearchAsync(postEfUser.Email.ToUpperInvariant(), skip, take);
|
||||
searchedEfUsers.Concat(searchedEfUsersCollection.ToList());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var searchedSqlUsers = await sqlUserRepo.SearchAsync(postSqlUser.Email.ToUpperInvariant(), skip, take);
|
||||
|
||||
var distinctItems = searchedEfUsers.Concat(searchedSqlUsers).Distinct(equalityCompare);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetManyByPremiumAsync_Works_DataMatches(User user,
|
||||
List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var savedUser = await sut.GetByEmailAsync(postEfUser.Email.ToUpperInvariant());
|
||||
savedUsers.Add(savedUser);
|
||||
var returnedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var searchedEfUsers = await sut.GetManyByPremiumAsync(user.Premium);
|
||||
returnedUsers.Concat(searchedEfUsers.ToList());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var searchedSqlUsers = await sqlUserRepo.GetManyByPremiumAsync(user.Premium);
|
||||
returnedUsers.Concat(searchedSqlUsers.ToList());
|
||||
|
||||
Assert.True(returnedUsers.All(x => x.Premium == user.Premium));
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
savedUsers.Add(await sqlUserRepo.GetByEmailAsync(postSqlUser.Email.ToUpperInvariant()));
|
||||
|
||||
var distinctItems = savedUsers.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetKdfInformationByEmailAsync_Works_DataMatches(User user,
|
||||
UserKdfInformationCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedKdfInformation = new List<UserKdfInformation>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetPublicKeyAsync_Works_DataMatches(User user, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var kdfInformation = await sut.GetKdfInformationByEmailAsync(postEfUser.Email.ToUpperInvariant());
|
||||
savedKdfInformation.Add(kdfInformation);
|
||||
var returnedKeys = new List<string>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var efKey = await sut.GetPublicKeyAsync(postEfUser.Id);
|
||||
returnedKeys.Add(efKey);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlKey = await sqlUserRepo.GetPublicKeyAsync(postSqlUser.Id);
|
||||
returnedKeys.Add(sqlKey);
|
||||
|
||||
Assert.True(!returnedKeys.Distinct().Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlKdfInformation = await sqlUserRepo.GetKdfInformationByEmailAsync(postSqlUser.Email);
|
||||
savedKdfInformation.Add(sqlKdfInformation);
|
||||
|
||||
var distinctItems = savedKdfInformation.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void SearchAsync_Works_DataMatches(User user, int skip, int take,
|
||||
UserCompare equalityCompare, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var searchedEfUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetAccountRevisionDateAsync(User user, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var returnedKeys = new List<string>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var searchedEfUsersCollection = await sut.SearchAsync(postEfUser.Email.ToUpperInvariant(), skip, take);
|
||||
searchedEfUsers.Concat(searchedEfUsersCollection.ToList());
|
||||
var efKey = await sut.GetPublicKeyAsync(postEfUser.Id);
|
||||
returnedKeys.Add(efKey);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlKey = await sqlUserRepo.GetPublicKeyAsync(postSqlUser.Id);
|
||||
returnedKeys.Add(sqlKey);
|
||||
|
||||
Assert.True(!returnedKeys.Distinct().Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var searchedSqlUsers = await sqlUserRepo.SearchAsync(postSqlUser.Email.ToUpperInvariant(), skip, take);
|
||||
|
||||
var distinctItems = searchedEfUsers.Concat(searchedSqlUsers).Distinct(equalityCompare);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetManyByPremiumAsync_Works_DataMatches(User user,
|
||||
List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var returnedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void UpdateRenewalReminderDateAsync_Works_DataMatches(User user,
|
||||
DateTime updatedReminderDate, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var savedDates = new List<DateTime?>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = user;
|
||||
postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var searchedEfUsers = await sut.GetManyByPremiumAsync(user.Premium);
|
||||
returnedUsers.Concat(searchedEfUsers.ToList());
|
||||
await sut.UpdateRenewalReminderDateAsync(postEfUser.Id, updatedReminderDate);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedUser = await sut.GetByIdAsync(postEfUser.Id);
|
||||
savedDates.Add(replacedUser.RenewalReminderDate);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
await sqlUserRepo.UpdateRenewalReminderDateAsync(postSqlUser.Id, updatedReminderDate);
|
||||
var replacedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);
|
||||
savedDates.Add(replacedSqlUser.RenewalReminderDate);
|
||||
|
||||
var distinctItems = savedDates.GroupBy(e => e.ToString());
|
||||
Assert.True(!distinctItems.Skip(1).Any() &&
|
||||
savedDates.All(e => e.ToString() == updatedReminderDate.ToString()));
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var searchedSqlUsers = await sqlUserRepo.GetManyByPremiumAsync(user.Premium);
|
||||
returnedUsers.Concat(searchedSqlUsers.ToList());
|
||||
|
||||
Assert.True(returnedUsers.All(x => x.Premium == user.Premium));
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetPublicKeyAsync_Works_DataMatches(User user, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var returnedKeys = new List<string>();
|
||||
foreach (var sut in suts)
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetBySsoUserAsync_Works_DataMatches(User user, Organization org,
|
||||
SsoUser ssoUser, UserCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
List<EfRepo.SsoUserRepository> ssoUserRepos, List<EfRepo.OrganizationRepository> orgRepos,
|
||||
SqlRepo.UserRepository sqlUserRepo, SqlRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
var returnedList = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var efKey = await sut.GetPublicKeyAsync(postEfUser.Id);
|
||||
returnedKeys.Add(efKey);
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var efOrg = await orgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = postEfUser.Id;
|
||||
ssoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await ssoUserRepos[i].CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var returnedUser = await sut.GetBySsoUserAsync(postEfSsoUser.ExternalId.ToUpperInvariant(), efOrg.Id);
|
||||
returnedList.Add(returnedUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
|
||||
var returnedSqlUser = await sqlUserRepo
|
||||
.GetBySsoUserAsync(postSqlSsoUser.ExternalId, sqlOrganization.Id);
|
||||
returnedList.Add(returnedSqlUser);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlKey = await sqlUserRepo.GetPublicKeyAsync(postSqlUser.Id);
|
||||
returnedKeys.Add(sqlKey);
|
||||
|
||||
Assert.True(!returnedKeys.Distinct().Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetAccountRevisionDateAsync(User user, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var returnedKeys = new List<string>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var efKey = await sut.GetPublicKeyAsync(postEfUser.Id);
|
||||
returnedKeys.Add(efKey);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlKey = await sqlUserRepo.GetPublicKeyAsync(postSqlUser.Id);
|
||||
returnedKeys.Add(sqlKey);
|
||||
|
||||
Assert.True(!returnedKeys.Distinct().Skip(1).Any());
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void UpdateRenewalReminderDateAsync_Works_DataMatches(User user,
|
||||
DateTime updatedReminderDate, List<EfRepo.UserRepository> suts,
|
||||
SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
var savedDates = new List<DateTime?>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var postEfUser = user;
|
||||
postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
await sut.UpdateRenewalReminderDateAsync(postEfUser.Id, updatedReminderDate);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var replacedUser = await sut.GetByIdAsync(postEfUser.Id);
|
||||
savedDates.Add(replacedUser.RenewalReminderDate);
|
||||
}
|
||||
|
||||
var postSqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
await sqlUserRepo.UpdateRenewalReminderDateAsync(postSqlUser.Id, updatedReminderDate);
|
||||
var replacedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);
|
||||
savedDates.Add(replacedSqlUser.RenewalReminderDate);
|
||||
|
||||
var distinctItems = savedDates.GroupBy(e => e.ToString());
|
||||
Assert.True(!distinctItems.Skip(1).Any() &&
|
||||
savedDates.All(e => e.ToString() == updatedReminderDate.ToString()));
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void GetBySsoUserAsync_Works_DataMatches(User user, Organization org,
|
||||
SsoUser ssoUser, UserCompare equalityComparer, List<EfRepo.UserRepository> suts,
|
||||
List<EfRepo.SsoUserRepository> ssoUserRepos, List<EfRepo.OrganizationRepository> orgRepos,
|
||||
SqlRepo.UserRepository sqlUserRepo, SqlRepo.SsoUserRepository sqlSsoUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
{
|
||||
var returnedList = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
var i = suts.IndexOf(sut);
|
||||
|
||||
var postEfUser = await sut.CreateAsync(user);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var efOrg = await orgRepos[i].CreateAsync(org);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
ssoUser.UserId = postEfUser.Id;
|
||||
ssoUser.OrganizationId = efOrg.Id;
|
||||
var postEfSsoUser = await ssoUserRepos[i].CreateAsync(ssoUser);
|
||||
sut.ClearChangeTracking();
|
||||
|
||||
var returnedUser = await sut.GetBySsoUserAsync(postEfSsoUser.ExternalId.ToUpperInvariant(), efOrg.Id);
|
||||
returnedList.Add(returnedUser);
|
||||
}
|
||||
|
||||
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
||||
var sqlOrganization = await sqlOrgRepo.CreateAsync(org);
|
||||
|
||||
ssoUser.UserId = sqlUser.Id;
|
||||
ssoUser.OrganizationId = sqlOrganization.Id;
|
||||
var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);
|
||||
|
||||
var returnedSqlUser = await sqlUserRepo
|
||||
.GetBySsoUserAsync(postSqlSsoUser.ExternalId, sqlOrganization.Id);
|
||||
returnedList.Add(returnedSqlUser);
|
||||
|
||||
var distinctItems = returnedList.Distinct(equalityComparer);
|
||||
Assert.True(!distinctItems.Skip(1).Any());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user