Skip to content

Commit

Permalink
Remove Moq from Library (#877)
Browse files Browse the repository at this point in the history
* remove moq

* workflow

* fix workflow

* build with 2.1

* testesttes

* force netstandard2.0

* test

* build in netstandard2.0

* defeated..

* run workflow on push only

* test on dotnet 7

* only test in net6
  • Loading branch information
jillingk authored Aug 30, 2023
1 parent d55225b commit 38ac158
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 122 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: .NET Core

on: [ push, pull_request ]
on: [ push ]

jobs:
build:
Expand All @@ -16,7 +16,6 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
2.1.x
6.0.x
- name: Install tools
run: |
Expand All @@ -25,14 +24,8 @@ jobs:
- name: Build Debug
run: dotnet build -c Debug

- name: Run test suite netcoreapp2.1
run: dotnet test --no-build -c Debug -f netcoreapp2.1 Adyen.Test/Adyen.Test.csproj

- name: Run test suite net6.0
run: dotnet test --no-build -c Debug -f net6.0 Adyen.Test/Adyen.Test.csproj
- name: Run integration test suite netcoreapp2.1
run: dotnet test --no-build -c Debug -f netcoreapp2.1 Adyen.IntegrationTest/Adyen.IntegrationTest.csproj
if: ${{ github.event.pull_request.head.ref == 'main' }}

- name: Run integration test suite net6.0
run: dotnet test --no-build -c Debug -f net6.0 Adyen.IntegrationTest/Adyen.IntegrationTest.csproj
Expand Down
2 changes: 1 addition & 1 deletion Adyen.IntegrationTest/Adyen.IntegrationTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
7 changes: 4 additions & 3 deletions Adyen.Test/Adyen.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>

<IsPackable>false</IsPackable>

Expand Down Expand Up @@ -37,11 +38,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />

<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />

<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />

<PackageReference Include="NSubstitute" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 10 additions & 10 deletions Adyen.Test/BalancePlatformTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Adyen.Model.BalancePlatform;
using Adyen.Service.BalancePlatform;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NSubstitute;

namespace Adyen.Test
{
Expand Down Expand Up @@ -73,7 +73,10 @@ public void GetAccountHoldersIdBalanceAccountsAsyncTest()
var response = service.GetAllBalanceAccountsOfAccountHolderAsync("id", offset: 1, limit: 3).Result;
Assert.AreEqual("BA32272223222B59K6ZXHBFN6", response.BalanceAccounts[0].Id);
Assert.AreEqual(BalanceAccountBase.StatusEnum.Closed, response.BalanceAccounts[1].Status);
ClientInterfaceMock.Verify(mock => mock.RequestAsync("https://balanceplatform-api-test.adyen.com/bcl/v2/accountHolders/id/balanceAccounts?offset=1&limit=3", null, null, HttpMethod.Get, new CancellationToken()));
ClientInterfaceSubstitute.Received()
.RequestAsync(
"https://balanceplatform-api-test.adyen.com/bcl/v2/accountHolders/id/balanceAccounts?offset=1&limit=3",
null, null, HttpMethod.Get, default);
}

#endregion
Expand Down Expand Up @@ -152,11 +155,10 @@ public void GetBalanceAccountsBalanceAccountIdSweepsTest()
Assert.AreEqual(response.Sweeps[0].Id, "SWPC4227C224555B5FTD2NT2JV4WN5");
var schedule = response.Sweeps[0].Schedule.Type;
Assert.AreEqual(schedule, SweepSchedule.TypeEnum.Daily);
ClientInterfaceMock.Verify(mock => mock.RequestAsync(
ClientInterfaceSubstitute.Received().RequestAsync(
"https://balanceplatform-api-test.adyen.com/bcl/v2/balanceAccounts/balanceAccountId/sweeps",
null,
null, HttpMethod.Get, new CancellationToken())
);
null, HttpMethod.Get, new CancellationToken());
}

