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

[WIP] .net core #16

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Ignore Visual Studio temporary files, build results, and
## ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userprefs
*.sln.docstates

# Build results
Expand Down Expand Up @@ -191,3 +192,8 @@ Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
*.nupkg

# Visual studio files
.vs


21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
sudo: false
sudo: required
language: csharp
solution: PromisePayDotNet.sln
install:
- nuget restore PromisePayDotNet.sln
- nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner
script:
- xbuild /p:Configuration=Release PromisePayDotNet.sln
- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe ./PromisePayDotNet.Tests/bin/Release/PromisePayDotNet.Tests.dll
dotnet: 1.0.3
mono:
- 4.8.0
dist: trusty
os:
- linux
script:
- dotnet restore
- dotnet build PromisePayDotNet
- dotnet build PromisePayDotNet.Tests
- cd PromisePayDotNet.Tests
- dotnet test
41 changes: 35 additions & 6 deletions PromisePayDotNet.Tests/AbstractTest.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
using Moq;
using RestSharp;
using RestSharp.Authenticators;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using PromisePayDotNet.Internals;
using PromisePayDotNet.Settings;
using System;
using System.Net;
using System.Threading.Tasks;

namespace PromisePayDotNet.Tests
{
public class AbstractTest
public abstract class AbstractTest
{
private static IServiceProvider CreateDi(IRestClient client = null)
{
var services = new ServiceCollection();
if (null != client)
{
services.AddTransient(ci => client);
}
services.AddPromisePay(new PromisePaySettings
{
ApiUrl = "https://test.api.promisepay.com",
Login = "[email protected]",
Password = "mJrUGo2Vxuo9zqMVAvkw"
});
if (null != client)
{
services.AddTransient(ci => client);
}
services.AddOptions();
services.AddLogging();
return services.BuildServiceProvider();
}


protected TRepo Get<TRepo>() => CreateDi().GetRequiredService<TRepo>();
protected TRepo Get<TRepo>(IRestClient client) => CreateDi(client).GetRequiredService<TRepo>();

protected Mock<IRestClient> GetMockClient(string content)
{
return GetMockClient(content, HttpStatusCode.OK);
}

protected Mock<IRestClient> GetMockClient(string content, HttpStatusCode StatusCode)
{
var response = new Mock<IRestResponse>(MockBehavior.Strict);
var response = new Mock<RestResponse>(MockBehavior.Strict);
response.SetupGet(x => x.Content).Returns(content);
response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com"));
response.SetupGet(x => x.StatusDescription).Returns("");
Expand All @@ -24,7 +53,7 @@ protected Mock<IRestClient> GetMockClient(string content, HttpStatusCode StatusC
var client = new Mock<IRestClient>(MockBehavior.Strict);
client.SetupSet(x => x.BaseUrl = It.IsAny<Uri>());
client.SetupSet(x => x.Authenticator = It.IsAny<IAuthenticator>());
client.Setup(x => x.Execute(It.IsAny<IRestRequest>())).Returns(response.Object);
client.Setup(x => x.ExecuteAsync(It.IsAny<RestRequest>())).ReturnsAsync(response.Object);
return client;
}

Expand Down
22 changes: 11 additions & 11 deletions PromisePayDotNet.Tests/AddressTest.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
using Newtonsoft.Json;
using NUnit.Framework;
using PromisePayDotNet.DTO;
using PromisePayDotNet.Implementations;
using PromisePayDotNet.Abstractions;
using PromisePayDotNet.Dto;
using System.IO;
using Xunit;

namespace PromisePayDotNet.Tests
{
public class AddressTest : AbstractTest
{
[Test]
[Fact]
public void AddressDeserialization()
{
var jsonStr = "{ \"addressline1\": null, \"addressline2\": null, \"postcode\": null, \"city\": null, \"state\": null, \"id\": \"07ed45e5-bb9d-459f-bb7b-a02ecb38f443\", \"country\": \"Australia\", \"links\": { \"self\": \"/addresses/07ed45e5-bb9d-459f-bb7b-a02ecb38f443\" }}";
var address = JsonConvert.DeserializeObject<Address>(jsonStr);
Assert.IsNotNull(address);
Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id);
Assert.NotNull(address);
Assert.Equal("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id);
}

[Test]
[Fact]
public void GetAddressSuccessfully()
{
var content = File.ReadAllText("../../Fixtures/address_get_by_id.json");
var content = Files.ReadAllText("./Fixtures/address_get_by_id.json");

var client = GetMockClient(content);

var repo = new AddressRepository(client.Object);
var repo = Get<IAddressRepository>(client.Object);

var address = repo.GetAddressById("07ed45e5-bb9d-459f-bb7b-a02ecb38f443");
client.VerifyAll();
Assert.IsNotNull(address);
Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id);
Assert.NotNull(address);
Assert.Equal("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id);

}
}
Expand Down
59 changes: 30 additions & 29 deletions PromisePayDotNet.Tests/BankAccountTest.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
using Newtonsoft.Json;
using NUnit.Framework;
using PromisePayDotNet.DTO;
using Xunit;
using PromisePayDotNet.Dto;
using PromisePayDotNet.Implementations;
using System;
using System.IO;
using PromisePayDotNet.Abstractions;

namespace PromisePayDotNet.Tests
{
public class BankAccountTest : AbstractTest
{
[Test]
[Fact]
public void BankAccountDeserialization()
{
const string jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-26T06:24:19.248Z\", \"updated_at\": \"2015-04-26T06:24:19.248Z\", \"id\": \"8d65c86c-14f4-4abf-a979-eba0a87b283a\", \"currency\": \"USD\", \"bank\": { \"bank_name\": \"Test Me\", \"country\": \"AUS\", \"account_name\": \"Test Account\", \"routing_number\": \"XXXXXXX3\", \"account_number\": \"XXXX344\", \"holder_type\": \"personal\", \"account_type\": \"savings\" }, \"links\": { \"self\": \"/bank_accounts/8d65c86c-14f4-4abf-a979-eba0a87b283a\", \"users\": \"/bank_accounts/8d65c86c-14f4-4abf-a979-eba0a87b283a/users\" } }";
var bankAccount = JsonConvert.DeserializeObject<BankAccount>(jsonStr);
Assert.AreEqual("8d65c86c-14f4-4abf-a979-eba0a87b283a", bankAccount.Id);
Assert.AreEqual("USD", bankAccount.Currency);
Assert.Equal("8d65c86c-14f4-4abf-a979-eba0a87b283a", bankAccount.Id);
Assert.Equal("USD", bankAccount.Currency);
}

[Test]
[Fact]
public void CreateBankAccountSuccessfully()
{
var content = File.ReadAllText("../../Fixtures/bank_account_create.json");
var content = Files.ReadAllText("./Fixtures/bank_account_create.json");

var client = GetMockClient(content);
var repo = new BankAccountRepository(client.Object);
var repo = Get<IBankAccountRepository>(client.Object);

const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before
var account = new BankAccount
Expand All @@ -44,61 +45,61 @@ public void CreateBankAccountSuccessfully()
};
var createdAccount = repo.CreateBankAccount(account);
client.VerifyAll();
Assert.IsNotNull(createdAccount);
Assert.IsNotNull(createdAccount.Id);
Assert.AreEqual("AUD", createdAccount.Currency); // It seems that currency is determined by country
Assert.IsNotNull(createdAccount.CreatedAt);
Assert.IsNotNull(createdAccount.UpdatedAt);
Assert.AreEqual("XXX789", createdAccount.Bank.AccountNumber); //Account number is masked
Assert.NotNull(createdAccount);
Assert.NotNull(createdAccount.Id);
Assert.Equal("AUD", createdAccount.Currency); // It seems that currency is determined by country
Assert.NotNull(createdAccount.CreatedAt);
Assert.NotNull(createdAccount.UpdatedAt);
Assert.Equal("XXX789", createdAccount.Bank.AccountNumber); //Account number is masked
}

[Test]
[Fact]
public void GetBankAccountSuccessfully()
{
var content = File.ReadAllText("../../Fixtures/bank_account_get_by_id.json");
var content = Files.ReadAllText("./Fixtures/bank_account_get_by_id.json");

var client = GetMockClient(content);
var repo = new BankAccountRepository(client.Object);
var repo = Get<IBankAccountRepository>(client.Object);
const string id = "ec9bf096-c505-4bef-87f6-18822b9dbf2c";
var gotAccount = repo.GetBankAccountById(id);
client.VerifyAll();
Assert.AreEqual(id, gotAccount.Id);
Assert.Equal(id, gotAccount.Id);
}

[Test]
[Fact]
public void GetBankAccountEmptyId()
{
var client = GetMockClient("");
var repo = new BankAccountRepository(client.Object);
var repo = Get<IBankAccountRepository>(client.Object);
Assert.Throws<ArgumentException>(() => repo.GetBankAccountById(string.Empty));
}

[Test]
[Fact]
public void GetUserForBankAccountSuccessfully()
{
var content = File.ReadAllText("../../Fixtures/bank_account_get_users.json");
var content = Files.ReadAllText("./Fixtures/bank_account_get_users.json");

var client = GetMockClient(content);
var repo = new BankAccountRepository(client.Object);
var repo = Get<IBankAccountRepository>(client.Object);
const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before
var gotUser = repo.GetUserForBankAccount("ec9bf096-c505-4bef-87f6-18822b9dbf2c");
client.VerifyAll();
Assert.IsNotNull(gotUser);
Assert.NotNull(gotUser);

Assert.AreEqual(userId, gotUser.Id);
Assert.Equal(userId, gotUser.Id);
}

[Test]
[Fact]
public void DeleteBankAccountSuccessfully()
{
var content = File.ReadAllText("../../Fixtures/bank_account_delete.json");
var content = Files.ReadAllText("./Fixtures/bank_account_delete.json");

var client = GetMockClient(content);
var repo = new BankAccountRepository(client.Object);
var repo = Get<IBankAccountRepository>(client.Object);

var result = repo.DeleteBankAccount("e923013e-61e9-4264-9622-83384e13d2b9");
client.VerifyAll();
Assert.IsTrue(result);
Assert.True(result);
}
}
}
Loading