Skip to content

Commit

Permalink
Step 2: Created default subscription, with default provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Jun 12, 2024
1 parent 6ed2bf5 commit 76dcdb6
Show file tree
Hide file tree
Showing 77 changed files with 1,671 additions and 339 deletions.
6 changes: 4 additions & 2 deletions src/Application.Interfaces/Services/IHostSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Application.Interfaces.Services;
using System.Net.Mime;

namespace Application.Interfaces.Services;

/// <summary>
/// Defines settings for the current API host
Expand Down Expand Up @@ -42,7 +44,7 @@ public interface IHostSettings
string GetWebsiteHostCSRFSigningSecret();

/// <summary>
/// Returns the URL for the specified <see cref="Image" />
/// Returns the URL for the specified <see cref="MediaTypeNames.Image" />
/// </summary>
string MakeImagesApiGetUrl(string imageId);
}
Expand Down
15 changes: 15 additions & 0 deletions src/Application.Resources.Shared/Subscriptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Application.Resources.Shared;

/// <summary>
/// Maintains the internal state for the billing provider
/// </summary>
public class BillingProviderState : Dictionary<string, string>
{
public BillingProviderState()
{
}

public BillingProviderState(Dictionary<string, string> properties) : base(properties)
{
}
}
6 changes: 3 additions & 3 deletions src/Application.Services.Shared/IBillingGatewayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IBillingGatewayService
/// Creates a new subscription the specified <see cref="buyer" />
/// </summary>
Task<Result<BillingProviderState, Error>> SubscribeAsync(ICallerContext caller, SubscriptionBuyer buyer,
SubscribeOptions options);
SubscribeOptions options, CancellationToken cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -54,14 +54,14 @@ public class SubscriptionBuyer
{
public required ProfileAddress Address { get; set; }

public required BuyerOrganization Organization { get; set; }

public required string EmailAddress { get; set; }

public required string Id { get; set; }

public required PersonName Name { get; set; }

public required BuyerOrganization Organization { get; set; }

public string? PhoneNumber { get; set; }
}

Expand Down
10 changes: 6 additions & 4 deletions src/Application.Services.Shared/IBillingProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Domain.Services.Shared;

namespace Application.Services.Shared;

/// <summary>
Expand All @@ -6,14 +8,14 @@ namespace Application.Services.Shared;
public interface IBillingProvider
{
/// <summary>
/// returns the name of the provider
/// Returns the gateway service for the provider
/// </summary>
string ProviderName { get; }
public IBillingGatewayService GatewayService { get; }

/// <summary>
/// Returns the gateway service for the provider
/// returns the name of the provider
/// </summary>
public IBillingGatewayService GatewayService { get; }
string ProviderName { get; }

/// <summary>
/// Returns the proxy to manage state changes to the provider
Expand Down
139 changes: 139 additions & 0 deletions src/Common.UnitTests/CurrencyCodesSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using Common.Extensions;
using FluentAssertions;
using ISO._4217;
using Xunit;

namespace Common.UnitTests;

[Trait("Category", "Unit")]
public class CurrencyCodesSpec
{
[Fact]
public void WhenExistsAndUnknown_ThenReturnsFalse()
{
var result = CurrencyCodes.Exists("notacurrencycode");

result.Should().BeFalse();
}

[Fact]
public void WhenExistsByCode_ThenReturnsTrue()
{
var result = CurrencyCodes.Exists(CurrencyCodes.Default.Code);

result.Should().BeTrue();
}

[Fact]
public void WhenExistsByNumeric_ThenReturnsTrue()
{
var result = CurrencyCodes.Exists(CurrencyCodes.Default.Numeric);

result.Should().BeTrue();
}

[Fact]
public void WhenFindAndUnknown_ThenReturnsNull()
{
var result = CurrencyCodes.Find("notacurrencycode");

result.Should().BeNull();
}

[Fact]
public void WhenFindByCode_ThenReturnsTrue()
{
var result = CurrencyCodes.Find(CurrencyCodes.Default.Code);

result.Should().Be(CurrencyCodes.Default);
}

[Fact]
public void WhenFindByNumeric_ThenReturnsTrue()
{
var result = CurrencyCodes.Find(CurrencyCodes.Default.Numeric);

result.Should().Be(CurrencyCodes.Default);
}

[Fact]
public void WhenFindForEveryCurrency_ThenReturnsCode()
{
var currencies = CurrencyCodesResolver.Codes
.Where(cur => cur.Code.HasValue())
.ToList();
foreach (var currency in currencies)
{
var result = CurrencyCodes.Find(currency.Code);

result.Should().NotBeNull($"{currency.Name} should have been found by Code");
}

foreach (var currency in currencies)
{
var result = CurrencyCodes.Find(currency.Num);

result.Should().NotBeNull($"{currency.Name} should have been found by NumericCode");
}
}

[Fact]
public void WhenCreateIso4217_ThenReturnsInstance()
{
var result = CurrencyCodeIso4217.Create("ashortname", "analpha2", "100", CurrencyDecimalKind.TwoDecimal);

result.ShortName.Should().Be("ashortname");
result.Code.Should().Be("analpha2");
result.Kind.Should().Be(CurrencyDecimalKind.TwoDecimal);
result.Numeric.Should().Be("100");
}

[Fact]
public void WhenEqualsAndNotTheSameNumeric_ThenReturnsFalse()
{
var currency1 = CurrencyCodeIso4217.Create("ashortname", "analpha2", "100", CurrencyDecimalKind.Unknown);
var currency2 = CurrencyCodeIso4217.Create("ashortname", "analpha2", "101", CurrencyDecimalKind.Unknown);

var result = currency1 == currency2;

result.Should().BeFalse();
}

[Fact]
public void WhenEqualsAndSameNumeric_ThenReturnsTrue()
{
var currency1 = CurrencyCodeIso4217.Create("ashortname1", "analpha21", "100", CurrencyDecimalKind.Unknown);
var currency2 = CurrencyCodeIso4217.Create("ashortname2", "analpha22", "100", CurrencyDecimalKind.Unknown);

var result = currency1 == currency2;

result.Should().BeTrue();
}

[Fact]
public void WhenToCurrencyWithAThousandAndOne_ThenReturnsUnitedStatesDollars()
{
var code = CurrencyCodes.UnitedStatesDollar.Code;
var result = CurrencyCodes.ToCurrency(code, 1001);

result.Should().Be(10.01M);
}

[Fact]
public void WhenToCurrencyWithAThousandAndOne_ThenReturnsKuwaitiDinars()
{
var code = CurrencyCodes.KuwaitiDinar.Code;
var result = CurrencyCodes.ToCurrency(code, 1001);

result.Should().Be(1.001M);
}

[Fact]
public void WhenToCurrencyWithAThousandAndOne_ThenReturnsChileanFomentos()
{
var code = CurrencyCodes.ChileanFomento.Code;
var result = CurrencyCodes.ToCurrency(code, 1001);

result.Should().Be(0.1001M);
}
}
1 change: 1 addition & 0 deletions src/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="ISO.3166.CountryCodes" Version="1.0.3" />
<PackageReference Include="ISO.4217.CurrencyCodes" Version="1.0.10" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageReference Include="NodaTime" Version="3.1.6" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 76dcdb6

Please sign in to comment.