1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-01 13:43:23 +01:00
bitwarden-server/test/Api.Test/Models/Request/Accounts/PremiumRequestModelTests.cs

65 lines
2.2 KiB
C#
Raw Normal View History

using Bit.Api.Models.Request.Accounts;
using Bit.Core.Settings;
using Microsoft.AspNetCore.Http;
using Xunit;
2022-08-29 22:06:55 +02:00
namespace Bit.Api.Test.Models.Request.Accounts;
public class PremiumRequestModelTests
{
2022-08-29 22:06:55 +02:00
public static IEnumerable<object[]> GetValidateData()
{
2022-08-29 22:06:55 +02:00
// 1. selfHosted
// 2. formFile
// 3. country
// 4. expected
2022-08-29 22:06:55 +02:00
yield return new object[] { true, null, null, false };
yield return new object[] { true, null, "US", false };
yield return new object[] { true, new NotImplementedFormFile(), null, false };
yield return new object[] { true, new NotImplementedFormFile(), "US", false };
2022-08-29 22:06:55 +02:00
yield return new object[] { false, null, null, false };
yield return new object[] { false, null, "US", true }; // Only true, cloud with null license AND a Country
yield return new object[] { false, new NotImplementedFormFile(), null, false };
yield return new object[] { false, new NotImplementedFormFile(), "US", false };
}
2022-08-29 22:06:55 +02:00
[Theory]
[MemberData(nameof(GetValidateData))]
public void Validate_Success(bool selfHosted, IFormFile formFile, string country, bool expected)
{
var gs = new GlobalSettings
{
2022-08-29 22:06:55 +02:00
SelfHosted = selfHosted
};
2022-08-29 22:06:55 +02:00
var sut = new PremiumRequestModel
{
License = formFile,
Country = country,
};
2022-08-29 22:06:55 +02:00
Assert.Equal(expected, sut.Validate(gs));
}
2022-08-29 22:06:55 +02:00
}
2022-08-29 22:06:55 +02:00
public class NotImplementedFormFile : IFormFile
{
public string ContentType => throw new NotImplementedException();
2022-08-29 22:06:55 +02:00
public string ContentDisposition => throw new NotImplementedException();
2022-08-29 22:06:55 +02:00
public IHeaderDictionary Headers => throw new NotImplementedException();
2022-08-29 22:06:55 +02:00
public long Length => throw new NotImplementedException();
2022-08-29 22:06:55 +02:00
public string Name => throw new NotImplementedException();
2022-08-29 22:06:55 +02:00
public string FileName => throw new NotImplementedException();
2022-08-29 22:06:55 +02:00
public void CopyTo(Stream target) => throw new NotImplementedException();
public Task CopyToAsync(Stream target, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public Stream OpenReadStream() => throw new NotImplementedException();
}