mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PM-3581] Fix Postgres Time (#3221)
* Fix Postgres Time - Migrate Send Tests - Delete Old Tests * Formatting * Update Comment * Change LaxComparer to Compare Some Milliseconds * Update Comment
This commit is contained in:
@ -1,71 +0,0 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using Bit.Core.Test.AutoFixture.UserFixtures;
|
||||
using Bit.Core.Tools.Entities;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.AutoFixture.Relays;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Tools.Repositories;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Tools.AutoFixture;
|
||||
|
||||
internal class SendBuilder : ISpecimenBuilder
|
||||
{
|
||||
public bool OrganizationOwned { get; set; }
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var type = request as Type;
|
||||
if (type == null || type != typeof(Send))
|
||||
{
|
||||
return new NoSpecimen();
|
||||
}
|
||||
|
||||
var fixture = new Fixture();
|
||||
fixture.Customizations.Insert(0, new MaxLengthStringRelay());
|
||||
if (!OrganizationOwned)
|
||||
{
|
||||
fixture.Customize<Send>(composer => composer
|
||||
.Without(c => c.OrganizationId));
|
||||
}
|
||||
var obj = fixture.WithAutoNSubstitutions().Create<Send>();
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfSend : ICustomization
|
||||
{
|
||||
public bool OrganizationOwned { get; set; }
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
||||
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
||||
fixture.Customizations.Add(new SendBuilder());
|
||||
fixture.Customizations.Add(new UserBuilder());
|
||||
fixture.Customizations.Add(new OrganizationBuilder());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<SendRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<UserRepository>());
|
||||
fixture.Customizations.Add(new EfRepositoryListBuilder<OrganizationRepository>());
|
||||
}
|
||||
}
|
||||
|
||||
internal class EfUserSendAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfUserSendAutoDataAttribute() : base(new SutProviderCustomization(), new EfSend())
|
||||
{ }
|
||||
}
|
||||
|
||||
internal class EfOrganizationSendAutoDataAttribute : CustomAutoDataAttribute
|
||||
{
|
||||
public EfOrganizationSendAutoDataAttribute() : base(new SutProviderCustomization(), new EfSend()
|
||||
{
|
||||
OrganizationOwned = true,
|
||||
})
|
||||
{ }
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Bit.Core.Tools.Entities;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Tools.Repositories.EqualityComparers;
|
||||
|
||||
public class SendCompare : IEqualityComparer<Send>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Test.AutoFixture.Attributes;
|
||||
using Bit.Core.Tools.Entities;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Tools.AutoFixture;
|
||||
using Bit.Infrastructure.EFIntegration.Test.Tools.Repositories.EqualityComparers;
|
||||
using Xunit;
|
||||
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using EfSendRepo = Bit.Infrastructure.EntityFramework.Tools.Repositories;
|
||||
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
||||
using SqlSendRepo = Bit.Infrastructure.Dapper.Tools.Repositories;
|
||||
|
||||
namespace Bit.Infrastructure.EFIntegration.Test.Tools.Repositories;
|
||||
|
||||
public class SendRepositoryTests
|
||||
{
|
||||
[CiSkippedTheory, EfUserSendAutoData, EfOrganizationSendAutoData]
|
||||
public async Task CreateAsync_Works_DataMatches(
|
||||
Send send,
|
||||
User user,
|
||||
Organization org,
|
||||
SendCompare equalityComparer,
|
||||
List<EfSendRepo.SendRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlSendRepo.SendRepository sqlSendRepo,
|
||||
SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
{
|
||||
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 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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user