/// <summary>
Expand Down Expand Up @@ -416,12 +418,10 @@ public void ValidateBankAccountTest()
})
};
service.ValidateBankAccountIdentification(bankAccountIdentificationValidationRequest);
ClientInterfaceMock.Verify(mock => mock.RequestAsync(
ClientInterfaceSubstitute.Received().RequestAsync(
"https://balanceplatform-api-test.adyen.com/bcl/v2/validateBankAccountIdentification",
It.IsAny<String>(),
null, HttpMethod.Post, new CancellationToken())
);

Arg.Any<String>(),
null, HttpMethod.Post, new CancellationToken());
}
#endregion
}
Expand Down
91 changes: 48 additions & 43 deletions Adyen.Test/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Adyen.Constants;
using Adyen.HttpClient;
using Adyen.HttpClient.Interfaces;
using Adyen.Model;
using Adyen.Model.Nexo;
using Adyen.Model.Payment;
using Adyen.Service;
using Moq;
using NSubstitute;
using Amount = Adyen.Model.Checkout;
using Environment = System.Environment;
using PaymentResult = Adyen.Model.Payment.PaymentResult;
Expand All @@ -22,7 +19,7 @@ namespace Adyen.Test
{
public class BaseTest
{
private protected Mock<IClient> ClientInterfaceMock;
private protected IClient ClientInterfaceSubstitute;

#region Payment request
/// <summary>
Expand Down Expand Up @@ -225,12 +222,15 @@ protected Amount.PaymentVerificationRequest CreatePaymentVerificationRequest()
protected Client CreateMockForAdyenClientTest(Config config)
{
//Create a mock interface
ClientInterfaceMock = new Mock<IClient>();
ClientInterfaceMock.Setup(x => x.RequestAsync(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<RequestOptions>(), It.IsAny<HttpMethod>(), It.IsAny<CancellationToken>())).ReturnsAsync(It.IsAny<string>());
ClientInterfaceSubstitute = Substitute.For<IClient>();

ClientInterfaceSubstitute.RequestAsync(Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<RequestOptions>(), Arg.Any<HttpMethod>(),
Arg.Any<CancellationToken>()).Returns("");

var clientMock = new Client(config)
{
HttpClient = ClientInterfaceMock.Object,
HttpClient = ClientInterfaceSubstitute,
Config = config
};
return clientMock;
Expand All @@ -245,19 +245,20 @@ protected Client CreateMockTestClientRequest(string fileName)
{
var mockPath = GetMockFilePath(fileName);
var response = MockFileToString(mockPath);
//Create a mock interface
var clientInterfaceMock = new Mock<IClient>();
var confMock = MockPaymentData.CreateConfigMock();

clientInterfaceMock.Setup(x => x.Request(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<RequestOptions>(), null)).Returns(response);

ClientInterfaceSubstitute = Substitute.For<IClient>();

ClientInterfaceSubstitute.RequestAsync(Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<RequestOptions>(), Arg.Any<HttpMethod>(),
Arg.Any<CancellationToken>()).Returns(response);
var config = new Config
{
Environment = It.IsAny<Model.Environment>()
Environment = Model.Environment.Test
};
var clientMock = new Client(config)
{
HttpClient = clientInterfaceMock.Object,
Config = confMock
HttpClient = ClientInterfaceSubstitute,
Config = MockPaymentData.CreateConfigMock()
};
return clientMock;
}
Expand All @@ -272,18 +273,19 @@ protected Client CreateMockTestClientApiKeyBasedRequestAsync(string fileName)
var mockPath = GetMockFilePath(fileName);
var response = MockFileToString(mockPath);
//Create a mock interface
ClientInterfaceMock = new Mock<IClient>();
var confMock = MockPaymentData.CreateConfigApiKeyBasedMock();
ClientInterfaceMock.Setup(x => x.RequestAsync(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<RequestOptions>(), It.IsAny<HttpMethod>(), It.IsAny<CancellationToken>())).ReturnsAsync(response);
ClientInterfaceSubstitute = Substitute.For<IClient>();

ClientInterfaceSubstitute.RequestAsync(Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<RequestOptions>(), Arg.Any<HttpMethod>(),
Arg.Any<CancellationToken>()).Returns(response);
var config = new Config
{
Environment = It.IsAny<Model.Environment>()
Environment = Model.Environment.Test
};
var clientMock = new Client(config)
{
HttpClient = ClientInterfaceMock.Object,
Config = confMock
HttpClient = ClientInterfaceSubstitute,
Config = MockPaymentData.CreateConfigMock()
};
return clientMock;
}
Expand All @@ -298,18 +300,21 @@ protected Client CreateAsyncMockTestClientApiKeyBasedRequest(string fileName)
var mockPath = GetMockFilePath(fileName);
var response = MockFileToString(mockPath);
//Create a mock interface
var clientInterfaceMock = new Mock<IClient>();
var confMock = MockPaymentData.CreateConfigApiKeyBasedMock();
clientInterfaceMock.Setup(x => x.RequestAsync(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<RequestOptions>(), null, It.IsAny<CancellationToken>()))
.ReturnsAsync(response);

ClientInterfaceSubstitute = Substitute.For<IClient>();

ClientInterfaceSubstitute.RequestAsync(Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<RequestOptions>(), Arg.Any<HttpMethod>(),
Arg.Any<CancellationToken>()).Returns(response);

var config = new Config
{
Environment = It.IsAny<Model.Environment>()
Environment = Model.Environment.Test
};
var clientMock = new Client(config)
{
HttpClient = clientInterfaceMock.Object,
HttpClient = ClientInterfaceSubstitute,
Config = confMock
};
return clientMock;
Expand All @@ -325,17 +330,19 @@ protected Client CreateMockTestClientPosCloudApiRequest(string fileName)
var config = new Config { CloudApiEndPoint = ClientConfig.CloudApiEndPointTest };
var mockPath = GetMockFilePath(fileName);
var response = MockFileToString(mockPath);

//Create a mock interface
var clientInterfaceMock = new Mock<IClient>();
clientInterfaceMock.Setup(x => x.Request(It.IsAny<string>(),
It.IsAny<string>(), It.IsAny<RequestOptions>(), null)).Returns(response);
ClientInterfaceSubstitute = Substitute.For<IClient>();

ClientInterfaceSubstitute.Request(Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<RequestOptions>(), Arg.Any<HttpMethod>()).Returns(response);
var anyConfig = new Config
{
Environment = It.IsAny<Model.Environment>()
Environment = Model.Environment.Test
};
var clientMock = new Client(anyConfig)
{
HttpClient = clientInterfaceMock.Object,
HttpClient = ClientInterfaceSubstitute,
Config = config
};
return clientMock;
Expand All @@ -356,19 +363,17 @@ protected Client CreateMockTestClientPosLocalApiRequest(string fileName)
var mockPath = GetMockFilePath(fileName);
var response = MockFileToString(mockPath);
//Create a mock interface
var clientInterfaceMock = new Mock<IClient>();
clientInterfaceMock.Setup(x => x.Request(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<RequestOptions>(), null
))
.Returns(response);
ClientInterfaceSubstitute = Substitute.For<IClient>();

ClientInterfaceSubstitute.Request(Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<RequestOptions>(), Arg.Any<HttpMethod>()).Returns(response);
var anyConfig = new Config
{
Environment = It.IsAny<Model.Environment>()
Environment = Model.Environment.Test
};
var clientMock = new Client(anyConfig)
{
HttpClient = clientInterfaceMock.Object,
HttpClient = ClientInterfaceSubstitute,
Config = config
};
return clientMock;
Expand Down
34 changes: 12 additions & 22 deletions Adyen.Test/CheckoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using Adyen.HttpClient.Interfaces;
using Adyen.Model;
using Adyen.Model.Checkout;
using Adyen.Service;
using Adyen.Service.Checkout;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NSubstitute;
using static Adyen.Model.Checkout.PaymentResponse;
using ApplicationInfo = Adyen.Model.ApplicationInformation.ApplicationInfo;
using Environment = Adyen.Model.Environment;
Expand All @@ -33,11 +32,9 @@ public void CheckoutEndpointTestEnvironmentSuccessTest()
client.SetEnvironment(Environment.Test, "companyUrl");
var checkout = new PaymentsService(client);
checkout.PaymentsAsync(new PaymentRequest()).GetAwaiter();
ClientInterfaceMock.Verify(
mock =>
mock.RequestAsync(
"https://checkout-test.adyen.com/v70/payments",
It.IsAny<string>(), null, new HttpMethod("POST"), default));

ClientInterfaceSubstitute.Received().RequestAsync("https://checkout-test.adyen.com/v70/payments",
Arg.Any<string>(), null, new HttpMethod("POST"), default);
}

/// <summary>
Expand All @@ -50,11 +47,10 @@ public void CheckoutEndpointLiveEnvironmentSuccessTest()
client.SetEnvironment(Environment.Live, "companyUrl");
var checkout = new PaymentsService(client);
checkout.PaymentsAsync(new PaymentRequest()).GetAwaiter();
ClientInterfaceMock.Verify(
mock =>
mock.RequestAsync(
"https://companyUrl-checkout-live.adyenpayments.com/checkout/v70/payments",
It.IsAny<string>(), null, new HttpMethod("POST"), default));

ClientInterfaceSubstitute.Received().RequestAsync(
"https://companyUrl-checkout-live.adyenpayments.com/checkout/v70/payments",
Arg.Any<string>(), null, new HttpMethod("POST"), Arg.Any<CancellationToken>());
}

