1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-10 15:13:29 +01:00
bitwarden-server/test/Infrastructure.EFIntegration.Test/Repositories/DeviceRepositoryTests.cs
2022-08-29 16:06:55 -04:00

47 lines
1.6 KiB
C#

using Bit.Core.Entities;
using Bit.Core.Test.AutoFixture.Attributes;
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
using Xunit;
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
public class DeviceRepositoryTests
{
[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 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 postEfDevice = await sut.CreateAsync(device);
sut.ClearChangeTracking();
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());
}
}