From fbf3e0dcdcb97189a99d977f5f29c859907d76e4 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Mon, 27 Sep 2021 19:34:55 +0200 Subject: [PATCH] Run full test suite (#1597) * Run all tests --- .github/workflows/build.yml | 4 +- .../Services/ProviderServiceTests.cs | 42 ++++++++++++------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77128fa752..8b518b7b12 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,7 +69,9 @@ jobs: shell: pwsh - name: Test solution - run: dotnet test .\test\Core.Test\Core.Test.csproj --configuration Debug --no-build + run: | + dotnet test ./test --configuration Debug --no-build + dotnet test ./bitwarden_license/test/CmmCore.Test --configuration Debug --no-build shell: pwsh diff --git a/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs b/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs index 1e639ea88a..a46d854432 100644 --- a/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs +++ b/bitwarden_license/test/CmmCore.Test/Services/ProviderServiceTests.cs @@ -100,7 +100,7 @@ namespace Bit.CommCore.Test.Services { provider.Id = default; - var exception = await Assert.ThrowsAsync( + var exception = await Assert.ThrowsAsync( () => sutProvider.Sut.UpdateAsync(provider)); Assert.Contains("Cannot create provider this way.", exception.Message); } @@ -113,15 +113,17 @@ namespace Bit.CommCore.Test.Services [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task InviteUserAsync_ProviderIdIsInvalid_Throws(ProviderUserInvite invite, SutProvider sutProvider) - { + { + sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(true); + await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(invite)); } [Theory, CustomAutoData(typeof(SutProviderCustomization))] public async Task InviteUserAsync_InvalidPermissions_Throws(ProviderUserInvite invite, SutProvider sutProvider) - { + { sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(false); - await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(invite)); + await Assert.ThrowsAsync(() => sutProvider.Sut.InviteUserAsync(invite)); } [Theory, CustomAutoData(typeof(SutProviderCustomization))] @@ -130,6 +132,7 @@ namespace Bit.CommCore.Test.Services { var providerRepository = sutProvider.GetDependency(); providerRepository.GetByIdAsync(providerUserInvite.ProviderId).Returns(provider); + sutProvider.GetDependency().ProviderManageUsers(providerUserInvite.ProviderId).Returns(true); providerUserInvite.UserIdentifiers = null; @@ -144,6 +147,7 @@ namespace Bit.CommCore.Test.Services providerRepository.GetByIdAsync(providerUserInvite.ProviderId).Returns(provider); var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetCountByProviderAsync(default, default, default).ReturnsForAnyArgs(1); + sutProvider.GetDependency().ProviderManageUsers(providerUserInvite.ProviderId).Returns(true); var result = await sutProvider.Sut.InviteUserAsync(providerUserInvite); Assert.Empty(result); @@ -157,6 +161,7 @@ namespace Bit.CommCore.Test.Services providerRepository.GetByIdAsync(providerUserInvite.ProviderId).Returns(provider); var providerUserRepository = sutProvider.GetDependency(); providerUserRepository.GetCountByProviderAsync(default, default, default).ReturnsForAnyArgs(0); + sutProvider.GetDependency().ProviderManageUsers(providerUserInvite.ProviderId).Returns(true); var result = await sutProvider.Sut.InviteUserAsync(providerUserInvite); Assert.Equal(providerUserInvite.UserIdentifiers.Count(), result.Count); @@ -182,16 +187,18 @@ namespace Bit.CommCore.Test.Services var providerUsers = new[] {pu1, pu2, pu3, pu4}; pu1.ProviderId = pu2.ProviderId = pu3.ProviderId = provider.Id; - var providerRepository = sutProvider.GetDependency(); - providerRepository.GetByIdAsync(provider.Id).Returns(provider); - var providerUserRepository = sutProvider.GetDependency(); - providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers.ToList()); - var invite = new ProviderUserInvite { UserIdentifiers = providerUsers.Select(pu => pu.Id), ProviderId = provider.Id }; + + var providerRepository = sutProvider.GetDependency(); + providerRepository.GetByIdAsync(provider.Id).Returns(provider); + var providerUserRepository = sutProvider.GetDependency(); + providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers.ToList()); + sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(true); + var result = await sutProvider.Sut.ResendInvitesAsync(invite); Assert.Equal("", result[0].Item2); Assert.Equal("User invalid.", result[1].Item2); @@ -208,17 +215,19 @@ namespace Bit.CommCore.Test.Services providerUser.ProviderId = provider.Id; providerUser.Status = ProviderUserStatusType.Invited; } - - var providerRepository = sutProvider.GetDependency(); - providerRepository.GetByIdAsync(provider.Id).Returns(provider); - var providerUserRepository = sutProvider.GetDependency(); - providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers.ToList()); var invite = new ProviderUserInvite { UserIdentifiers = providerUsers.Select(pu => pu.Id), ProviderId = provider.Id }; + + var providerRepository = sutProvider.GetDependency(); + providerRepository.GetByIdAsync(provider.Id).Returns(provider); + var providerUserRepository = sutProvider.GetDependency(); + providerUserRepository.GetManyAsync(default).ReturnsForAnyArgs(providerUsers.ToList()); + sutProvider.GetDependency().ProviderManageUsers(invite.ProviderId).Returns(true); + var result = await sutProvider.Sut.ResendInvitesAsync(invite); Assert.True(result.All(r => r.Item2 == "")); } @@ -441,9 +450,12 @@ namespace Bit.CommCore.Test.Services public async Task AddOrganization_Success(Provider provider, Organization organization, User user, string key, SutProvider sutProvider) { + organization.PlanType = PlanType.EnterpriseAnnually; + sutProvider.GetDependency().GetByIdAsync(provider.Id).Returns(provider); var providerOrganizationRepository = sutProvider.GetDependency(); providerOrganizationRepository.GetByOrganizationId(organization.Id).ReturnsNull(); + sutProvider.GetDependency().GetByIdAsync(organization.Id).Returns(organization); await sutProvider.Sut.AddOrganization(provider.Id, organization.Id, user.Id, key); @@ -457,6 +469,8 @@ namespace Bit.CommCore.Test.Services public async Task CreateOrganizationAsync_Success(Provider provider, OrganizationSignup organizationSignup, Organization organization, string clientOwnerEmail, User user, SutProvider sutProvider) { + organizationSignup.Plan = PlanType.EnterpriseAnnually; + sutProvider.GetDependency().GetByIdAsync(provider.Id).Returns(provider); var providerOrganizationRepository = sutProvider.GetDependency(); sutProvider.GetDependency().SignUpAsync(organizationSignup, true)