-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathSerializerTest.cs
95 lines (89 loc) · 6.36 KB
/
SerializerTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Text;
using Adyen.ApiSerialization;
using Adyen.Model.Checkout;
using Adyen.Model.TerminalApi;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PaymentResponse = Adyen.Model.TerminalApi.PaymentResponse;
namespace Adyen.Test
{
[TestClass]
public class SerializerTest
{
[TestMethod]
public void SerializeByteArrayTest()
{
var plainTextBytes = Encoding.ASCII.GetBytes("Bytes-To-Be-Encoded");
string base64String = System.Convert.ToBase64String(plainTextBytes);
var base64Bytes = Encoding.ASCII.GetBytes(base64String);
var threeDSecure = new ThreeDSecureData
{
Cavv = base64Bytes,
Xid = base64Bytes
};
var jsonRequest = Util.JsonOperation.SerializeRequest(threeDSecure);
var json = "{\"cavv\":\"Qnl0ZXMtVG8tQmUtRW5jb2RlZA==\",\"xid\":\"Qnl0ZXMtVG8tQmUtRW5jb2RlZA==\"}";
Assert.AreEqual(json, jsonRequest);
}
[TestMethod]
public void DeserializeByteArrayTest()
{
var json = "{\"cavv\":\"Qnl0ZXMtVG8tQmUtRW5jb2RlZA==\",\"xid\":\"Qnl0ZXMtVG8tQmUtRW5jb2RlZA==\"}";
var jsonRequest = Util.JsonOperation.Deserialize<ThreeDSecureData>(json);
var xid = Encoding.ASCII.GetString(jsonRequest.Xid);
var cavv = Encoding.ASCII.GetString(jsonRequest.Cavv);
var jsonElementBase64 = "Qnl0ZXMtVG8tQmUtRW5jb2RlZA==";
Assert.AreEqual(jsonElementBase64, xid);
Assert.AreEqual(jsonElementBase64, cavv);
}
[TestMethod]
public void EnumSerializerTest()
{
var saleToPoiMessageSerializer = new SaleToPoiMessageSerializer();
var saleToMessageOnLine = saleToPoiMessageSerializer.Deserialize(GetSaleToPoiMessage("OnlinePin"));
var saleToMessageOnline = saleToPoiMessageSerializer.Deserialize(GetSaleToPoiMessage("OnLinePin"));
var paymentResponseOnLine = (PaymentResponse)saleToMessageOnLine.MessagePayload;
var paymentResponseOnline = (PaymentResponse)saleToMessageOnline.MessagePayload;
Assert.AreEqual(paymentResponseOnline.PaymentResult.AuthenticationMethod[0], AuthenticationMethodType.OnLinePIN);
Assert.AreEqual(paymentResponseOnLine.PaymentResult.AuthenticationMethod[0], AuthenticationMethodType.OnLinePIN);
}
[TestMethod]
public void CheckoutLongSerializationTest()
{
var checkoutSessionRequest = new CreateCheckoutSessionRequest
{
MerchantAccount = "merchantAccount",
Reference = "TestReference",
ReturnUrl = "http://test-url.com",
Amount = new Model.Checkout.Amount("EUR", 10000L),
Channel = CreateCheckoutSessionRequest.ChannelEnum.Web,
CountryCode = "NL",
LineItems = new List<LineItem>()
{
new LineItem(quantity: 1, amountIncludingTax: 5000, description: "description1",
amountExcludingTax: 0),
new LineItem(quantity: 1, amountIncludingTax: 5000, description: "description2", taxAmount: 0)
}
}.ToJson();
// Assert that Long parameters set to zero are actually serialised (just like Int)
Assert.IsTrue(checkoutSessionRequest.Contains("amountExcludingTax\": 0,"));
Assert.IsTrue(checkoutSessionRequest.Contains("taxAmount\": 0"));
}
[TestMethod]
public void CheckoutSessionResponseCheckForIdTest()
{
var sessionResponse = @"{""mode"": ""embedded"",""amount"": {""currency"": ""EUR"",""value"": 10000},""expiresAt"": ""2023-04-06T17:11:15+02:00"",""id"": ""CS0068299CB8DA273A"",""merchantAccount"": ""TestMerchantAccount"",""reference"": ""TestReference"",""returnUrl"": ""http://test-url.com"",""sessionData"": ""Ab02b4c0!BQABAgBoacRJuRbNM/typUK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ddCyhzOLZYQ3JVgglty6hLgVeQzuN4b2MoalhfTl11HsElJT1kB0mznVX8CL7UMTUp/2uSgL8DN6kB4owEZ45nWRxIR/2sCidMJ1tnSI1uSqkeqXRf1vat5qPq+BzpYE0Urn2ZZEmgJyb2u0ZLn2x1tfJyPtv+hqBoT7iqJ224dSbuB4HMT49YtcheUtR0jnrImJXm+M1TeIjWB3XWOScrNV8sWEJMAiIU="",""shopperLocale"": ""en-US""}";
// Assert that readonly parameters like ID are actually deserialised and can be serialised again.
var deserializedResponse = JsonConvert.DeserializeObject<CreateCheckoutSessionResponse>(sessionResponse);
Assert.IsNotNull(deserializedResponse.Id);
Assert.IsTrue(deserializedResponse.ToJson().Contains("\"id\": \"CS0068299CB8DA273A\","));
}
private static string GetSaleToPoiMessage(string online)
{
return "{\"SaleToPOIResponse\": {\"PaymentResponse\": {\"POIData\": {},\"PaymentResult\": {\"AuthenticationMethod\": [\"" + online + "\"],\"PaymentAcquirerData\": {\"AcquirerPOIID\": \"MX925-260390740\",\"MerchantID\": \"PME_POS\"},\"PaymentType\": \"Normal\"},\"Response\": {\"Result\": \"Success\"}},\"MessageHeader\": {\"ProtocolVersion\": \"3.0\",\"SaleID\": \"Appie\",\"MessageClass\": \"Service\",\"MessageCategory\": \"Payment\",\"ServiceID\": \"20095135\",\"POIID\": \"MX925-260390740\",\"MessageType\": \"Response\"}}}";
}
}
}