/// <summary>
Expand Down Expand Up @@ -102,11 +98,8 @@ public void CheckoutEndpointLiveWithBasicAuthTest()
});
var checkout = new PaymentsService(client);
checkout.PaymentsAsync(new PaymentRequest()).GetAwaiter();
ClientInterfaceMock.Verify(
mock =>
mock.RequestAsync(
"https://live-url-checkout-live.adyenpayments.com/checkout/v70/payments",
It.IsAny<string>(), null, new HttpMethod("POST"), default));
ClientInterfaceSubstitute.Received().RequestAsync("https://live-url-checkout-live.adyenpayments.com/checkout/v70/payments",
Arg.Any<string>(), null, new HttpMethod("POST"), default);
}

/// <summary>
Expand All @@ -124,11 +117,8 @@ public void CheckoutEndpointLiveWithAPIKeyTest()
});
var checkout = new PaymentsService(client);
checkout.PaymentsAsync(new PaymentRequest()).GetAwaiter();
ClientInterfaceMock.Verify(
mock =>
mock.RequestAsync(
"https://live-url-checkout-live.adyenpayments.com/checkout/v70/payments",
It.IsAny<string>(), null, new HttpMethod("POST"), default));
ClientInterfaceSubstitute.Received().RequestAsync("https://live-url-checkout-live.adyenpayments.com/checkout/v70/payments",
Arg.Any<string>(), null, new HttpMethod("POST"), Arg.Any<CancellationToken>());
}

/// <summary>
Expand Down
Loading

0 comments on commit 38ac158

Please sign in to comment.