|
|
|
@ -34,6 +34,7 @@ using Bit.Test.Common.AutoFixture.Attributes; |
|
|
|
using Bit.Test.Common.Fakes; |
|
|
|
using Bit.Test.Common.Fakes; |
|
|
|
using NSubstitute; |
|
|
|
using NSubstitute; |
|
|
|
using NSubstitute.ExceptionExtensions; |
|
|
|
using NSubstitute.ExceptionExtensions; |
|
|
|
|
|
|
|
using NSubstitute.ReturnsExtensions; |
|
|
|
using Xunit; |
|
|
|
using Xunit; |
|
|
|
using Organization = Bit.Core.Entities.Organization; |
|
|
|
using Organization = Bit.Core.Entities.Organization; |
|
|
|
using OrganizationUser = Bit.Core.Entities.OrganizationUser; |
|
|
|
using OrganizationUser = Bit.Core.Entities.OrganizationUser; |
|
|
|
@ -1606,15 +1607,16 @@ public class OrganizationServiceTests |
|
|
|
[BitAutoData(0, null, 100, true, "")] |
|
|
|
[BitAutoData(0, null, 100, true, "")] |
|
|
|
[BitAutoData(1, 100, null, true, "")] |
|
|
|
[BitAutoData(1, 100, null, true, "")] |
|
|
|
[BitAutoData(1, 100, 100, false, "Seat limit has been reached")] |
|
|
|
[BitAutoData(1, 100, 100, false, "Seat limit has been reached")] |
|
|
|
public void CanScale(int seatsToAdd, int? currentSeats, int? maxAutoscaleSeats, |
|
|
|
public async Task CanScaleAsync(int seatsToAdd, int? currentSeats, int? maxAutoscaleSeats, |
|
|
|
bool expectedResult, string expectedFailureMessage, Organization organization, |
|
|
|
bool expectedResult, string expectedFailureMessage, Organization organization, |
|
|
|
SutProvider<OrganizationService> sutProvider) |
|
|
|
SutProvider<OrganizationService> sutProvider) |
|
|
|
{ |
|
|
|
{ |
|
|
|
organization.Seats = currentSeats; |
|
|
|
organization.Seats = currentSeats; |
|
|
|
organization.MaxAutoscaleSeats = maxAutoscaleSeats; |
|
|
|
organization.MaxAutoscaleSeats = maxAutoscaleSeats; |
|
|
|
sutProvider.GetDependency<ICurrentContext>().ManageUsers(organization.Id).Returns(true); |
|
|
|
sutProvider.GetDependency<ICurrentContext>().ManageUsers(organization.Id).Returns(true); |
|
|
|
|
|
|
|
sutProvider.GetDependency<IProviderRepository>().GetByOrganizationIdAsync(organization.Id).ReturnsNull(); |
|
|
|
|
|
|
|
|
|
|
|
var (result, failureMessage) = sutProvider.Sut.CanScale(organization, seatsToAdd); |
|
|
|
var (result, failureMessage) = await sutProvider.Sut.CanScaleAsync(organization, seatsToAdd); |
|
|
|
|
|
|
|
|
|
|
|
if (expectedFailureMessage == string.Empty) |
|
|
|
if (expectedFailureMessage == string.Empty) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -1628,16 +1630,35 @@ public class OrganizationServiceTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory, PaidOrganizationCustomize, BitAutoData] |
|
|
|
[Theory, PaidOrganizationCustomize, BitAutoData] |
|
|
|
public void CanScale_FailsOnSelfHosted(Organization organization, |
|
|
|
public async Task CanScaleAsync_FailsOnSelfHosted(Organization organization, |
|
|
|
SutProvider<OrganizationService> sutProvider) |
|
|
|
SutProvider<OrganizationService> sutProvider) |
|
|
|
{ |
|
|
|
{ |
|
|
|
sutProvider.GetDependency<IGlobalSettings>().SelfHosted.Returns(true); |
|
|
|
sutProvider.GetDependency<IGlobalSettings>().SelfHosted.Returns(true); |
|
|
|
var (result, failureMessage) = sutProvider.Sut.CanScale(organization, 10); |
|
|
|
var (result, failureMessage) = await sutProvider.Sut.CanScaleAsync(organization, 10); |
|
|
|
|
|
|
|
|
|
|
|
Assert.False(result); |
|
|
|
Assert.False(result); |
|
|
|
Assert.Contains("Cannot autoscale on self-hosted instance", failureMessage); |
|
|
|
Assert.Contains("Cannot autoscale on self-hosted instance", failureMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Theory, PaidOrganizationCustomize, BitAutoData] |
|
|
|
|
|
|
|
public async Task CanScaleAsync_FailsOnResellerManagedOrganization( |
|
|
|
|
|
|
|
Organization organization, |
|
|
|
|
|
|
|
SutProvider<OrganizationService> sutProvider) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var provider = new Provider |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Enabled = true, |
|
|
|
|
|
|
|
Type = ProviderType.Reseller |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IProviderRepository>().GetByOrganizationIdAsync(organization.Id).Returns(provider); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (result, failureMessage) = await sutProvider.Sut.CanScaleAsync(organization, 10); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.False(result); |
|
|
|
|
|
|
|
Assert.Contains("Seat limit has been reached. Contact your provider to purchase additional seats.", failureMessage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory, PaidOrganizationCustomize, BitAutoData] |
|
|
|
[Theory, PaidOrganizationCustomize, BitAutoData] |
|
|
|
public async Task Delete_Success(Organization organization, SutProvider<OrganizationService> sutProvider) |
|
|
|
public async Task Delete_Success(Organization organization, SutProvider<OrganizationService> sutProvider) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|