From 1148f01f768ec2bb7bd089a213f02773f37e4dd8 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Sat, 6 Oct 2018 01:54:49 +0200 Subject: [PATCH] Add some missing tests --- src/StripeTests/NullableValueTypes.cs | 31 ++---------- .../SourceTransactionServiceTest.cs | 50 +++++++++++++++++++ .../Services/Sources/SourceServiceTest.cs | 28 +++++++++++ 3 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 src/StripeTests/Services/SourceTransactions/SourceTransactionServiceTest.cs diff --git a/src/StripeTests/NullableValueTypes.cs b/src/StripeTests/NullableValueTypes.cs index f7b3a93be1..e29f290493 100644 --- a/src/StripeTests/NullableValueTypes.cs +++ b/src/StripeTests/NullableValueTypes.cs @@ -11,7 +11,7 @@ namespace StripeTests using Stripe; using Xunit; -#if NETCOREAPP1_1 +#if NETCOREAPP public class NullableValueTypes { [Fact] @@ -21,9 +21,10 @@ public void EnsureAllValueTypesAreNullable() // Get all classes that implement INestedOptions var type = typeof(INestedOptions); - var optionsClasses = GetReferencingAssemblies("Stripe.net") - .SelectMany(assembly => assembly.ExportedTypes) - .Where(p => type.IsAssignableFrom(p)); + var assembly = type.GetTypeInfo().Assembly; + var optionsClasses = assembly.DefinedTypes + .Where(t => t.IsClass && t.ImplementedInterfaces.Contains(type)) + .Select(t => t.AsType()); foreach (Type optionsClass in optionsClasses) { @@ -71,28 +72,6 @@ public void EnsureAllValueTypesAreNullable() Assert.True(false, "Found at least one non-nullable value type"); } } - - private static IEnumerable GetReferencingAssemblies(string assemblyName) - { - var assemblies = new List(); - var dependencies = DependencyContext.Default.RuntimeLibraries; - foreach (var library in dependencies) - { - if (IsCandidateLibrary(library, assemblyName)) - { - var assembly = Assembly.Load(new AssemblyName(library.Name)); - assemblies.Add(assembly); - } - } - - return assemblies; - } - - private static bool IsCandidateLibrary(RuntimeLibrary library, string assemblyName) - { - return library.Name == assemblyName - || library.Dependencies.Any(d => d.Name.StartsWith(assemblyName)); - } } #endif } diff --git a/src/StripeTests/Services/SourceTransactions/SourceTransactionServiceTest.cs b/src/StripeTests/Services/SourceTransactions/SourceTransactionServiceTest.cs new file mode 100644 index 0000000000..47e3797ae7 --- /dev/null +++ b/src/StripeTests/Services/SourceTransactions/SourceTransactionServiceTest.cs @@ -0,0 +1,50 @@ +namespace StripeTests +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + using Stripe; + using Xunit; + + public class SourceTransactionServiceTest : BaseStripeTest + { + private const string SourceId = "src_123"; + + private SourceTransactionService service; + private SourceTransactionsListOptions listOptions; + + public SourceTransactionServiceTest() + { + this.service = new SourceTransactionService(); + + this.listOptions = new SourceTransactionsListOptions() + { + Limit = 1, + }; + } + + [Fact] + public void List() + { + var sources = this.service.List(SourceId, this.listOptions); + this.AssertRequest(HttpMethod.Get, "/v1/sources/src_123/source_transactions"); + Assert.NotNull(sources); + Assert.Equal("list", sources.Object); + Assert.Single(sources.Data); + Assert.Equal("source_transaction", sources.Data[0].Object); + } + + [Fact] + public async Task ListAsync() + { + var sources = await this.service.ListAsync(SourceId, this.listOptions); + this.AssertRequest(HttpMethod.Get, "/v1/sources/src_123/source_transactions"); + Assert.NotNull(sources); + Assert.Equal("list", sources.Object); + Assert.Single(sources.Data); + Assert.Equal("source_transaction", sources.Data[0].Object); + } + } +} diff --git a/src/StripeTests/Services/Sources/SourceServiceTest.cs b/src/StripeTests/Services/Sources/SourceServiceTest.cs index 338cccd683..4120636920 100644 --- a/src/StripeTests/Services/Sources/SourceServiceTest.cs +++ b/src/StripeTests/Services/Sources/SourceServiceTest.cs @@ -14,6 +14,7 @@ public class SourceServiceTest : BaseStripeTest private const string SourceId = "src_123"; private SourceService service; + private SourceAttachOptions attachOptions; private SourceCreateOptions createOptions; private SourceUpdateOptions updateOptions; private SourceListOptions listOptions; @@ -22,6 +23,11 @@ public SourceServiceTest() { this.service = new SourceService(); + this.attachOptions = new SourceAttachOptions + { + Source = SourceId, + }; + this.createOptions = new SourceCreateOptions { Type = SourceType.AchCreditTransfer, @@ -72,6 +78,28 @@ public SourceServiceTest() }; } + [Fact] + public void Attach() + { + var source = this.service.Attach(CustomerId, this.attachOptions); + this.AssertRequest(HttpMethod.Post, "/v1/customers/cus_123/sources"); + Assert.NotNull(source); + + // We can't test the object returned as stripe-mock returns an Account + // Assert.Equal("source", source.Object); + } + + [Fact] + public async Task AttachAsync() + { + var source = await this.service.AttachAsync(CustomerId, this.attachOptions); + this.AssertRequest(HttpMethod.Post, "/v1/customers/cus_123/sources"); + Assert.NotNull(source); + + // We can't test the object returned as stripe-mock returns an Account + // Assert.Equal("source", source.Object); + } + [Fact] public void Create() {