diff --git a/.editorconfig b/.editorconfig index 828d0a7b3..40931fa5e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -114,7 +114,7 @@ csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true -# Namespace settigns +# Namespace settings csharp_style_namespace_declarations = file_scoped:warning # All files diff --git a/bitwarden_license/test/Commercial.Core.Test/Services/ProviderServiceTests.cs b/bitwarden_license/test/Commercial.Core.Test/Services/ProviderServiceTests.cs index 53911ea06..52da69186 100644 --- a/bitwarden_license/test/Commercial.Core.Test/Services/ProviderServiceTests.cs +++ b/bitwarden_license/test/Commercial.Core.Test/Services/ProviderServiceTests.cs @@ -21,9 +21,10 @@ using ProviderUser = Bit.Core.Entities.Provider.ProviderUser; namespace Bit.Commercial.Core.Test.Services; +[SutProviderCustomize] public class ProviderServiceTests { - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task CreateAsync_UserIdIsInvalid_Throws(SutProvider sutProvider) { var exception = await Assert.ThrowsAsync( @@ -31,7 +32,7 @@ public class ProviderServiceTests Assert.Contains("Invalid owner.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task CreateAsync_Success(User user, SutProvider sutProvider) { var userRepository = sutProvider.GetDependency(); @@ -43,7 +44,7 @@ public class ProviderServiceTests await sutProvider.GetDependency().ReceivedWithAnyArgs().SendProviderSetupInviteEmailAsync(default, default, default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task CompleteSetupAsync_UserIdIsInvalid_Throws(SutProvider sutProvider) { var exception = await Assert.ThrowsAsync( @@ -51,7 +52,7 @@ public class ProviderServiceTests Assert.Contains("Invalid owner.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task CompleteSetupAsync_TokenIsInvalid_Throws(User user, Provider provider, SutProvider sutProvider) { @@ -63,7 +64,7 @@ public class ProviderServiceTests Assert.Contains("Invalid token.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task CompleteSetupAsync_Success(User user, Provider provider, string key, [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser providerUser, SutProvider sutProvider) @@ -91,7 +92,7 @@ public class ProviderServiceTests .ReplaceAsync(Arg.Is(pu => pu.UserId == user.Id && pu.ProviderId == provider.Id && pu.Key == key)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateAsync_ProviderIdIsInvalid_Throws(Provider provider, SutProvider sutProvider) { provider.Id = default; @@ -101,13 +102,13 @@ public class ProviderServiceTests Assert.Contains("Cannot create provider this way.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateAsync_Success(Provider provider, SutProvider sutProvider) { await sutProvider.Sut.UpdateAsync(provider); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InviteUserAsync_ProviderIdIsInvalid_Throws(ProviderUserInvite invite, SutProvider sutProvider) { sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(true); @@ -115,14 +116,14 @@ public class ProviderServiceTests await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(invite)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InviteUserAsync_InvalidPermissions_Throws(ProviderUserInvite invite, SutProvider sutProvider) { sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(false); await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(invite)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InviteUserAsync_EmailsInvalid_Throws(Provider provider, ProviderUserInvite providerUserInvite, SutProvider sutProvider) { @@ -135,7 +136,7 @@ public class ProviderServiceTests await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(providerUserInvite)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InviteUserAsync_AlreadyInvited(Provider provider, ProviderUserInvite providerUserInvite, SutProvider sutProvider) { @@ -149,7 +150,7 @@ public class ProviderServiceTests Assert.Empty(result); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InviteUserAsync_Success(Provider provider, ProviderUserInvite providerUserInvite, SutProvider sutProvider) { @@ -165,14 +166,14 @@ public class ProviderServiceTests Assert.True(result.TrueForAll(pu => pu.ProviderId == providerUserInvite.ProviderId), "Provider Id must be correct"); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ResendInviteUserAsync_InvalidPermissions_Throws(ProviderUserInvite invite, SutProvider sutProvider) { sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(false); await Assert.ThrowsAsync(() => sutProvider.Sut.ResendInvitesAsync(invite)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ResendInvitesAsync_Errors(Provider provider, [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, @@ -202,7 +203,7 @@ public class ProviderServiceTests Assert.Equal("User invalid.", result[3].Item2); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ResendInvitesAsync_Success(Provider provider, IEnumerable providerUsers, SutProvider sutProvider) { @@ -228,7 +229,7 @@ public class ProviderServiceTests Assert.True(result.All(r => r.Item2 == "")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AcceptUserAsync_UserIsInvalid_Throws(SutProvider sutProvider) { var exception = await Assert.ThrowsAsync( @@ -236,7 +237,7 @@ public class ProviderServiceTests Assert.Equal("User invalid.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AcceptUserAsync_AlreadyAccepted_Throws( [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser providerUser, User user, SutProvider sutProvider) @@ -249,7 +250,7 @@ public class ProviderServiceTests Assert.Equal("Already accepted.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AcceptUserAsync_TokenIsInvalid_Throws( [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user, SutProvider sutProvider) @@ -262,7 +263,7 @@ public class ProviderServiceTests Assert.Equal("Invalid token.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AcceptUserAsync_WrongEmail_Throws( [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user, SutProvider sutProvider) @@ -283,7 +284,7 @@ public class ProviderServiceTests Assert.Equal("User email does not match invite.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AcceptUserAsync_Success( [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser providerUser, User user, SutProvider sutProvider) @@ -306,7 +307,7 @@ public class ProviderServiceTests Assert.Equal(user.Id, pu.UserId); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUsersAsync_NoValid( [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, @@ -324,7 +325,7 @@ public class ProviderServiceTests Assert.Empty(result); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUsersAsync_Success( [ProviderUser(ProviderUserStatusType.Invited)] ProviderUser pu1, User u1, [ProviderUser(ProviderUserStatusType.Accepted)] ProviderUser pu2, User u2, @@ -352,7 +353,7 @@ public class ProviderServiceTests Assert.Equal("Invalid user.", result[2].Item2); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveUserAsync_UserIdIsInvalid_Throws(ProviderUser providerUser, SutProvider sutProvider) { @@ -362,7 +363,7 @@ public class ProviderServiceTests Assert.Equal("Invite the user first.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveUserAsync_Success( [ProviderUser(type: ProviderUserType.ProviderAdmin)] ProviderUser providerUser, User savingUser, SutProvider sutProvider) @@ -376,7 +377,7 @@ public class ProviderServiceTests .LogProviderUserEventAsync(providerUser, EventType.ProviderUser_Updated, null); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsersAsync_NoRemainingOwner_Throws(Provider provider, User deletingUser, ICollection providerUsers, SutProvider sutProvider) { @@ -399,7 +400,7 @@ public class ProviderServiceTests Assert.Equal("Provider must have at least one confirmed ProviderAdmin.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsersAsync_Success(Provider provider, User deletingUser, ICollection providerUsers, [ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser remainingOwner, SutProvider sutProvider) @@ -426,7 +427,7 @@ public class ProviderServiceTests Assert.Equal("Invalid user.", result[2].Item2); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AddOrganization_OrganizationAlreadyBelongsToAProvider_Throws(Provider provider, Organization organization, ProviderOrganization po, User user, string key, SutProvider sutProvider) @@ -441,7 +442,7 @@ public class ProviderServiceTests Assert.Equal("Organization already belongs to a provider.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task AddOrganization_Success(Provider provider, Organization organization, User user, string key, SutProvider sutProvider) { @@ -460,7 +461,7 @@ public class ProviderServiceTests EventType.ProviderOrganization_Added); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task CreateOrganizationAsync_Success(Provider provider, OrganizationSignup organizationSignup, Organization organization, string clientOwnerEmail, User user, SutProvider sutProvider) { @@ -488,7 +489,7 @@ public class ProviderServiceTests t.First().Item2 == null)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task RemoveOrganization_ProviderOrganizationIsInvalid_Throws(Provider provider, ProviderOrganization providerOrganization, User user, SutProvider sutProvider) { @@ -501,7 +502,7 @@ public class ProviderServiceTests Assert.Equal("Invalid organization.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task RemoveOrganization_ProviderOrganizationBelongsToWrongProvider_Throws(Provider provider, ProviderOrganization providerOrganization, User user, SutProvider sutProvider) { @@ -514,7 +515,7 @@ public class ProviderServiceTests Assert.Equal("Invalid organization.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task RemoveOrganization_HasNoOwners_Throws(Provider provider, ProviderOrganization providerOrganization, User user, SutProvider sutProvider) { @@ -530,7 +531,7 @@ public class ProviderServiceTests Assert.Equal("Organization needs to have at least one confirmed owner.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task RemoveOrganization_Success(Provider provider, ProviderOrganization providerOrganization, User user, SutProvider sutProvider) { diff --git a/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs index fb16d2f90..b9a1c2f6a 100644 --- a/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/InlineCustomAutoDataAttribute.cs @@ -1,5 +1,4 @@ -using AutoFixture; -using AutoFixture.Xunit2; +using AutoFixture.Xunit2; using Xunit; using Xunit.Sdk; @@ -12,10 +11,4 @@ public class InlineCustomAutoDataAttribute : CompositeDataAttribute new CustomAutoDataAttribute(iCustomizationTypes) }) { } - - public InlineCustomAutoDataAttribute(ICustomization[] customizations, params object[] values) : base(new DataAttribute[] { - new InlineDataAttribute(values), - new CustomAutoDataAttribute(customizations) - }) - { } } diff --git a/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs deleted file mode 100644 index ae32b476c..000000000 --- a/test/Common/AutoFixture/Attributes/InlineSutAutoDataAttribute.cs +++ /dev/null @@ -1,17 +0,0 @@ -using AutoFixture; - -namespace Bit.Test.Common.AutoFixture.Attributes; - -public class InlineSutAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineSutAutoDataAttribute(params object[] values) : base( - new Type[] { typeof(SutProviderCustomization) }, values) - { } - public InlineSutAutoDataAttribute(Type[] iCustomizationTypes, params object[] values) : base( - iCustomizationTypes.Append(typeof(SutProviderCustomization)).ToArray(), values) - { } - - public InlineSutAutoDataAttribute(ICustomization[] customizations, params object[] values) : base( - customizations.Append(new SutProviderCustomization()).ToArray(), values) - { } -} diff --git a/test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs b/test/Common/AutoFixture/Attributes/SutProviderCustomizeAttribute.cs similarity index 50% rename from test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs rename to test/Common/AutoFixture/Attributes/SutProviderCustomizeAttribute.cs index a84bc3118..e582e1715 100644 --- a/test/Common/AutoFixture/Attributes/SutAutoDataAttribute.cs +++ b/test/Common/AutoFixture/Attributes/SutProviderCustomizeAttribute.cs @@ -6,10 +6,3 @@ public class SutProviderCustomizeAttribute : BitCustomizeAttribute { public override ICustomization GetCustomization() => new SutProviderCustomization(); } - -public class SutAutoDataAttribute : CustomAutoDataAttribute -{ - public SutAutoDataAttribute(params Type[] iCustomizationTypes) : base( - iCustomizationTypes.Append(typeof(SutProviderCustomization)).ToArray()) - { } -} diff --git a/test/Core.Test/AutoFixture/CipherFixtures.cs b/test/Core.Test/AutoFixture/CipherFixtures.cs index b4c87ef8a..ae883c5fa 100644 --- a/test/Core.Test/AutoFixture/CipherFixtures.cs +++ b/test/Core.Test/AutoFixture/CipherFixtures.cs @@ -33,36 +33,12 @@ internal class UserCipher : ICustomization } } -internal class UserCipherAutoDataAttribute : CustomAutoDataAttribute +internal class UserCipherCustomizeAttribute : BitCustomizeAttribute { - public UserCipherAutoDataAttribute(string userId = null) : base(new SutProviderCustomization(), - new UserCipher { UserId = userId == null ? (Guid?)null : new Guid(userId) }) - { } -} -internal class InlineUserCipherAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineUserCipherAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(UserCipher) }, values) - { } + public override ICustomization GetCustomization() => new UserCipher(); } -internal class InlineKnownUserCipherAutoDataAttribute : InlineCustomAutoDataAttribute +internal class OrganizationCipherCustomizeAttribute : BitCustomizeAttribute { - public InlineKnownUserCipherAutoDataAttribute(string userId, params object[] values) : base(new ICustomization[] - { new SutProviderCustomization(), new UserCipher { UserId = new Guid(userId) } }, values) - { } -} - -internal class OrganizationCipherAutoDataAttribute : CustomAutoDataAttribute -{ - public OrganizationCipherAutoDataAttribute(string organizationId = null) : base(new SutProviderCustomization(), - new OrganizationCipher { OrganizationId = organizationId == null ? (Guid?)null : new Guid(organizationId) }) - { } -} - -internal class InlineOrganizationCipherAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineOrganizationCipherAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(OrganizationCipher) }, values) - { } + public override ICustomization GetCustomization() => new OrganizationCipher(); } diff --git a/test/Core.Test/AutoFixture/CollectionFixtures.cs b/test/Core.Test/AutoFixture/CollectionFixtures.cs deleted file mode 100644 index 26c169a44..000000000 --- a/test/Core.Test/AutoFixture/CollectionFixtures.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Bit.Core.Test.AutoFixture.OrganizationFixtures; -using Bit.Test.Common.AutoFixture.Attributes; - -namespace Bit.Core.Test.AutoFixture.CollectionFixtures; - -internal class CollectionAutoDataAttribute : CustomAutoDataAttribute -{ - public CollectionAutoDataAttribute() : base(new SutProviderCustomization(), new OrganizationCustomization()) - { } -} diff --git a/test/Core.Test/AutoFixture/CurrentContextFixtures.cs b/test/Core.Test/AutoFixture/CurrentContextFixtures.cs index 1949dedd7..0f6c3ee95 100644 --- a/test/Core.Test/AutoFixture/CurrentContextFixtures.cs +++ b/test/Core.Test/AutoFixture/CurrentContextFixtures.cs @@ -2,6 +2,7 @@ using AutoFixture.Kernel; using Bit.Core.Context; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; namespace Bit.Core.Test.AutoFixture.CurrentContextFixtures; @@ -35,3 +36,8 @@ internal class CurrentContextBuilder : ISpecimenBuilder return obj; } } + +internal class CurrentContextCustomize : BitCustomizeAttribute +{ + public override ICustomization GetCustomization() => new CurrentContext(); +} diff --git a/test/Core.Test/AutoFixture/GroupFixtures.cs b/test/Core.Test/AutoFixture/GroupFixtures.cs deleted file mode 100644 index 2501bbfc3..000000000 --- a/test/Core.Test/AutoFixture/GroupFixtures.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Bit.Core.Test.AutoFixture.OrganizationFixtures; -using Bit.Test.Common.AutoFixture.Attributes; - -namespace Bit.Core.Test.AutoFixture.GroupFixtures; - -internal class GroupOrganizationAutoDataAttribute : CustomAutoDataAttribute -{ - public GroupOrganizationAutoDataAttribute() : base( - new SutProviderCustomization(), new OrganizationCustomization { UseGroups = true }) - { } -} - -internal class GroupOrganizationNotUseGroupsAutoDataAttribute : CustomAutoDataAttribute -{ - public GroupOrganizationNotUseGroupsAutoDataAttribute() : base( - new SutProviderCustomization(), new OrganizationCustomization { UseGroups = false }) - { } -} diff --git a/test/Core.Test/AutoFixture/OrganizationFixtures.cs b/test/Core.Test/AutoFixture/OrganizationFixtures.cs index 0641cb29e..34f64914e 100644 --- a/test/Core.Test/AutoFixture/OrganizationFixtures.cs +++ b/test/Core.Test/AutoFixture/OrganizationFixtures.cs @@ -64,7 +64,7 @@ internal class PaidOrganization : ICustomization public PlanType CheckedPlanType { get; set; } public void Customize(IFixture fixture) { - var validUpgradePlans = StaticStore.Plans.Where(p => p.Type != PlanType.Free && !p.Disabled).Select(p => p.Type).ToList(); + var validUpgradePlans = StaticStore.Plans.Where(p => p.Type != PlanType.Free && p.LegacyYear == null).OrderBy(p => p.UpgradeSortOrder).Select(p => p.Type).ToList(); var lowestActivePaidPlan = validUpgradePlans.First(); CheckedPlanType = CheckedPlanType.Equals(PlanType.Free) ? lowestActivePaidPlan : CheckedPlanType; validUpgradePlans.Remove(lowestActivePaidPlan); @@ -109,7 +109,7 @@ internal class OrganizationInvite : ICustomization public string PermissionsBlob { get; set; } public void Customize(IFixture fixture) { - var organizationId = new Guid(); + var organizationId = Guid.NewGuid(); PermissionsBlob = PermissionsBlob ?? JsonSerializer.Serialize(new Permissions(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, @@ -126,60 +126,38 @@ internal class OrganizationInvite : ICustomization } } -internal class PaidOrganizationAutoDataAttribute : CustomAutoDataAttribute +internal class OrganizationCustomizeAttribute : BitCustomizeAttribute { - public PaidOrganizationAutoDataAttribute(PlanType planType) : base(new SutProviderCustomization(), - new PaidOrganization { CheckedPlanType = planType }) - { } - public PaidOrganizationAutoDataAttribute(int planType = 0) : this((PlanType)planType) { } + public bool UseGroups { get; set; } + public override ICustomization GetCustomization() => new OrganizationCustomization() { UseGroups = UseGroups }; } -internal class InlinePaidOrganizationAutoDataAttribute : InlineCustomAutoDataAttribute +internal class PaidOrganizationCustomizeAttribute : BitCustomizeAttribute { - public InlinePaidOrganizationAutoDataAttribute(PlanType planType, object[] values) : base( - new ICustomization[] { new SutProviderCustomization(), new PaidOrganization { CheckedPlanType = planType } }, values) - { } - - public InlinePaidOrganizationAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(PaidOrganization) }, values) - { } + public PlanType CheckedPlanType { get; set; } = PlanType.FamiliesAnnually; + public override ICustomization GetCustomization() => new PaidOrganization() { CheckedPlanType = CheckedPlanType }; } -internal class InlineFreeOrganizationAutoDataAttribute : InlineCustomAutoDataAttribute +internal class FreeOrganizationCustomizeAttribute : BitCustomizeAttribute { - public InlineFreeOrganizationAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(FreeOrganization) }, values) - { } + public override ICustomization GetCustomization() => new FreeOrganization(); } -internal class FreeOrganizationUpgradeAutoDataAttribute : CustomAutoDataAttribute +internal class FreeOrganizationUpgradeCustomize : BitCustomizeAttribute { - public FreeOrganizationUpgradeAutoDataAttribute() : base(new SutProviderCustomization(), new FreeOrganizationUpgrade()) - { } + public override ICustomization GetCustomization() => new FreeOrganizationUpgrade(); } -internal class InlineFreeOrganizationUpgradeAutoDataAttribute : InlineCustomAutoDataAttribute +internal class OrganizationInviteCustomizeAttribute : BitCustomizeAttribute { - public InlineFreeOrganizationUpgradeAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(FreeOrganizationUpgrade) }, values) - { } -} + public OrganizationUserType InviteeUserType { get; set; } = OrganizationUserType.Owner; + public OrganizationUserType InvitorUserType { get; set; } = OrganizationUserType.Owner; + public string PermissionsBlob { get; set; } -internal class OrganizationInviteAutoDataAttribute : CustomAutoDataAttribute -{ - public OrganizationInviteAutoDataAttribute(int inviteeUserType = 0, int invitorUserType = 0, string permissionsBlob = null) : base(new SutProviderCustomization(), - new OrganizationInvite - { - InviteeUserType = (OrganizationUserType)inviteeUserType, - InvitorUserType = (OrganizationUserType)invitorUserType, - PermissionsBlob = permissionsBlob, - }) - { } -} - -internal class InlineOrganizationInviteAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineOrganizationInviteAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(OrganizationInvite) }, values) - { } + public override ICustomization GetCustomization() => new OrganizationInvite + { + InviteeUserType = InviteeUserType, + InvitorUserType = InvitorUserType, + PermissionsBlob = PermissionsBlob, + }; } diff --git a/test/Core.Test/AutoFixture/SendFixtures.cs b/test/Core.Test/AutoFixture/SendFixtures.cs index b7cdeeafd..102a4bb5b 100644 --- a/test/Core.Test/AutoFixture/SendFixtures.cs +++ b/test/Core.Test/AutoFixture/SendFixtures.cs @@ -4,17 +4,6 @@ using Bit.Test.Common.AutoFixture.Attributes; namespace Bit.Core.Test.AutoFixture.SendFixtures; -internal class OrganizationSend : ICustomization -{ - public Guid? OrganizationId { get; set; } - public void Customize(IFixture fixture) - { - fixture.Customize(composer => composer - .With(s => s.OrganizationId, OrganizationId ?? Guid.NewGuid()) - .Without(s => s.UserId)); - } -} - internal class UserSend : ICustomization { public Guid? UserId { get; set; } @@ -26,38 +15,7 @@ internal class UserSend : ICustomization } } -internal class UserSendAutoDataAttribute : CustomAutoDataAttribute +internal class UserSendCustomizeAttribute : BitCustomizeAttribute { - public UserSendAutoDataAttribute(string userId = null) : base(new SutProviderCustomization(), - new UserSend { UserId = userId == null ? (Guid?)null : new Guid(userId) }) - { } -} -internal class InlineUserSendAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineUserSendAutoDataAttribute(params object[] values) : base(new[] { typeof(CurrentContextFixtures.CurrentContext), - typeof(SutProviderCustomization), typeof(UserSend) }, values) - { } -} - -internal class InlineKnownUserSendAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineKnownUserSendAutoDataAttribute(string userId, params object[] values) : base(new ICustomization[] - { new CurrentContextFixtures.CurrentContext(), new SutProviderCustomization(), - new UserSend { UserId = new Guid(userId) } }, values) - { } -} - -internal class OrganizationSendAutoDataAttribute : CustomAutoDataAttribute -{ - public OrganizationSendAutoDataAttribute(string organizationId = null) : base(new CurrentContextFixtures.CurrentContext(), - new SutProviderCustomization(), - new OrganizationSend { OrganizationId = organizationId == null ? (Guid?)null : new Guid(organizationId) }) - { } -} - -internal class InlineOrganizationSendAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineOrganizationSendAutoDataAttribute(params object[] values) : base(new[] { typeof(CurrentContextFixtures.CurrentContext), - typeof(SutProviderCustomization), typeof(OrganizationSend) }, values) - { } + public override ICustomization GetCustomization() => new UserSend(); } diff --git a/test/Core.Test/AutoFixture/UserFixtures.cs b/test/Core.Test/AutoFixture/UserFixtures.cs index 39221aafc..a1330bcb8 100644 --- a/test/Core.Test/AutoFixture/UserFixtures.cs +++ b/test/Core.Test/AutoFixture/UserFixtures.cs @@ -5,6 +5,7 @@ using Bit.Core.Enums; using Bit.Core.Models; using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; namespace Bit.Core.Test.AutoFixture.UserFixtures; @@ -42,6 +43,11 @@ public class UserBuilder : ISpecimenBuilder } } +internal class UserCustomizeAttribute : BitCustomizeAttribute +{ + public override ICustomization GetCustomization() => new UserFixture(); +} + public class UserFixture : ICustomization { public virtual void Customize(IFixture fixture) diff --git a/test/Core.Test/Models/CipherTests.cs b/test/Core.Test/Models/CipherTests.cs index af7a0b6e3..fa9521b6c 100644 --- a/test/Core.Test/Models/CipherTests.cs +++ b/test/Core.Test/Models/CipherTests.cs @@ -1,6 +1,7 @@ using System.Text.Json; using Bit.Core.Entities; using Bit.Core.Test.AutoFixture.CipherFixtures; +using Bit.Test.Common.AutoFixture.Attributes; using Xunit; namespace Bit.Core.Test.Models; @@ -8,9 +9,17 @@ namespace Bit.Core.Test.Models; public class CipherTests { [Theory] - [InlineUserCipherAutoData] - [InlineOrganizationCipherAutoData] - public void Clone_CreatesExactCopy(Cipher cipher) + [UserCipherCustomize] + [BitAutoData] + public void Clone_UserCipher_CreatesExactCopy(Cipher cipher) + { + Assert.Equal(JsonSerializer.Serialize(cipher), JsonSerializer.Serialize(cipher.Clone())); + } + + [Theory] + [OrganizationCipherCustomize] + [BitAutoData] + public void Clone_OrganizationCipher_CreatesExactCopy(Cipher cipher) { Assert.Equal(JsonSerializer.Serialize(cipher), JsonSerializer.Serialize(cipher.Clone())); } diff --git a/test/Core.Test/Services/CipherServiceTests.cs b/test/Core.Test/Services/CipherServiceTests.cs index f036b973f..ed47954f3 100644 --- a/test/Core.Test/Services/CipherServiceTests.cs +++ b/test/Core.Test/Services/CipherServiceTests.cs @@ -4,6 +4,7 @@ using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Test.AutoFixture.CipherFixtures; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; using Castle.Core.Internal; using Core.Models.Data; using NSubstitute; @@ -11,9 +12,11 @@ using Xunit; namespace Bit.Core.Test.Services; +[UserCipherCustomize] +[SutProviderCustomize] public class CipherServiceTests { - [Theory, UserCipherAutoData] + [Theory, BitAutoData] public async Task SaveAsync_WrongRevisionDate_Throws(SutProvider sutProvider, Cipher cipher) { var lastKnownRevisionDate = cipher.RevisionDate.AddDays(-1); @@ -23,7 +26,7 @@ public class CipherServiceTests Assert.Contains("out of date", exception.Message); } - [Theory, UserCipherAutoData] + [Theory, BitAutoData] public async Task SaveDetailsAsync_WrongRevisionDate_Throws(SutProvider sutProvider, CipherDetails cipherDetails) { @@ -34,7 +37,7 @@ public class CipherServiceTests Assert.Contains("out of date", exception.Message); } - [Theory, UserCipherAutoData] + [Theory, BitAutoData] public async Task ShareAsync_WrongRevisionDate_Throws(SutProvider sutProvider, Cipher cipher, Organization organization, List collectionIds) { @@ -47,7 +50,7 @@ public class CipherServiceTests Assert.Contains("out of date", exception.Message); } - [Theory, UserCipherAutoData("99ab4f6c-44f8-4ff5-be7a-75c37c33c69e")] + [Theory, BitAutoData] public async Task ShareManyAsync_WrongRevisionDate_Throws(SutProvider sutProvider, IEnumerable ciphers, Guid organizationId, List collectionIds) { @@ -66,8 +69,8 @@ public class CipherServiceTests } [Theory] - [InlineUserCipherAutoData("")] - [InlineUserCipherAutoData("Correct Time")] + [BitAutoData("")] + [BitAutoData("Correct Time")] public async Task SaveAsync_CorrectRevisionDate_Passes(string revisionDateString, SutProvider sutProvider, Cipher cipher) { @@ -78,8 +81,8 @@ public class CipherServiceTests } [Theory] - [InlineUserCipherAutoData("")] - [InlineUserCipherAutoData("Correct Time")] + [BitAutoData("")] + [BitAutoData("Correct Time")] public async Task SaveDetailsAsync_CorrectRevisionDate_Passes(string revisionDateString, SutProvider sutProvider, CipherDetails cipherDetails) { @@ -90,8 +93,8 @@ public class CipherServiceTests } [Theory] - [InlineUserCipherAutoData("")] - [InlineUserCipherAutoData("Correct Time")] + [BitAutoData("")] + [BitAutoData("Correct Time")] public async Task ShareAsync_CorrectRevisionDate_Passes(string revisionDateString, SutProvider sutProvider, Cipher cipher, Organization organization, List collectionIds) { @@ -106,8 +109,8 @@ public class CipherServiceTests } [Theory] - [InlineKnownUserCipherAutoData(userId: "99ab4f6c-44f8-4ff5-be7a-75c37c33c69e", "")] - [InlineKnownUserCipherAutoData(userId: "99ab4f6c-44f8-4ff5-be7a-75c37c33c69e", "CorrectTime")] + [BitAutoData("")] + [BitAutoData("Correct Time")] public async Task ShareManyAsync_CorrectRevisionDate_Passes(string revisionDateString, SutProvider sutProvider, IEnumerable ciphers, Organization organization, List collectionIds) { @@ -128,9 +131,8 @@ public class CipherServiceTests } [Theory] - [InlineKnownUserCipherAutoData("c64d8a15-606e-41d6-9c7e-174d4d8f3b2e", "c64d8a15-606e-41d6-9c7e-174d4d8f3b2e")] - [InlineOrganizationCipherAutoData("c64d8a15-606e-41d6-9c7e-174d4d8f3b2e")] - public async Task RestoreAsync_UpdatesCipher(Guid restoringUserId, Cipher cipher, SutProvider sutProvider) + [BitAutoData] + public async Task RestoreAsync_UpdatesUserCipher(Guid restoringUserId, Cipher cipher, SutProvider sutProvider) { sutProvider.GetDependency().GetCanEditByIdAsync(restoringUserId, cipher.Id).Returns(true); @@ -145,10 +147,28 @@ public class CipherServiceTests } [Theory] - [InlineKnownUserCipherAutoData("c64d8a15-606e-41d6-9c7e-174d4d8f3b2e", "c64d8a15-606e-41d6-9c7e-174d4d8f3b2e")] - public async Task RestoreManyAsync_UpdatesCiphers(Guid restoringUserId, IEnumerable ciphers, + [OrganizationCipherCustomize] + [BitAutoData] + public async Task RestoreAsync_UpdatesOrganizationCipher(Guid restoringUserId, Cipher cipher, SutProvider sutProvider) + { + sutProvider.GetDependency().GetCanEditByIdAsync(restoringUserId, cipher.Id).Returns(true); + + var initialRevisionDate = new DateTime(1970, 1, 1, 0, 0, 0); + cipher.DeletedDate = initialRevisionDate; + cipher.RevisionDate = initialRevisionDate; + + await sutProvider.Sut.RestoreAsync(cipher, restoringUserId, cipher.OrganizationId.HasValue); + + Assert.Null(cipher.DeletedDate); + Assert.NotEqual(initialRevisionDate, cipher.RevisionDate); + } + + [Theory] + [BitAutoData] + public async Task RestoreManyAsync_UpdatesCiphers(IEnumerable ciphers, SutProvider sutProvider) { + var restoringUserId = ciphers.First().UserId.Value; var previousRevisionDate = DateTime.UtcNow; foreach (var cipher in ciphers) { @@ -168,8 +188,7 @@ public class CipherServiceTests } } - [Theory] - [InlineUserCipherAutoData] + [Theory, BitAutoData] public async Task ShareManyAsync_FreeOrgWithAttachment_Throws(SutProvider sutProvider, IEnumerable ciphers, Guid organizationId, List collectionIds) { @@ -190,8 +209,7 @@ public class CipherServiceTests Assert.Contains("This organization cannot use attachments", exception.Message); } - [Theory] - [InlineUserCipherAutoData] + [Theory, BitAutoData] public async Task ShareManyAsync_PaidOrgWithAttachment_Passes(SutProvider sutProvider, IEnumerable ciphers, Guid organizationId, List collectionIds) { diff --git a/test/Core.Test/Services/CollectionServiceTests.cs b/test/Core.Test/Services/CollectionServiceTests.cs index b6a68b58e..1478d2014 100644 --- a/test/Core.Test/Services/CollectionServiceTests.cs +++ b/test/Core.Test/Services/CollectionServiceTests.cs @@ -4,7 +4,7 @@ using Bit.Core.Exceptions; using Bit.Core.Models.Data; using Bit.Core.Repositories; using Bit.Core.Services; -using Bit.Core.Test.AutoFixture.CollectionFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; @@ -12,9 +12,11 @@ using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] +[OrganizationCustomize] public class CollectionServiceTest { - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task SaveAsync_DefaultId_CreatesCollectionInTheRepository(Collection collection, Organization organization, SutProvider sutProvider) { collection.Id = default; @@ -30,7 +32,7 @@ public class CollectionServiceTest Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task SaveAsync_DefaultIdWithGroups_CreateCollectionWithGroupsInRepository(Collection collection, IEnumerable groups, Organization organization, SutProvider sutProvider) { @@ -48,7 +50,7 @@ public class CollectionServiceTest Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task SaveAsync_NonDefaultId_ReplacesCollectionInRepository(Collection collection, Organization organization, SutProvider sutProvider) { var creationDate = collection.CreationDate; @@ -64,7 +66,7 @@ public class CollectionServiceTest Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task SaveAsync_OrganizationNotUseGroup_CreateCollectionWithoutGroupsInRepository(Collection collection, IEnumerable groups, Organization organization, SutProvider sutProvider) { @@ -81,7 +83,7 @@ public class CollectionServiceTest Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task SaveAsync_DefaultIdWithUserId_UpdateUserInCollectionRepository(Collection collection, Organization organization, OrganizationUser organizationUser, SutProvider sutProvider) { @@ -104,7 +106,7 @@ public class CollectionServiceTest Assert.True(collection.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Collection collection, SutProvider sutProvider) { var ex = await Assert.ThrowsAsync(() => sutProvider.Sut.SaveAsync(collection)); @@ -115,7 +117,7 @@ public class CollectionServiceTest await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().LogCollectionEventAsync(default, default); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task SaveAsync_ExceedsOrganizationMaxCollections_ThrowsBadRequest(Collection collection, Organization organization, SutProvider sutProvider) { collection.Id = default; @@ -131,7 +133,7 @@ public class CollectionServiceTest await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().LogCollectionEventAsync(default, default); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task DeleteUserAsync_DeletesValidUserWhoBelongsToCollection(Collection collection, Organization organization, OrganizationUser organizationUser, SutProvider sutProvider) { @@ -148,7 +150,7 @@ public class CollectionServiceTest await sutProvider.GetDependency().Received().LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Updated); } - [Theory, CollectionAutoData] + [Theory, BitAutoData] public async Task DeleteUserAsync_InvalidUser_ThrowsNotFound(Collection collection, Organization organization, OrganizationUser organizationUser, SutProvider sutProvider) { diff --git a/test/Core.Test/Services/EmergencyAccessServiceTests.cs b/test/Core.Test/Services/EmergencyAccessServiceTests.cs index 6f8576d8e..110aa4a25 100644 --- a/test/Core.Test/Services/EmergencyAccessServiceTests.cs +++ b/test/Core.Test/Services/EmergencyAccessServiceTests.cs @@ -11,9 +11,10 @@ using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] public class EmergencyAccessServiceTests { - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_PremiumCannotUpdate( SutProvider sutProvider, User savingUser) { @@ -33,7 +34,7 @@ public class EmergencyAccessServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InviteAsync_UserWithKeyConnectorCannotUseTakeover( SutProvider sutProvider, User invitingUser, string email, int waitTime) { @@ -47,7 +48,7 @@ public class EmergencyAccessServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().CreateAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUserAsync_UserWithKeyConnectorCannotUseTakeover( SutProvider sutProvider, User confirmingUser, string key) { @@ -69,7 +70,7 @@ public class EmergencyAccessServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_UserWithKeyConnectorCannotUseTakeover( SutProvider sutProvider, User savingUser) { @@ -91,7 +92,7 @@ public class EmergencyAccessServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task InitiateAsync_UserWithKeyConnectorCannotUseTakeover( SutProvider sutProvider, User initiatingUser, User grantor) { @@ -114,7 +115,7 @@ public class EmergencyAccessServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task TakeoverAsync_UserWithKeyConnectorCannotUseTakeover( SutProvider sutProvider, User requestingUser, User grantor) { @@ -136,7 +137,7 @@ public class EmergencyAccessServiceTests Assert.Contains("You cannot takeover an account that is using Key Connector", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task PasswordAsync_Disables_2FA_Providers_And_Unknown_Device_Verification_On_The_Grantor( SutProvider sutProvider, User requestingUser, User grantor) { diff --git a/test/Core.Test/Services/GroupServiceTests.cs b/test/Core.Test/Services/GroupServiceTests.cs index 04aad9726..80660af17 100644 --- a/test/Core.Test/Services/GroupServiceTests.cs +++ b/test/Core.Test/Services/GroupServiceTests.cs @@ -4,7 +4,7 @@ using Bit.Core.Exceptions; using Bit.Core.Models.Data; using Bit.Core.Repositories; using Bit.Core.Services; -using Bit.Core.Test.AutoFixture.GroupFixtures; +using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; @@ -12,9 +12,11 @@ using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] +[OrganizationCustomize(UseGroups = true)] public class GroupServiceTests { - [Theory, GroupOrganizationAutoData] + [Theory, BitAutoData] public async Task SaveAsync_DefaultGroupId_CreatesGroupInRepository(Group group, Organization organization, SutProvider sutProvider) { group.Id = default(Guid); @@ -31,7 +33,7 @@ public class GroupServiceTests Assert.True(group.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, GroupOrganizationAutoData] + [Theory, BitAutoData] public async Task SaveAsync_DefaultGroupIdAndCollections_CreatesGroupInRepository(Group group, Organization organization, List collections, SutProvider sutProvider) { group.Id = default(Guid); @@ -48,7 +50,7 @@ public class GroupServiceTests Assert.True(group.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, GroupOrganizationAutoData] + [Theory, BitAutoData] public async Task SaveAsync_NonDefaultGroupId_ReplaceGroupInRepository(Group group, Organization organization, List collections, SutProvider sutProvider) { organization.UseGroups = true; @@ -62,7 +64,7 @@ public class GroupServiceTests Assert.True(group.RevisionDate - DateTime.UtcNow < TimeSpan.FromSeconds(1)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Group group, SutProvider sutProvider) { var exception = await Assert.ThrowsAsync( @@ -73,7 +75,7 @@ public class GroupServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().LogGroupEventAsync(default, default, default); } - [Theory, GroupOrganizationNotUseGroupsAutoData] + [Theory, OrganizationCustomize(UseGroups = false), BitAutoData] public async Task SaveAsync_OrganizationDoesNotUseGroups_ThrowsBadRequest(Group group, Organization organization, SutProvider sutProvider) { sutProvider.GetDependency().GetByIdAsync(organization.Id).Returns(organization); @@ -87,7 +89,7 @@ public class GroupServiceTests await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().LogGroupEventAsync(default, default, default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteAsync_ValidData_DeletesGroup(Group group, SutProvider sutProvider) { await sutProvider.Sut.DeleteAsync(group); @@ -97,7 +99,7 @@ public class GroupServiceTests .LogGroupEventAsync(group, EventType.Group_Deleted); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUserAsync_ValidData_DeletesUserInGroupRepository(Group group, Organization organization, OrganizationUser organizationUser, SutProvider sutProvider) { group.OrganizationId = organization.Id; @@ -114,7 +116,7 @@ public class GroupServiceTests .LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_UpdatedGroups); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUserAsync_InvalidUser_ThrowsNotFound(Group group, Organization organization, OrganizationUser organizationUser, SutProvider sutProvider) { group.OrganizationId = organization.Id; diff --git a/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs b/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs index cf05933f4..660ee7197 100644 --- a/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs +++ b/test/Core.Test/Services/LocalAttachmentStorageServiceTests.cs @@ -13,6 +13,7 @@ using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] public class LocalAttachmentStorageServiceTests { @@ -155,10 +156,14 @@ public class LocalAttachmentStorageServiceTests } } - [Theory] - [InlineUserCipherAutoData] - [InlineOrganizationCipherAutoData] - public async Task CleanupAsync_Succes(Cipher cipher) + [Theory, BitAutoData] + [UserCipherCustomize] + public async Task UserCipher_CleanupAsync_Success(Cipher cipher) => await CleanupAsync_Success(cipher); + [Theory, BitAutoData] + [OrganizationCipherCustomize] + public async Task OrganizationCipher_CleanupAsync_Success(Cipher cipher) => await CleanupAsync_Success(cipher); + + private async Task CleanupAsync_Success(Cipher cipher) { using (var tempDirectory = new TempDirectory()) { @@ -176,10 +181,14 @@ public class LocalAttachmentStorageServiceTests } } - [Theory] - [InlineUserCipherAutoData] - [InlineOrganizationCipherAutoData] - public async Task DeleteAttachmentsForCipherAsync_Succes(Cipher cipher) + [Theory, BitAutoData] + [UserCipherCustomize] + public async Task UserCipher_DeleteAttachmentsForCipherAsync_Succes(Cipher cipher) => await DeleteAttachmentsForCipherAsync_Succes(cipher); + [Theory, BitAutoData] + [OrganizationCipherCustomize] + public async Task OrganizationCipher_DeleteAttachmentsForCipherAsync_Succes(Cipher cipher) => await DeleteAttachmentsForCipherAsync_Succes(cipher); + + private async Task DeleteAttachmentsForCipherAsync_Succes(Cipher cipher) { using (var tempDirectory = new TempDirectory()) { diff --git a/test/Core.Test/Services/OrganizationServiceTests.cs b/test/Core.Test/Services/OrganizationServiceTests.cs index 73f0b8cfe..c07a30184 100644 --- a/test/Core.Test/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/Services/OrganizationServiceTests.cs @@ -22,10 +22,11 @@ using Policy = Bit.Core.Entities.Policy; namespace Bit.Core.Test.Services; +[SutProviderCustomize] public class OrganizationServiceTests { // [Fact] - [Theory, PaidOrganizationAutoData] + [Theory, PaidOrganizationCustomize, BitAutoData] public async Task OrgImportCreateNewUsers(SutProvider sutProvider, Guid userId, Organization org, List existingUsers, List newUsers) { @@ -75,7 +76,7 @@ public class OrganizationServiceTests referenceEvent.Users == expectedNewUsersCount)); } - [Theory, PaidOrganizationAutoData] + [Theory, PaidOrganizationCustomize, BitAutoData] public async Task OrgImportCreateNewUsersAndMarryExistingUser(SutProvider sutProvider, Guid userId, Organization org, List existingUsers, List newUsers) @@ -133,7 +134,7 @@ public class OrganizationServiceTests referenceEvent.Users == expectedNewUsersCount)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpgradePlan_OrganizationIsNull_Throws(Guid organizationId, OrganizationUpgrade upgrade, SutProvider sutProvider) { @@ -142,7 +143,7 @@ public class OrganizationServiceTests () => sutProvider.Sut.UpgradePlanAsync(organizationId, upgrade)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpgradePlan_GatewayCustomIdIsNull_Throws(Organization organization, OrganizationUpgrade upgrade, SutProvider sutProvider) { @@ -153,7 +154,7 @@ public class OrganizationServiceTests Assert.Contains("no payment method", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpgradePlan_AlreadyInPlan_Throws(Organization organization, OrganizationUpgrade upgrade, SutProvider sutProvider) { @@ -164,7 +165,7 @@ public class OrganizationServiceTests Assert.Contains("already on this plan", exception.Message); } - [Theory, PaidOrganizationAutoData] + [Theory, PaidOrganizationCustomize(CheckedPlanType = PlanType.Free), BitAutoData] public async Task UpgradePlan_UpgradeFromPaidPlan_Throws(Organization organization, OrganizationUpgrade upgrade, SutProvider sutProvider) { @@ -175,7 +176,7 @@ public class OrganizationServiceTests } [Theory] - [FreeOrganizationUpgradeAutoData] + [FreeOrganizationUpgradeCustomize, BitAutoData] public async Task UpgradePlan_Passes(Organization organization, OrganizationUpgrade upgrade, SutProvider sutProvider) { @@ -185,7 +186,7 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData] + [OrganizationInviteCustomize, BitAutoData] public async Task InviteUser_NoEmails_Throws(Organization organization, OrganizationUser invitor, OrganizationUserInvite invite, SutProvider sutProvider) { @@ -196,7 +197,7 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData] + [OrganizationInviteCustomize, BitAutoData] public async Task InviteUser_DuplicateEmails_PassesWithoutDuplicates(Organization organization, OrganizationUser invitor, [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser owner, OrganizationUserInvite invite, SutProvider sutProvider) @@ -218,10 +219,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.Admin, - invitorUserType: (int)OrganizationUserType.Owner - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.Admin, + InvitorUserType = OrganizationUserType.Owner + ), BitAutoData] public async Task InviteUser_NoOwner_Throws(Organization organization, OrganizationUser invitor, OrganizationUserInvite invite, SutProvider sutProvider) { @@ -234,10 +235,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.Owner, - invitorUserType: (int)OrganizationUserType.Admin - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.Owner, + InvitorUserType = OrganizationUserType.Admin + ), BitAutoData] public async Task InviteUser_NonOwnerConfiguringOwner_Throws(Organization organization, OrganizationUserInvite invite, OrganizationUser invitor, SutProvider sutProvider) { @@ -253,10 +254,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.Custom, - invitorUserType: (int)OrganizationUserType.User - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.Custom, + InvitorUserType = OrganizationUserType.User + ), BitAutoData] public async Task InviteUser_NonAdminConfiguringAdmin_Throws(Organization organization, OrganizationUserInvite invite, OrganizationUser invitor, SutProvider sutProvider) { @@ -272,10 +273,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.Manager, - invitorUserType: (int)OrganizationUserType.Custom - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.Manager, + InvitorUserType = OrganizationUserType.Custom + ), BitAutoData] public async Task InviteUser_CustomUserWithoutManageUsersConfiguringUser_Throws(Organization organization, OrganizationUserInvite invite, OrganizationUser invitor, SutProvider sutProvider) { @@ -298,10 +299,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.Admin, - invitorUserType: (int)OrganizationUserType.Custom - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.Admin, + InvitorUserType = OrganizationUserType.Custom + ), BitAutoData] public async Task InviteUser_CustomUserConfiguringAdmin_Throws(Organization organization, OrganizationUserInvite invite, OrganizationUser invitor, SutProvider sutProvider) { @@ -324,10 +325,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.User, - invitorUserType: (int)OrganizationUserType.Owner - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.User, + InvitorUserType = OrganizationUserType.Owner + ), BitAutoData] public async Task InviteUser_NoPermissionsObject_Passes(Organization organization, OrganizationUserInvite invite, OrganizationUser invitor, SutProvider sutProvider) { @@ -347,10 +348,10 @@ public class OrganizationServiceTests } [Theory] - [OrganizationInviteAutoData( - inviteeUserType: (int)OrganizationUserType.User, - invitorUserType: (int)OrganizationUserType.Custom - )] + [OrganizationInviteCustomize( + InviteeUserType = OrganizationUserType.User, + InvitorUserType = OrganizationUserType.Custom + ), BitAutoData] public async Task InviteUser_Passes(Organization organization, IEnumerable<(OrganizationUserInvite invite, string externalId)> invites, OrganizationUser invitor, [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser owner, @@ -383,7 +384,7 @@ public class OrganizationServiceTests Arg.Is>(v => v.Count() == invites.SelectMany(i => i.invite.Emails).Count())); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveUser_NoUserId_Throws(OrganizationUser user, Guid? savingUserId, IEnumerable collections, SutProvider sutProvider) { @@ -393,7 +394,7 @@ public class OrganizationServiceTests Assert.Contains("invite the user first", exception.Message.ToLowerInvariant()); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveUser_NoChangeToData_Throws(OrganizationUser user, Guid? savingUserId, IEnumerable collections, SutProvider sutProvider) { @@ -404,7 +405,7 @@ public class OrganizationServiceTests Assert.Contains("make changes before saving", exception.Message.ToLowerInvariant()); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveUser_Passes( OrganizationUser oldUserData, OrganizationUser newUserData, @@ -426,7 +427,7 @@ public class OrganizationServiceTests await sutProvider.Sut.SaveUserAsync(newUserData, savingUser.UserId, collections); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUser_InvalidUser(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) { @@ -439,7 +440,7 @@ public class OrganizationServiceTests Assert.Contains("User not valid.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUser_RemoveYourself(OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -451,7 +452,7 @@ public class OrganizationServiceTests Assert.Contains("You cannot remove yourself.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUser_NonOwnerRemoveOwner( [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser organizationUser, [OrganizationUser(type: OrganizationUserType.Admin)] OrganizationUser deletingUser, @@ -469,7 +470,7 @@ public class OrganizationServiceTests Assert.Contains("Only owners can delete other owners.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUser_LastOwner( [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser organizationUser, OrganizationUser deletingUser, @@ -487,7 +488,7 @@ public class OrganizationServiceTests Assert.Contains("Organization must have at least one confirmed owner.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUser_Success( OrganizationUser organizationUser, [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, @@ -506,7 +507,7 @@ public class OrganizationServiceTests await sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsers_FilterInvalid(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) { @@ -520,7 +521,7 @@ public class OrganizationServiceTests Assert.Contains("Users invalid.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsers_RemoveYourself( [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser orgUser, OrganizationUser deletingUser, @@ -536,7 +537,7 @@ public class OrganizationServiceTests Assert.Contains("You cannot remove yourself.", result[0].Item2); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsers_NonOwnerRemoveOwner( [OrganizationUser(type: OrganizationUserType.Admin)] OrganizationUser deletingUser, [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, @@ -555,7 +556,7 @@ public class OrganizationServiceTests Assert.Contains("Only owners can delete other owners.", result[0].Item2); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsers_LastOwner( [OrganizationUser(status: OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser orgUser, SutProvider sutProvider) @@ -572,7 +573,7 @@ public class OrganizationServiceTests Assert.Contains("Organization must have at least one confirmed owner.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task DeleteUsers_Success( [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, OrganizationUser orgUser2, @@ -593,7 +594,7 @@ public class OrganizationServiceTests await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUser_InvalidStatus(OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Invited)] OrganizationUser orgUser, string key, SutProvider sutProvider) @@ -608,7 +609,7 @@ public class OrganizationServiceTests Assert.Contains("User not valid.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUser_WrongOrganization(OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, string key, SutProvider sutProvider) @@ -624,8 +625,8 @@ public class OrganizationServiceTests } [Theory] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, OrganizationUserType.Owner)] + [BitAutoData(OrganizationUserType.Admin)] + [BitAutoData(OrganizationUserType.Owner)] public async Task ConfirmUserToFree_AlreadyFreeAdminOrOwner_Throws(OrganizationUserType userType, Organization org, OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, string key, SutProvider sutProvider) @@ -650,28 +651,28 @@ public class OrganizationServiceTests } [Theory] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.Custom, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.Custom, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseAnnually, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseAnnually, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseAnnually2019, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseAnnually2019, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseMonthly, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseMonthly, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseMonthly2019, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.EnterpriseMonthly2019, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.FamiliesAnnually, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.FamiliesAnnually, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.FamiliesAnnually2019, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.FamiliesAnnually2019, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsAnnually, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsAnnually, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsAnnually2019, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsAnnually2019, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsMonthly, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsMonthly, OrganizationUserType.Owner)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsMonthly2019, OrganizationUserType.Admin)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PlanType.TeamsMonthly2019, OrganizationUserType.Owner)] + [BitAutoData(PlanType.Custom, OrganizationUserType.Admin)] + [BitAutoData(PlanType.Custom, OrganizationUserType.Owner)] + [BitAutoData(PlanType.EnterpriseAnnually, OrganizationUserType.Admin)] + [BitAutoData(PlanType.EnterpriseAnnually, OrganizationUserType.Owner)] + [BitAutoData(PlanType.EnterpriseAnnually2019, OrganizationUserType.Admin)] + [BitAutoData(PlanType.EnterpriseAnnually2019, OrganizationUserType.Owner)] + [BitAutoData(PlanType.EnterpriseMonthly, OrganizationUserType.Admin)] + [BitAutoData(PlanType.EnterpriseMonthly, OrganizationUserType.Owner)] + [BitAutoData(PlanType.EnterpriseMonthly2019, OrganizationUserType.Admin)] + [BitAutoData(PlanType.EnterpriseMonthly2019, OrganizationUserType.Owner)] + [BitAutoData(PlanType.FamiliesAnnually, OrganizationUserType.Admin)] + [BitAutoData(PlanType.FamiliesAnnually, OrganizationUserType.Owner)] + [BitAutoData(PlanType.FamiliesAnnually2019, OrganizationUserType.Admin)] + [BitAutoData(PlanType.FamiliesAnnually2019, OrganizationUserType.Owner)] + [BitAutoData(PlanType.TeamsAnnually, OrganizationUserType.Admin)] + [BitAutoData(PlanType.TeamsAnnually, OrganizationUserType.Owner)] + [BitAutoData(PlanType.TeamsAnnually2019, OrganizationUserType.Admin)] + [BitAutoData(PlanType.TeamsAnnually2019, OrganizationUserType.Owner)] + [BitAutoData(PlanType.TeamsMonthly, OrganizationUserType.Admin)] + [BitAutoData(PlanType.TeamsMonthly, OrganizationUserType.Owner)] + [BitAutoData(PlanType.TeamsMonthly2019, OrganizationUserType.Admin)] + [BitAutoData(PlanType.TeamsMonthly2019, OrganizationUserType.Owner)] public async Task ConfirmUserToNonFree_AlreadyFreeAdminOrOwner_DoesNotThrow(PlanType planType, OrganizationUserType orgUserType, Organization org, OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, string key, SutProvider sutProvider) @@ -698,7 +699,7 @@ public class OrganizationServiceTests } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUser_SingleOrgPolicy(Organization org, OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, OrganizationUser orgUserAnotherOrg, [Policy(PolicyType.SingleOrg)] Policy singleOrgPolicy, @@ -725,7 +726,7 @@ public class OrganizationServiceTests Assert.Contains("User is a member of another organization.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUser_TwoFactorPolicy(Organization org, OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, OrganizationUser orgUserAnotherOrg, [Policy(PolicyType.TwoFactorAuthentication)] Policy twoFactorPolicy, @@ -751,7 +752,7 @@ public class OrganizationServiceTests Assert.Contains("User does not have two-step login enabled.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUser_Success(Organization org, OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser, User user, [Policy(PolicyType.TwoFactorAuthentication)] Policy twoFactorPolicy, @@ -775,7 +776,7 @@ public class OrganizationServiceTests await sutProvider.Sut.ConfirmUserAsync(orgUser.OrganizationId, orgUser.Id, key, confirmingUser.Id, userService); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task ConfirmUsers_Success(Organization org, OrganizationUser confirmingUser, [OrganizationUser(OrganizationUserStatusType.Accepted)] OrganizationUser orgUser1, @@ -815,7 +816,7 @@ public class OrganizationServiceTests Assert.Contains("User is a member of another organization.", result[2].Item2); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateOrganizationKeysAsync_WithoutManageResetPassword_Throws(Guid orgId, string publicKey, string privateKey, SutProvider sutProvider) { @@ -826,7 +827,7 @@ public class OrganizationServiceTests () => sutProvider.Sut.UpdateOrganizationKeysAsync(orgId, publicKey, privateKey)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateOrganizationKeysAsync_KeysAlreadySet_Throws(Organization org, string publicKey, string privateKey, SutProvider sutProvider) { @@ -841,7 +842,7 @@ public class OrganizationServiceTests Assert.Contains("Organization Keys already exist", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateOrganizationKeysAsync_KeysAlreadySet_Success(Organization org, string publicKey, string privateKey, SutProvider sutProvider) { @@ -858,10 +859,20 @@ public class OrganizationServiceTests } [Theory] - [InlinePaidOrganizationAutoData(PlanType.EnterpriseAnnually, new object[] { "Cannot set max seat autoscaling below seat count", 1, 0, 2 })] - [InlinePaidOrganizationAutoData(PlanType.EnterpriseAnnually, new object[] { "Cannot set max seat autoscaling below seat count", 4, -1, 6 })] - [InlineFreeOrganizationAutoData("Your plan does not allow seat autoscaling", 10, 0, null)] - public async Task UpdateSubscription_BadInputThrows(string expectedMessage, + [PaidOrganizationCustomize(CheckedPlanType = PlanType.EnterpriseAnnually)] + [BitAutoData("Cannot set max seat autoscaling below seat count", 1, 0, 2)] + [BitAutoData("Cannot set max seat autoscaling below seat count", 4, -1, 6)] + public async Task Enterprise_UpdateSubscription_BadInputThrows(string expectedMessage, + int? maxAutoscaleSeats, int seatAdjustment, int? currentSeats, Organization organization, SutProvider sutProvider) + => await UpdateSubscription_BadInputThrows(expectedMessage, maxAutoscaleSeats, seatAdjustment, currentSeats, organization, sutProvider); + [Theory] + [FreeOrganizationCustomize] + [BitAutoData("Your plan does not allow seat autoscaling", 10, 0, null)] + public async Task Free_UpdateSubscription_BadInputThrows(string expectedMessage, + int? maxAutoscaleSeats, int seatAdjustment, int? currentSeats, Organization organization, SutProvider sutProvider) + => await UpdateSubscription_BadInputThrows(expectedMessage, maxAutoscaleSeats, seatAdjustment, currentSeats, organization, sutProvider); + + private async Task UpdateSubscription_BadInputThrows(string expectedMessage, int? maxAutoscaleSeats, int seatAdjustment, int? currentSeats, Organization organization, SutProvider sutProvider) { organization.Seats = currentSeats; @@ -873,7 +884,7 @@ public class OrganizationServiceTests Assert.Contains(expectedMessage, exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateSubscription_NoOrganization_Throws(Guid organizationId, SutProvider sutProvider) { sutProvider.GetDependency().GetByIdAsync(organizationId).Returns((Organization)null); @@ -881,12 +892,12 @@ public class OrganizationServiceTests await Assert.ThrowsAsync(() => sutProvider.Sut.UpdateSubscription(organizationId, 0, null)); } - [Theory] - [InlinePaidOrganizationAutoData(0, 100, null, true, "")] - [InlinePaidOrganizationAutoData(0, 100, 100, true, "")] - [InlinePaidOrganizationAutoData(0, null, 100, true, "")] - [InlinePaidOrganizationAutoData(1, 100, null, true, "")] - [InlinePaidOrganizationAutoData(1, 100, 100, false, "Cannot invite new users. Seat limit has been reached")] + [Theory, PaidOrganizationCustomize] + [BitAutoData(0, 100, null, true, "")] + [BitAutoData(0, 100, 100, true, "")] + [BitAutoData(0, null, 100, true, "")] + [BitAutoData(1, 100, null, true, "")] + [BitAutoData(1, 100, 100, false, "Cannot invite new users. Seat limit has been reached")] public void CanScale(int seatsToAdd, int? currentSeats, int? maxAutoscaleSeats, bool expectedResult, string expectedFailureMessage, Organization organization, SutProvider sutProvider) @@ -908,7 +919,7 @@ public class OrganizationServiceTests Assert.Equal(expectedResult, result); } - [Theory, PaidOrganizationAutoData] + [Theory, PaidOrganizationCustomize, BitAutoData] public void CanScale_FailsOnSelfHosted(Organization organization, SutProvider sutProvider) { @@ -919,7 +930,7 @@ public class OrganizationServiceTests Assert.Contains("Cannot autoscale on self-hosted instance", failureMessage); } - [Theory, PaidOrganizationAutoData] + [Theory, PaidOrganizationCustomize, BitAutoData] public async Task Delete_Success(Organization organization, SutProvider sutProvider) { var organizationRepository = sutProvider.GetDependency(); @@ -931,7 +942,7 @@ public class OrganizationServiceTests await applicationCacheService.Received().DeleteOrganizationAbilityAsync(organization.Id); } - [Theory, PaidOrganizationAutoData] + [Theory, PaidOrganizationCustomize, BitAutoData] public async Task Delete_Fails_KeyConnector(Organization organization, SutProvider sutProvider, SsoConfig ssoConfig) { diff --git a/test/Core.Test/Services/SendServiceTests.cs b/test/Core.Test/Services/SendServiceTests.cs index 1468bd0b0..6bbf63396 100644 --- a/test/Core.Test/Services/SendServiceTests.cs +++ b/test/Core.Test/Services/SendServiceTests.cs @@ -7,15 +7,20 @@ using Bit.Core.Models.Data; using Bit.Core.Models.Data.Organizations.Policies; using Bit.Core.Repositories; using Bit.Core.Services; +using Bit.Core.Test.AutoFixture.CurrentContextFixtures; using Bit.Core.Test.AutoFixture.SendFixtures; using Bit.Core.Test.Entities; using Bit.Test.Common.AutoFixture; +using Bit.Test.Common.AutoFixture.Attributes; using Microsoft.AspNetCore.Identity; using NSubstitute; using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] +[CurrentContextCustomize] +[UserSendCustomize] public class SendServiceTests { private void SaveSendAsync_Setup(SendType sendType, bool disableSendPolicyAppliesToUser, @@ -31,8 +36,8 @@ public class SendServiceTests // Disable Send policy check [Theory] - [InlineUserSendAutoData(SendType.File)] - [InlineUserSendAutoData(SendType.Text)] + [BitAutoData(SendType.File)] + [BitAutoData(SendType.Text)] public async void SaveSendAsync_DisableSend_Applies_throws(SendType sendType, SutProvider sutProvider, Send send) { @@ -42,8 +47,8 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData(SendType.File)] - [InlineUserSendAutoData(SendType.Text)] + [BitAutoData(SendType.File)] + [BitAutoData(SendType.Text)] public async void SaveSendAsync_DisableSend_DoesntApply_success(SendType sendType, SutProvider sutProvider, Send send) { @@ -78,8 +83,8 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData(SendType.File)] - [InlineUserSendAutoData(SendType.Text)] + [BitAutoData(SendType.File)] + [BitAutoData(SendType.Text)] public async void SaveSendAsync_DisableHideEmail_Applies_throws(SendType sendType, SutProvider sutProvider, Send send, Policy policy) { @@ -90,8 +95,8 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData(SendType.File)] - [InlineUserSendAutoData(SendType.Text)] + [BitAutoData(SendType.File)] + [BitAutoData(SendType.Text)] public async void SaveSendAsync_DisableHideEmail_DoesntApply_success(SendType sendType, SutProvider sutProvider, Send send, Policy policy) { @@ -104,8 +109,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveSendAsync_ExistingSend_Updates(SutProvider sutProvider, Send send) { @@ -126,7 +130,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_TextType_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -140,7 +144,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_EmptyFile_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -154,7 +158,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_UserCannotAccessPremium_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -182,7 +186,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_UserHasUnconfirmedEmail_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -211,7 +215,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_UserCanAccessPremium_HasNoStorage_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -243,7 +247,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_UserCanAccessPremium_StorageFull_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -275,7 +279,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_UserCanAccessPremium_IsNotPremium_IsSelfHosted_GiantFile_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -308,7 +312,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_UserCanAccessPremium_IsNotPremium_IsNotSelfHosted_TwoGigabyteFile_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -341,7 +345,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_ThroughOrg_MaxStorageIsNull_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -367,7 +371,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_ThroughOrg_MaxStorageIsNull_TwoGBFile_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -393,7 +397,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_ThroughOrg_MaxStorageIsOneGB_TwoGBFile_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -419,7 +423,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_HasEnouphStorage_Success(SutProvider sutProvider, Send send) { @@ -473,7 +477,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void SaveFileSendAsync_HasEnouphStorage_SendFileThrows_CleansUp(SutProvider sutProvider, Send send) { @@ -531,7 +535,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void UpdateFileToExistingSendAsync_SendNull_ThrowsBadRequest(SutProvider sutProvider) { @@ -543,7 +547,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void UpdateFileToExistingSendAsync_SendDataNull_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -557,7 +561,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void UpdateFileToExistingSendAsync_NotFileType_ThrowsBadRequest(SutProvider sutProvider, Send send) { @@ -569,7 +573,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void UpdateFileToExistingSendAsync_Success(SutProvider sutProvider, Send send) { @@ -593,7 +597,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public async void UpdateFileToExistingSendAsync_InvalidSize(SutProvider sutProvider, Send send) { @@ -618,7 +622,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public void SendCanBeAccessed_Success(SutProvider sutProvider, Send send) { var now = DateTime.UtcNow; @@ -641,7 +645,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public void SendCanBeAccessed_NullMaxAccess_Success(SutProvider sutProvider, Send send) { @@ -665,7 +669,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public void SendCanBeAccessed_NullSend_DoesNotGrantAccess(SutProvider sutProvider) { sutProvider.GetDependency>() @@ -681,7 +685,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public void SendCanBeAccessed_NullPassword_PasswordRequiredErrorReturnsTrue(SutProvider sutProvider, Send send) { @@ -706,7 +710,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public void SendCanBeAccessed_RehashNeeded_RehashesPassword(SutProvider sutProvider, Send send) { @@ -735,7 +739,7 @@ public class SendServiceTests } [Theory] - [InlineUserSendAutoData] + [BitAutoData] public void SendCanBeAccessed_VerifyFailed_PasswordInvalidReturnsTrue(SutProvider sutProvider, Send send) { diff --git a/test/Core.Test/Services/SsoConfigServiceTests.cs b/test/Core.Test/Services/SsoConfigServiceTests.cs index fa5cb904a..01899270a 100644 --- a/test/Core.Test/Services/SsoConfigServiceTests.cs +++ b/test/Core.Test/Services/SsoConfigServiceTests.cs @@ -11,9 +11,10 @@ using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] public class SsoConfigServiceTests { - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_ExistingItem_UpdatesRevisionDateOnly(SutProvider sutProvider, Organization organization) { @@ -41,7 +42,7 @@ public class SsoConfigServiceTests Assert.True(ssoConfig.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_NewItem_UpdatesCreationAndRevisionDate(SutProvider sutProvider, Organization organization) { @@ -69,7 +70,7 @@ public class SsoConfigServiceTests Assert.True(ssoConfig.RevisionDate - utcNow < TimeSpan.FromSeconds(1)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_PreventDisablingKeyConnector(SutProvider sutProvider, Organization organization) { @@ -113,7 +114,7 @@ public class SsoConfigServiceTests .UpsertAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_AllowDisablingKeyConnectorWhenNoUserIsUsingIt( SutProvider sutProvider, Organization organization) { @@ -151,7 +152,7 @@ public class SsoConfigServiceTests await sutProvider.Sut.SaveAsync(newSsoConfig, organization); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_KeyConnector_SingleOrgNotEnabled_Throws(SutProvider sutProvider, Organization organization) { @@ -179,7 +180,7 @@ public class SsoConfigServiceTests .UpsertAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_KeyConnector_SsoPolicyNotEnabled_Throws(SutProvider sutProvider, Organization organization) { @@ -213,7 +214,7 @@ public class SsoConfigServiceTests .UpsertAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_KeyConnector_SsoConfigNotEnabled_Throws(SutProvider sutProvider, Organization organization) { @@ -247,7 +248,7 @@ public class SsoConfigServiceTests .UpsertAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_KeyConnector_KeyConnectorAbilityNotEnabled_Throws(SutProvider sutProvider, Organization organization) { @@ -282,7 +283,7 @@ public class SsoConfigServiceTests .UpsertAsync(default); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SaveAsync_KeyConnector_Success(SutProvider sutProvider, Organization organization) { diff --git a/test/Core.Test/Services/StripePaymentServiceTests.cs b/test/Core.Test/Services/StripePaymentServiceTests.cs index a14f183d4..beb8406dc 100644 --- a/test/Core.Test/Services/StripePaymentServiceTests.cs +++ b/test/Core.Test/Services/StripePaymentServiceTests.cs @@ -14,16 +14,17 @@ using PaymentMethodType = Bit.Core.Enums.PaymentMethodType; namespace Bit.Core.Test.Services; +[SutProviderCustomize] public class StripePaymentServiceTests { [Theory] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.BitPay)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.BitPay)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.Credit)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.WireTransfer)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.AppleInApp)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.GoogleInApp)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, PaymentMethodType.Check)] + [BitAutoData(PaymentMethodType.BitPay)] + [BitAutoData(PaymentMethodType.BitPay)] + [BitAutoData(PaymentMethodType.Credit)] + [BitAutoData(PaymentMethodType.WireTransfer)] + [BitAutoData(PaymentMethodType.AppleInApp)] + [BitAutoData(PaymentMethodType.GoogleInApp)] + [BitAutoData(PaymentMethodType.Check)] public async void PurchaseOrganizationAsync_Invalid(PaymentMethodType paymentMethodType, SutProvider sutProvider) { var exception = await Assert.ThrowsAsync( @@ -32,7 +33,7 @@ public class StripePaymentServiceTests Assert.Equal("Payment method is not supported at this time.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Stripe(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -81,7 +82,7 @@ public class StripePaymentServiceTests )); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Stripe_PM(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -131,7 +132,7 @@ public class StripePaymentServiceTests )); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Stripe_TaxRate(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -160,7 +161,7 @@ public class StripePaymentServiceTests )); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Stripe_Declined(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -193,7 +194,7 @@ public class StripePaymentServiceTests await stripeAdapter.Received(1).CustomerDeleteAsync("C-1"); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Stripe_RequiresAction(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -224,7 +225,7 @@ public class StripePaymentServiceTests Assert.False(organization.Enabled); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Paypal(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -283,7 +284,7 @@ public class StripePaymentServiceTests )); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_Paypal_FailedCreate(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -300,7 +301,7 @@ public class StripePaymentServiceTests Assert.Equal("Failed to create PayPal customer record.", exception.Message); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void PurchaseOrganizationAsync_PayPal_Declined(SutProvider sutProvider, Organization organization, string paymentToken, TaxInfo taxInfo) { var plan = StaticStore.Plans.First(p => p.Type == PlanType.EnterpriseAnnually); @@ -344,7 +345,7 @@ public class StripePaymentServiceTests await braintreeGateway.Customer.Received(1).DeleteAsync("Braintree-Id"); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void UpgradeFreeOrganizationAsync_Success(SutProvider sutProvider, Organization organization, TaxInfo taxInfo) { diff --git a/test/Core.Test/Services/UserServiceTests.cs b/test/Core.Test/Services/UserServiceTests.cs index 5e82e4c40..845cf49b4 100644 --- a/test/Core.Test/Services/UserServiceTests.cs +++ b/test/Core.Test/Services/UserServiceTests.cs @@ -16,9 +16,10 @@ using Xunit; namespace Bit.Core.Test.Services; +[SutProviderCustomize] public class UserServiceTests { - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task UpdateLicenseAsync_Success(SutProvider sutProvider, User user, UserLicense userLicense) { @@ -55,7 +56,7 @@ public class UserServiceTests Assert.Equal(1, versionProp.GetInt32()); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SendTwoFactorEmailAsync_Success(SutProvider sutProvider, User user) { var email = user.Email.ToLowerInvariant(); @@ -86,7 +87,7 @@ public class UserServiceTests .SendTwoFactorEmailAsync(email, token); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SendTwoFactorEmailBecauseNewDeviceLoginAsync_Success(SutProvider sutProvider, User user) { var email = user.Email.ToLowerInvariant(); @@ -117,7 +118,7 @@ public class UserServiceTests .SendNewDeviceLoginTwoFactorEmailAsync(email, token); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SendTwoFactorEmailAsync_ExceptionBecauseNoProviderOnUser(SutProvider sutProvider, User user) { user.TwoFactorProviders = null; @@ -125,7 +126,7 @@ public class UserServiceTests await Assert.ThrowsAsync("No email.", () => sutProvider.Sut.SendTwoFactorEmailAsync(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SendTwoFactorEmailAsync_ExceptionBecauseNoProviderMetadataOnUser(SutProvider sutProvider, User user) { user.SetTwoFactorProviders(new Dictionary @@ -140,7 +141,7 @@ public class UserServiceTests await Assert.ThrowsAsync("No email.", () => sutProvider.Sut.SendTwoFactorEmailAsync(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task SendTwoFactorEmailAsync_ExceptionBecauseNoProviderEmailMetadataOnUser(SutProvider sutProvider, User user) { user.SetTwoFactorProviders(new Dictionary @@ -155,7 +156,7 @@ public class UserServiceTests await Assert.ThrowsAsync("No email.", () => sutProvider.Sut.SendTwoFactorEmailAsync(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsTrue(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -177,7 +178,7 @@ public class UserServiceTests Assert.True(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "password")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsFalse_When_GranType_Is_AuthorizationCode(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -195,7 +196,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "authorization_code")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsFalse_When_Email_Is_Not_Verified(SutProvider sutProvider, User user) { user.EmailVerified = false; @@ -213,7 +214,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "password")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsFalse_When_Is_The_First_Device(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -227,7 +228,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "password")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsFalse_When_DeviceId_Is_Already_In_Repo(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -244,7 +245,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "password")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsFalse_When_GlobalSettings_2FA_EmailOnNewDeviceLogin_Is_Disabled(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -264,7 +265,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "password")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async Task Needs2FABecauseNewDeviceAsync_ReturnsFalse_When_UnknownDeviceVerification_Is_Disabled(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -285,7 +286,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.Needs2FABecauseNewDeviceAsync(user, deviceIdToCheck, "password")); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public void CanEditDeviceVerificationSettings_ReturnsTrue(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -296,7 +297,7 @@ public class UserServiceTests Assert.True(sutProvider.Sut.CanEditDeviceVerificationSettings(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public void CanEditDeviceVerificationSettings_ReturnsFalse_When_GlobalSettings_2FA_EmailOnNewDeviceLogin_Is_Disabled(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -307,7 +308,7 @@ public class UserServiceTests Assert.False(sutProvider.Sut.CanEditDeviceVerificationSettings(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public void CanEditDeviceVerificationSettings_ReturnsFalse_When_Email_Is_Not_Verified(SutProvider sutProvider, User user) { user.EmailVerified = false; @@ -318,7 +319,7 @@ public class UserServiceTests Assert.False(sutProvider.Sut.CanEditDeviceVerificationSettings(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public void CanEditDeviceVerificationSettings_ReturnsFalse_When_User_Uses_Key_Connector(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -330,7 +331,7 @@ public class UserServiceTests Assert.False(sutProvider.Sut.CanEditDeviceVerificationSettings(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public void CanEditDeviceVerificationSettings_ReturnsFalse_When_User_Has_A_2FA_Already_Set_Up(SutProvider sutProvider, User user) { user.EmailVerified = true; @@ -348,7 +349,7 @@ public class UserServiceTests Assert.False(sutProvider.Sut.CanEditDeviceVerificationSettings(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void HasPremiumFromOrganization_Returns_False_If_No_Orgs(SutProvider sutProvider, User user) { sutProvider.GetDependency().GetManyByUserAsync(user.Id).Returns(new List()); @@ -357,8 +358,8 @@ public class UserServiceTests } [Theory] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, false, true)] - [InlineCustomAutoData(new[] { typeof(SutProviderCustomization) }, true, false)] + [BitAutoData(false, true)] + [BitAutoData(true, false)] public async void HasPremiumFromOrganization_Returns_False_If_Org_Not_Eligible(bool orgEnabled, bool orgUsersGetPremium, SutProvider sutProvider, User user, OrganizationUser orgUser, Organization organization) { orgUser.OrganizationId = organization.Id; @@ -372,7 +373,7 @@ public class UserServiceTests Assert.False(await sutProvider.Sut.HasPremiumFromOrganization(user)); } - [Theory, CustomAutoData(typeof(SutProviderCustomization))] + [Theory, BitAutoData] public async void HasPremiumFromOrganization_Returns_True_If_Org_Eligible(SutProvider sutProvider, User user, OrganizationUser orgUser, Organization organization) { orgUser.OrganizationId = organization.Id; diff --git a/test/Core.Test/Utilities/CoreHelpersTests.cs b/test/Core.Test/Utilities/CoreHelpersTests.cs index 76db48fe3..9b3909385 100644 --- a/test/Core.Test/Utilities/CoreHelpersTests.cs +++ b/test/Core.Test/Utilities/CoreHelpersTests.cs @@ -286,7 +286,7 @@ public class CoreHelpersTests Assert.Equal("Contents of embeddedResource.txt\n", fileContents.Replace("\r\n", "\n")); } - [Theory, CustomAutoData(typeof(UserFixture))] + [Theory, BitAutoData, UserCustomize] public void BuildIdentityClaims_BaseClaims_Success(User user, bool isPremium) { var expected = new Dictionary @@ -308,7 +308,7 @@ public class CoreHelpersTests Assert.Equal(expected.Count, actual.Count); } - [Theory, CustomAutoData(typeof(UserFixture))] + [Theory, BitAutoData, UserCustomize] public void BuildIdentityClaims_NonCustomOrganizationUserType_Success(User user) { var fixture = new Fixture().WithAutoNSubstitutions(); @@ -324,7 +324,7 @@ public class CoreHelpersTests } } - [Theory, CustomAutoData(typeof(UserFixture))] + [Theory, BitAutoData, UserCustomize] public void BuildIdentityClaims_CustomOrganizationUserClaims_Success(User user, CurrentContentOrganization org) { var fixture = new Fixture().WithAutoNSubstitutions(); @@ -346,7 +346,7 @@ public class CoreHelpersTests } } - [Theory, CustomAutoData(typeof(UserFixture))] + [Theory, BitAutoData, UserCustomize] public void BuildIdentityClaims_ProviderClaims_Success(User user) { var fixture = new Fixture().WithAutoNSubstitutions(); diff --git a/test/Infrastructure.EFIntegration.Test/AutoFixture/CipherFixtures.cs b/test/Infrastructure.EFIntegration.Test/AutoFixture/CipherFixtures.cs index 13d222316..71b89dc98 100644 --- a/test/Infrastructure.EFIntegration.Test/AutoFixture/CipherFixtures.cs +++ b/test/Infrastructure.EFIntegration.Test/AutoFixture/CipherFixtures.cs @@ -96,24 +96,12 @@ internal class EfCipher : ICustomization } } -internal class EfUserCipherAutoDataAttribute : CustomAutoDataAttribute +internal class EfUserCipherCustomizeAttribute : BitCustomizeAttribute { - public EfUserCipherAutoDataAttribute() : base(new SutProviderCustomization(), new EfCipher()) - { } + public override ICustomization GetCustomization() => new EfCipher(); } -internal class EfOrganizationCipherAutoDataAttribute : CustomAutoDataAttribute +internal class EfOrganizationCipherCustomizeAttribute : BitCustomizeAttribute { - public EfOrganizationCipherAutoDataAttribute() : base(new SutProviderCustomization(), new EfCipher() - { - OrganizationOwned = true, - }) - { } -} - -internal class InlineEfCipherAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineEfCipherAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(EfCipher) }, values) - { } + public override ICustomization GetCustomization() => new EfCipher(); } diff --git a/test/Infrastructure.EFIntegration.Test/AutoFixture/CollectionFixtures.cs b/test/Infrastructure.EFIntegration.Test/AutoFixture/CollectionFixtures.cs index 4cb6cfbd4..8068bfe54 100644 --- a/test/Infrastructure.EFIntegration.Test/AutoFixture/CollectionFixtures.cs +++ b/test/Infrastructure.EFIntegration.Test/AutoFixture/CollectionFixtures.cs @@ -43,15 +43,7 @@ internal class EfCollection : ICustomization } } -internal class EfCollectionAutoDataAttribute : CustomAutoDataAttribute +internal class EfCollectionCustomize : BitCustomizeAttribute { - public EfCollectionAutoDataAttribute() : base(new SutProviderCustomization(), new EfCollection()) - { } -} - -internal class InlineEfCollectionAutoDataAttribute : InlineCustomAutoDataAttribute -{ - public InlineEfCollectionAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), - typeof(EfCollection) }, values) - { } + public override ICustomization GetCustomization() => new EfCollection(); } diff --git a/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs b/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs index 9b70bffe7..e96a2a3b4 100644 --- a/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs +++ b/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs @@ -4,6 +4,7 @@ using Bit.Core.Test.AutoFixture.Attributes; using Bit.Infrastructure.EFIntegration.Test.AutoFixture; using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers; using Bit.Infrastructure.EntityFramework.Repositories.Queries; +using Bit.Test.Common.AutoFixture.Attributes; using LinqToDB; using Xunit; using EfRepo = Bit.Infrastructure.EntityFramework.Repositories; @@ -13,7 +14,7 @@ namespace Bit.Infrastructure.EFIntegration.Test.Repositories; public class CipherRepositoryTests { - [Theory(Skip = "Run ad-hoc"), EfUserCipherAutoData] + [Theory(Skip = "Run ad-hoc"), EfUserCipherCustomize, BitAutoData] public async void RefreshDb(List suts) { foreach (var sut in suts) @@ -22,8 +23,21 @@ public class CipherRepositoryTests } } - [CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData] - public async void CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org, + [CiSkippedTheory, EfUserCipherCustomize, BitAutoData] + public async void UserCipher_CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org, + CipherCompare equalityComparer, List suts, List efUserRepos, + List efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo, + SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo) => CreateAsync_Works_DataMatches( + cipher, user, org, equalityComparer, suts, efUserRepos, efOrgRepos, sqlCipherRepo, sqlUserRepo, sqlOrgRepo); + + [CiSkippedTheory, EfOrganizationCipherCustomize, BitAutoData] + public async void OrganizationCipher_CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org, + CipherCompare equalityComparer, List suts, List efUserRepos, + List efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo, + SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo) => CreateAsync_Works_DataMatches( + cipher, user, org, equalityComparer, suts, efUserRepos, efOrgRepos, sqlCipherRepo, sqlUserRepo, sqlOrgRepo); + + private async void CreateAsync_Works_DataMatches(Cipher cipher, User user, Organization org, CipherCompare equalityComparer, List suts, List efUserRepos, List efOrgRepos, SqlRepo.CipherRepository sqlCipherRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo) @@ -68,7 +82,7 @@ public class CipherRepositoryTests Assert.True(!distinctItems.Skip(1).Any()); } - [CiSkippedTheory, EfUserCipherAutoData] + [CiSkippedTheory, EfUserCipherCustomize, BitAutoData] public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user, List suts, List efUserRepos) { var bumpedUsers = new List(); @@ -91,7 +105,7 @@ public class CipherRepositoryTests Assert.True(bumpedUsers.All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString())); } - [CiSkippedTheory, EfOrganizationCipherAutoData] + [CiSkippedTheory, EfOrganizationCipherCustomize, BitAutoData] public async void CreateAsync_BumpsOrgUserAccountRevisionDates(Cipher cipher, List users, List orgUsers, Collection collection, Organization org, List suts, List efUserRepos, List efOrgRepos, List efOrgUserRepos, List efCollectionRepos) @@ -153,8 +167,26 @@ public class CipherRepositoryTests } } - [CiSkippedTheory, EfUserCipherAutoData, EfOrganizationCipherAutoData] - public async void DeleteAsync_CipherIsDeleted( + [CiSkippedTheory, EfUserCipherCustomize, BitAutoData] + public async Task UserCipher_DeleteAsync_CipherIsDeleted( + Cipher cipher, + User user, + Organization org, + List suts, + List efUserRepos, + List efOrgRepos + ) => await DeleteAsync_CipherIsDeleted(cipher, user, org, suts, efUserRepos, efOrgRepos); + [CiSkippedTheory, EfOrganizationCipherCustomize, BitAutoData] + public async Task OrganizationCipher_DeleteAsync_CipherIsDeleted( + Cipher cipher, + User user, + Organization org, + List suts, + List efUserRepos, + List efOrgRepos + ) => DeleteAsync_CipherIsDeleted(cipher, user, org, suts, efUserRepos, efOrgRepos); + + private async Task DeleteAsync_CipherIsDeleted( Cipher cipher, User user, Organization org, diff --git a/test/Infrastructure.EFIntegration.Test/Repositories/CollectionRepository.cs b/test/Infrastructure.EFIntegration.Test/Repositories/CollectionRepository.cs index 1fb20c684..eb3b26946 100644 --- a/test/Infrastructure.EFIntegration.Test/Repositories/CollectionRepository.cs +++ b/test/Infrastructure.EFIntegration.Test/Repositories/CollectionRepository.cs @@ -2,15 +2,17 @@ using Bit.Core.Test.AutoFixture.Attributes; using Bit.Infrastructure.EFIntegration.Test.AutoFixture; using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers; +using Bit.Test.Common.AutoFixture.Attributes; using Xunit; using EfRepo = Bit.Infrastructure.EntityFramework.Repositories; using SqlRepo = Bit.Infrastructure.Dapper.Repositories; namespace Bit.Infrastructure.EFIntegration.Test.Repositories; +[EfCollectionCustomize] public class CollectionRepositoryTests { - [CiSkippedTheory, EfCollectionAutoData] + [CiSkippedTheory, BitAutoData] public async void CreateAsync_Works_DataMatches( Collection collection, Organization organization,