mirror of
https://github.com/NecroticBamboo/QRBee.git
synced 2025-12-21 12:11:53 +00:00
Unit tests added
This commit is contained in:
parent
34c96c8a94
commit
41dcf6ff0a
40
QRBee.Tests/ClientCardDataTests.cs
Normal file
40
QRBee.Tests/ClientCardDataTests.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using QRBee.Core.Data;
|
||||||
|
|
||||||
|
namespace QRBee.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ClientCardDataTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void AsString()
|
||||||
|
{
|
||||||
|
var ccd = new ClientCardData
|
||||||
|
{
|
||||||
|
TransactionId = "1",
|
||||||
|
CardNumber = "2",
|
||||||
|
ExpirationDateYYYYMM = "202506",
|
||||||
|
ValidFromYYYYMM = "",
|
||||||
|
CardHolderName = "MR CARDHOLDER",
|
||||||
|
CVC = "123",
|
||||||
|
IssueNo = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
var s = ccd.AsString();
|
||||||
|
Assert.AreEqual( "1|2|202506||MR CARDHOLDER|123|1", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromString()
|
||||||
|
{
|
||||||
|
var s = "1|2|202506||MR CARDHOLDER|123|";
|
||||||
|
var ccd = ClientCardData.FromString(s);
|
||||||
|
|
||||||
|
Assert.AreEqual("1" , ccd.TransactionId);
|
||||||
|
Assert.AreEqual("2" , ccd.CardNumber);
|
||||||
|
Assert.AreEqual("MR CARDHOLDER", ccd.CardHolderName);
|
||||||
|
Assert.AreEqual("123" , ccd.CVC);
|
||||||
|
Assert.IsNull(ccd.IssueNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
QRBee.Tests/QRBee.Tests.csproj
Normal file
21
QRBee.Tests/QRBee.Tests.csproj
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\QRBee.Core\QRBee.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
55
QRBee.Tests/RequestsTests.cs
Normal file
55
QRBee.Tests/RequestsTests.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using QRBee.Core.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace QRBee.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class RequestsTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void MTC_AsQRCode()
|
||||||
|
{
|
||||||
|
var mtc = TestData.MakeMTCRequest();
|
||||||
|
var s = mtc.AsQRCodeString();
|
||||||
|
|
||||||
|
Assert.AreEqual("555|111-222-333|Merchant|123.45|2022-03-24:20.18.42.5550|merchant-sig", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MTC_AsDataForSig()
|
||||||
|
{
|
||||||
|
var mtc = TestData.MakeMTCRequest();
|
||||||
|
var s = mtc.AsDataForSignature();
|
||||||
|
|
||||||
|
Assert.AreEqual("555|111-222-333|Merchant|123.45|2022-03-24:20.18.42.5550", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MTC_FromString()
|
||||||
|
{
|
||||||
|
var mtc = MerchantToClientRequest.FromString("555|111-222-333|Merchant|123.45|2022-03-24:20.18.42.5550|merchant-sig");
|
||||||
|
|
||||||
|
Assert.AreEqual("merchant-sig", mtc.MerchantSignature);
|
||||||
|
Assert.AreEqual("555", mtc.MerchantId);
|
||||||
|
Assert.AreEqual("Merchant", mtc.Name);
|
||||||
|
Assert.AreEqual("111-222-333", mtc.MerchantTransactionId);
|
||||||
|
Assert.AreEqual(123.45M, mtc.Amount);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PaymentReq_AsString()
|
||||||
|
{
|
||||||
|
var pr = TestData.MakePaymentRequest();
|
||||||
|
|
||||||
|
var s = pr.AsString();
|
||||||
|
Assert.AreEqual("1234|2022-03-24:20.18.43.1234|555|111-222-333|Merchant|123.45|2022-03-24:20.18.42.5550|merchant-sig|abc", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
64
QRBee.Tests/ResponcesTests.cs
Normal file
64
QRBee.Tests/ResponcesTests.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using QRBee.Core.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace QRBee.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ResponcesTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void CTMR_AsQRCode()
|
||||||
|
{
|
||||||
|
ClientToMerchantResponse ctm = TestData.MakeCTMResponse();
|
||||||
|
|
||||||
|
var s = ctm.AsQRCodeString();
|
||||||
|
Assert.AreEqual("1234|2022-03-24:20.18.43.1234|abc|enc-data", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CTMR_AsDataForSig()
|
||||||
|
{
|
||||||
|
ClientToMerchantResponse ctm = TestData.MakeCTMResponse();
|
||||||
|
|
||||||
|
var s = ctm.AsDataForSignature();
|
||||||
|
Assert.AreEqual("1234|2022-03-24:20.18.43.1234|555|111-222-333|Merchant|123.45|2022-03-24:20.18.42.5550|merchant-sig", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CTMR_FromString()
|
||||||
|
{
|
||||||
|
var mtc = TestData.MakeMTCRequest();
|
||||||
|
var ctmr = ClientToMerchantResponse.FromString("1234|2022-03-24:20.18.43.1234|client-sig|client-card", mtc);
|
||||||
|
|
||||||
|
Assert.AreEqual("1234" , ctmr.ClientId);
|
||||||
|
Assert.AreEqual("555" , ctmr.MerchantRequest.MerchantId);
|
||||||
|
Assert.AreEqual("client-sig" , ctmr.ClientSignature);
|
||||||
|
Assert.AreEqual("merchant-sig", ctmr.MerchantRequest.MerchantSignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PayResponse_AsDataForSig()
|
||||||
|
{
|
||||||
|
var pr = new PaymentResponse
|
||||||
|
{
|
||||||
|
GatewayTransactionId = "gwt-id",
|
||||||
|
PaymentRequest = TestData.MakePaymentRequest(),
|
||||||
|
Success = false,
|
||||||
|
RejectReason = "rejected",
|
||||||
|
ServerSignature = "server-sig",
|
||||||
|
ServerTransactionId = "server_tr-id",
|
||||||
|
ServerTimeStampUTC = DateTime.Parse("2022-03-24 20:18:44.3452"),
|
||||||
|
};
|
||||||
|
|
||||||
|
var s= pr.AsDataForSignature();
|
||||||
|
Assert.AreEqual("server_tr-id|gwt-id|1234|2022-03-24:20.18.43.1234|555|111-222-333|Merchant|123.45|2022-03-24:20.18.42.5550|merchant-sig|abc|2022-03-24:20.18.44.3452|False|rejected", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
46
QRBee.Tests/TestData.cs
Normal file
46
QRBee.Tests/TestData.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using QRBee.Core.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace QRBee.Tests
|
||||||
|
{
|
||||||
|
internal class TestData
|
||||||
|
{
|
||||||
|
public static MerchantToClientRequest MakeMTCRequest()
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
MerchantId = "555",
|
||||||
|
MerchantTransactionId = "111-222-333",
|
||||||
|
Name = "Merchant",
|
||||||
|
Amount = 123.45M,
|
||||||
|
TimeStampUTC = DateTime.Parse("2022-03-24 20:18:42.555"),
|
||||||
|
MerchantSignature = "merchant-sig",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClientToMerchantResponse MakeCTMResponse()
|
||||||
|
{
|
||||||
|
return new ClientToMerchantResponse
|
||||||
|
{
|
||||||
|
MerchantRequest = MakeMTCRequest(),
|
||||||
|
ClientId = "1234",
|
||||||
|
TimeStampUTC = DateTime.Parse("2022-03-24 20:18:43.1234"),
|
||||||
|
ClientSignature = "abc",
|
||||||
|
EncryptedClientCardData = "enc-data",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PaymentRequest MakePaymentRequest()
|
||||||
|
{
|
||||||
|
return new PaymentRequest
|
||||||
|
{
|
||||||
|
ClientResponse = MakeCTMResponse(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
QRBee.sln
14
QRBee.sln
@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee.Api", "QRBeeApi\QRBee
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee.Core", "QRBee.Core\QRBee.Core.csproj", "{7C461562-66EF-4894-8AD8-F27F0B94053F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee.Core", "QRBee.Core\QRBee.Core.csproj", "{7C461562-66EF-4894-8AD8-F27F0B94053F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRBee.Tests", "QRBee.Tests\QRBee.Tests.csproj", "{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -81,6 +83,18 @@ Global
|
|||||||
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhone.Build.0 = Release|Any CPU
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
{7C461562-66EF-4894-8AD8-F27F0B94053F}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
|
{C48223E7-4AEF-4F6B-A8A0-DDE16B7111DA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user