using Bit.Api.Billing.Controllers.VNext; using Bit.Core.Billing.Licenses.Queries; using Bit.Core.Billing.Payment.Commands; using Bit.Core.Billing.Payment.Queries; using Bit.Core.Billing.Premium.Commands; using Bit.Core.Entities; using Bit.Test.Common.AutoFixture.Attributes; using Microsoft.AspNetCore.Http; using NSubstitute; using Xunit; namespace Bit.Api.Test.Billing.Controllers.VNext; public class AccountBillingVNextControllerTests { private readonly ICreateBitPayInvoiceForCreditCommand _createBitPayInvoiceForCreditCommand; private readonly ICreatePremiumCloudHostedSubscriptionCommand _createPremiumCloudHostedSubscriptionCommand; private readonly IGetCreditQuery _getCreditQuery; private readonly IGetPaymentMethodQuery _getPaymentMethodQuery; private readonly IGetUserLicenseQuery _getUserLicenseQuery; private readonly IUpdatePaymentMethodCommand _updatePaymentMethodCommand; private readonly AccountBillingVNextController _sut; public AccountBillingVNextControllerTests() { _createBitPayInvoiceForCreditCommand = Substitute.For(); _createPremiumCloudHostedSubscriptionCommand = Substitute.For(); _getCreditQuery = Substitute.For(); _getPaymentMethodQuery = Substitute.For(); _getUserLicenseQuery = Substitute.For(); _updatePaymentMethodCommand = Substitute.For(); _sut = new AccountBillingVNextController( _createBitPayInvoiceForCreditCommand, _createPremiumCloudHostedSubscriptionCommand, _getCreditQuery, _getPaymentMethodQuery, _getUserLicenseQuery, _updatePaymentMethodCommand); } [Theory, BitAutoData] public async Task GetLicenseAsync_ValidUser_ReturnsLicenseResponse(User user, Core.Billing.Licenses.Models.Api.Response.LicenseResponseModel licenseResponse) { // Arrange _getUserLicenseQuery.Run(user).Returns(licenseResponse); // Act var result = await _sut.GetLicenseAsync(user); // Assert var okResult = Assert.IsAssignableFrom(result); await _getUserLicenseQuery.Received(1).Run(user); } }