diff options
| -rw-r--r-- | src/IOL.VippsEcommerce.Tests/Helpers.cs | 22 | ||||
| -rw-r--r-- | src/IOL.VippsEcommerce.Tests/InitialisationTests.cs (renamed from src/IOL.VippsEcommerce.Tests/Integration/InitialisationTests.cs) | 25 | ||||
| -rw-r--r-- | src/IOL.VippsEcommerce.Tests/PaymentInitiationTests.cs | 13 |
3 files changed, 38 insertions, 22 deletions
diff --git a/src/IOL.VippsEcommerce.Tests/Helpers.cs b/src/IOL.VippsEcommerce.Tests/Helpers.cs new file mode 100644 index 0000000..9f89c1a --- /dev/null +++ b/src/IOL.VippsEcommerce.Tests/Helpers.cs @@ -0,0 +1,22 @@ +using System; +using IOL.VippsEcommerce.Models; +using Microsoft.Extensions.DependencyInjection; +using Xunit.Sdk; + +namespace IOL.VippsEcommerce.Tests +{ + public static class Helpers + { + public static IVippsEcommerceService GetVippsEcommerceService(Action<VippsConfiguration> conf) { + var services = new ServiceCollection(); + services.AddVippsEcommerceService(conf); + var provider = services.BuildServiceProvider(); + var vippsEcommerceService = provider.GetService<IVippsEcommerceService>(); + if (vippsEcommerceService == default) { + throw new NullException(nameof(vippsEcommerceService)); + } + + return vippsEcommerceService; + } + } +}
\ No newline at end of file diff --git a/src/IOL.VippsEcommerce.Tests/Integration/InitialisationTests.cs b/src/IOL.VippsEcommerce.Tests/InitialisationTests.cs index 6035c15..aa05a7d 100644 --- a/src/IOL.VippsEcommerce.Tests/Integration/InitialisationTests.cs +++ b/src/IOL.VippsEcommerce.Tests/InitialisationTests.cs @@ -1,11 +1,9 @@ -using System.Collections.Generic; -using System.Text.Json; using IOL.VippsEcommerce.Models; using Microsoft.Extensions.DependencyInjection; using Xunit; using Xunit.Abstractions; -namespace IOL.VippsEcommerce.Tests.Integration +namespace IOL.VippsEcommerce.Tests { public class InitialisationTests { @@ -17,29 +15,19 @@ namespace IOL.VippsEcommerce.Tests.Integration [Fact] public void Succeed_On_Valid_Minimal_Configuration() { - var services = new ServiceCollection(); - services.AddVippsEcommerceService(o => { + var vippsEcommerceService = Helpers.GetVippsEcommerceService(o => { o.ApiUrl = "https://validuri.no"; o.ClientId = "asdf"; o.ClientSecret = "asdf"; o.SecondarySubscriptionKey = "asdf"; }); - var provider = services.BuildServiceProvider(); - var vippsEcommerceService = provider.GetService<IVippsEcommerceService>(); - if (vippsEcommerceService == default) { - _helper.WriteLine(nameof(IVippsEcommerceService) + " was default"); - return; - } vippsEcommerceService.Configuration.Verify(); - Assert.True(true); } - [Fact] public void Configuration_Follows_Through_Initialisation() { - var services = new ServiceCollection(); - services.AddVippsEcommerceService(o => { + var vippsEcommerceService = Helpers.GetVippsEcommerceService(o => { o.ApiUrl = "https://validuri.no"; o.ClientId = "asdf"; o.ClientSecret = "asdf"; @@ -54,13 +42,6 @@ namespace IOL.VippsEcommerce.Tests.Integration o.CacheEncryptionKey = "asdf"; o.ConfigurationMode = VippsConfigurationMode.ONLY_OBJECT; }); - var provider = services.BuildServiceProvider(); - var vippsEcommerceService = provider.GetService<IVippsEcommerceService>(); - - if (vippsEcommerceService == default) { - _helper.WriteLine(nameof(IVippsEcommerceService) + " was default"); - return; - } foreach (var prop in typeof(VippsConfiguration).GetProperties()) { var value = prop.GetValue(vippsEcommerceService.Configuration, null); diff --git a/src/IOL.VippsEcommerce.Tests/PaymentInitiationTests.cs b/src/IOL.VippsEcommerce.Tests/PaymentInitiationTests.cs new file mode 100644 index 0000000..d802fb1 --- /dev/null +++ b/src/IOL.VippsEcommerce.Tests/PaymentInitiationTests.cs @@ -0,0 +1,13 @@ +using Xunit.Abstractions; + +namespace IOL.VippsEcommerce.Tests +{ + public class PaymentInitiationTests + { + private readonly ITestOutputHelper _helper; + + public PaymentInitiationTests(ITestOutputHelper helper) { + _helper = helper; + } + } +}
\ No newline at end of file |
