Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing tests #1328

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions src/StripeTests/NullableValueTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace StripeTests
using Stripe;
using Xunit;

#if NETCOREAPP1_1
#if NETCOREAPP
public class NullableValueTypes
{
[Fact]
Expand All @@ -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)
{
Expand Down Expand Up @@ -71,28 +72,6 @@ public void EnsureAllValueTypesAreNullable()
Assert.True(false, "Found at least one non-nullable value type");
}
}

private static IEnumerable<Assembly> GetReferencingAssemblies(string assemblyName)
{
var assemblies = new List<Assembly>();
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
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
28 changes: 28 additions & 0 deletions src/StripeTests/Services/Sources/SourceServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,11 @@ public SourceServiceTest()
{
this.service = new SourceService();

this.attachOptions = new SourceAttachOptions
{
Source = SourceId,
};

this.createOptions = new SourceCreateOptions
{
Type = SourceType.AchCreditTransfer,
Expand Down Expand Up @@ -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()
{
Expand Down