1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

Turn on file scoped namespaces (#2225)

This commit is contained in:
Justin Baur
2022-08-29 14:53:16 -04:00
committed by GitHub
parent 7c4521e0b4
commit 34fb4cca2a
1206 changed files with 73816 additions and 75022 deletions

View File

@ -9,53 +9,52 @@ using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.Services
namespace Bit.Core.Test.Services;
[SutProviderCustomize]
public class LicensingServiceTests
{
[SutProviderCustomize]
public class LicensingServiceTests
private static string licenseFilePath(Guid orgId) =>
Path.Combine(OrganizationLicenseDirectory.Value, $"{orgId}.json");
private static string LicenseDirectory => Path.GetDirectoryName(OrganizationLicenseDirectory.Value);
private static Lazy<string> OrganizationLicenseDirectory => new(() =>
{
private static string licenseFilePath(Guid orgId) =>
Path.Combine(OrganizationLicenseDirectory.Value, $"{orgId}.json");
private static string LicenseDirectory => Path.GetDirectoryName(OrganizationLicenseDirectory.Value);
private static Lazy<string> OrganizationLicenseDirectory => new(() =>
var directory = Path.Combine(Path.GetTempPath(), "organization");
if (!Directory.Exists(directory))
{
var directory = Path.Combine(Path.GetTempPath(), "organization");
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
return directory;
});
public static SutProvider<LicensingService> GetSutProvider()
{
var fixture = new Fixture().WithAutoNSubstitutions();
var settings = fixture.Create<IGlobalSettings>();
settings.LicenseDirectory = LicenseDirectory;
settings.SelfHosted = true;
return new SutProvider<LicensingService>(fixture)
.SetDependency(settings)
.Create();
Directory.CreateDirectory(directory);
}
return directory;
});
[Theory, BitAutoData, OrganizationLicenseCustomize]
public async Task ReadOrganizationLicense(Organization organization, OrganizationLicense license)
public static SutProvider<LicensingService> GetSutProvider()
{
var fixture = new Fixture().WithAutoNSubstitutions();
var settings = fixture.Create<IGlobalSettings>();
settings.LicenseDirectory = LicenseDirectory;
settings.SelfHosted = true;
return new SutProvider<LicensingService>(fixture)
.SetDependency(settings)
.Create();
}
[Theory, BitAutoData, OrganizationLicenseCustomize]
public async Task ReadOrganizationLicense(Organization organization, OrganizationLicense license)
{
var sutProvider = GetSutProvider();
File.WriteAllText(licenseFilePath(organization.Id), JsonSerializer.Serialize(license));
var actual = await sutProvider.Sut.ReadOrganizationLicenseAsync(organization);
try
{
var sutProvider = GetSutProvider();
File.WriteAllText(licenseFilePath(organization.Id), JsonSerializer.Serialize(license));
var actual = await sutProvider.Sut.ReadOrganizationLicenseAsync(organization);
try
{
Assert.Equal(JsonSerializer.Serialize(license), JsonSerializer.Serialize(actual));
}
finally
{
Directory.Delete(OrganizationLicenseDirectory.Value, true);
}
Assert.Equal(JsonSerializer.Serialize(license), JsonSerializer.Serialize(actual));
}
finally
{
Directory.Delete(OrganizationLicenseDirectory.Value, true);
}
}
}