2024-06-24 17:15:47 +02:00
|
|
|
|
using Bit.Api.Billing.Controllers;
|
|
|
|
|
using Bit.Core.AdminConsole.Entities.Provider;
|
|
|
|
|
using Bit.Core.AdminConsole.Enums.Provider;
|
|
|
|
|
using Bit.Core.AdminConsole.Repositories;
|
|
|
|
|
using Bit.Core.Context;
|
2024-07-31 15:26:44 +02:00
|
|
|
|
using Bit.Core.Models.Api;
|
2024-06-24 17:15:47 +02:00
|
|
|
|
using Bit.Test.Common.AutoFixture;
|
2024-07-31 15:26:44 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
2024-06-24 17:15:47 +02:00
|
|
|
|
using NSubstitute;
|
2024-07-31 15:26:44 +02:00
|
|
|
|
using Xunit;
|
2024-06-24 17:15:47 +02:00
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.Billing;
|
|
|
|
|
|
|
|
|
|
public static class Utilities
|
|
|
|
|
{
|
2024-07-31 15:26:44 +02:00
|
|
|
|
public static void AssertNotFound(IResult result)
|
|
|
|
|
{
|
|
|
|
|
Assert.IsType<NotFound<ErrorResponseModel>>(result);
|
|
|
|
|
|
|
|
|
|
var response = ((NotFound<ErrorResponseModel>)result).Value;
|
|
|
|
|
|
|
|
|
|
Assert.Equal("Resource not found.", response.Message);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 20:11:10 +01:00
|
|
|
|
public static void AssertUnauthorized(IResult result, string message = "Unauthorized.")
|
2024-07-31 15:26:44 +02:00
|
|
|
|
{
|
|
|
|
|
Assert.IsType<JsonHttpResult<ErrorResponseModel>>(result);
|
|
|
|
|
|
|
|
|
|
var response = (JsonHttpResult<ErrorResponseModel>)result;
|
|
|
|
|
|
|
|
|
|
Assert.Equal(StatusCodes.Status401Unauthorized, response.StatusCode);
|
2024-11-12 20:11:10 +01:00
|
|
|
|
Assert.Equal(message, response.Value.Message);
|
2024-07-31 15:26:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:48:14 +02:00
|
|
|
|
public static void ConfigureStableProviderAdminInputs<T>(
|
2024-06-24 17:15:47 +02:00
|
|
|
|
Provider provider,
|
|
|
|
|
SutProvider<T> sutProvider) where T : BaseProviderController
|
|
|
|
|
{
|
2024-08-28 16:48:14 +02:00
|
|
|
|
ConfigureBaseProviderInputs(provider, sutProvider);
|
2024-06-24 17:15:47 +02:00
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().ProviderProviderAdmin(provider.Id)
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:48:14 +02:00
|
|
|
|
public static void ConfigureStableProviderServiceUserInputs<T>(
|
2024-06-24 17:15:47 +02:00
|
|
|
|
Provider provider,
|
|
|
|
|
SutProvider<T> sutProvider) where T : BaseProviderController
|
|
|
|
|
{
|
2024-08-28 16:48:14 +02:00
|
|
|
|
ConfigureBaseProviderInputs(provider, sutProvider);
|
2024-06-24 17:15:47 +02:00
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().ProviderUser(provider.Id)
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:48:14 +02:00
|
|
|
|
private static void ConfigureBaseProviderInputs<T>(
|
2024-06-24 17:15:47 +02:00
|
|
|
|
Provider provider,
|
|
|
|
|
SutProvider<T> sutProvider) where T : BaseProviderController
|
|
|
|
|
{
|
|
|
|
|
provider.Type = ProviderType.Msp;
|
|
|
|
|
provider.Status = ProviderStatusType.Billable;
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(provider.Id).Returns(provider);
|
|
|
|
|
}
|
|
|
|
|
}
|