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 1 commit
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 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
Expand Down Expand Up @@ -191,3 +191,6 @@ 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
20 changes: 10 additions & 10 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.Abstractions;
using PromisePayDotNet.DTO;
using PromisePayDotNet.Implementations;
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
57 changes: 29 additions & 28 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 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);
}
}
}
58 changes: 29 additions & 29 deletions PromisePayDotNet.Tests/CardAccountTest.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using Newtonsoft.Json;
using NUnit.Framework;
using PromisePayDotNet.Abstractions;
using PromisePayDotNet.DTO;
using PromisePayDotNet.Implementations;
using System;
using System.IO;
using Xunit;

namespace PromisePayDotNet.Tests
{
public class CardAccountTest : AbstractTest
{
[Test]
[Fact]
public void CardAccountDeserialization()
{
const string jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-26T06:28:55.559Z\", \"updated_at\": \"2015-04-26T06:28:55.559Z\", \"id\": \"ea464d25-fc9a-4887-861a-3d8ec2e12c19\", \"currency\": \"USD\", \"card\": { \"type\": \"visa\", \"full_name\": \"Joe Frio\", \"number\": \"XXXX-XXXX-XXXX-1111\", \"expiry_month\": \"5\", \"expiry_year\": \"2016\" }, \"links\": { \"self\": \"/card_accounts/ea464d25-fc9a-4887-861a-3d8ec2e12c19\", \"users\": \"/card_accounts/ea464d25-fc9a-4887-861a-3d8ec2e12c19/users\" } }";
var cardAccount = JsonConvert.DeserializeObject<CardAccount>(jsonStr);
Assert.AreEqual("ea464d25-fc9a-4887-861a-3d8ec2e12c19", cardAccount.Id);
Assert.AreEqual("USD", cardAccount.Currency);
Assert.AreEqual("Joe Frio", cardAccount.Card.FullName);
Assert.Equal("ea464d25-fc9a-4887-861a-3d8ec2e12c19", cardAccount.Id);
Assert.Equal("USD", cardAccount.Currency);
Assert.Equal("Joe Frio", cardAccount.Card.FullName);
}

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

var client = GetMockClient(content);
var repo = new CardAccountRepository(client.Object);
var repo = Get<ICardAccountRepository>(client.Object);

const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before
var account = new CardAccount
Expand All @@ -44,61 +44,61 @@ public void CreateCardAccountSuccessfully()
};
var createdAccount = repo.CreateCardAccount(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.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);

}

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

var client = GetMockClient(content);
var repo = new CardAccountRepository(client.Object);
var repo = Get<ICardAccountRepository>(client.Object);
var gotAccount = repo.GetCardAccountById("25d34744-8ef0-46a4-8b18-2a8322933cd1");
client.VerifyAll();
Assert.AreEqual("25d34744-8ef0-46a4-8b18-2a8322933cd1", gotAccount.Id);
Assert.Equal("25d34744-8ef0-46a4-8b18-2a8322933cd1", gotAccount.Id);
}

[Test]
[Fact]
public void GetCardAccountEmptyId()
{
var client = GetMockClient("");
var repo = new CardAccountRepository(client.Object);
var repo = Get<ICardAccountRepository>(client.Object);
Assert.Throws<ArgumentException>(() => repo.GetCardAccountById(string.Empty));
}

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

var client = GetMockClient(content);
var repo = new CardAccountRepository(client.Object);
var repo = Get<ICardAccountRepository>(client.Object);
var gotUser = repo.GetUserForCardAccount("25d34744-8ef0-46a4-8b18-2a8322933cd1");

client.VerifyAll();

Assert.IsNotNull(gotUser);
Assert.AreEqual("1", gotUser.Id);
Assert.NotNull(gotUser);
Assert.Equal("1", gotUser.Id);
}

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

var client = GetMockClient(content);
var repo = new CardAccountRepository(client.Object);
var repo = Get<ICardAccountRepository>(client.Object);
const string id = "25d34744-8ef0-46a4-8b18-2a8322933cd1";

var result = repo.DeleteCardAccount(id);
client.VerifyAll();
Assert.IsTrue(result);
Assert.True(result);
}

}
Expand Down
Loading