-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathCardPresentGatewayTest.cs
More file actions
186 lines (152 loc) · 7.95 KB
/
CardPresentGatewayTest.cs
File metadata and controls
186 lines (152 loc) · 7.95 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using AuthorizeNet;
using NUnit.Framework;
using System;
using System.Configuration;
namespace AuthorizeNETtest
{
/// <summary>
///This is a test class for CardPresentGatewayTest and is intended to contain all CardPresent Unit Tests
///</summary>
[TestFixture()]
public class CardPresentGatewayTest : BaseTest
{
/// <summary>
/// Auth Transaction - Approved
/// </summary>
[Test()]
public void SendTest_Auth_Approved()
{
//check ApiLoginid / TransactionKey
string sError = CheckApiLoginTransactionKey();
Assert.IsTrue(sError == "", sError);
string responseString = "1.0|1|1|This transaction has been approved.|N8IV1Z|Y||2207395117|4BA6F435F8046E347710457856F3BAD1||||||||||||XXXX1111|Visa";
LocalRequestObject.ResponseString = responseString;
IGatewayResponse expected = new CardPresentResponse(responseString.Split('|'));
CardPresentGateway target = new CardPresentGateway(ApiLogin, TransactionKey, true);
IGatewayRequest request = new CardPresentAuthorizationRequest((decimal)30.11, "4111111111111111", "02", "20");
string description = "CP Auth transaction approved testing";
IGatewayResponse actual = target.Send(request, description);
Assert.AreEqual(expected.Amount, actual.Amount);
Assert.AreEqual(expected.Approved, actual.Approved);
Assert.AreEqual(expected.CardNumber, actual.CardNumber);
Assert.AreEqual(expected.Message, actual.Message);
Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);
Assert.IsTrue(actual.AuthorizationCode.Trim().Length > 0);
Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
}
/// <summary>
/// Capture Transaction - Approved
/// </summary>
[Test()]
public void SendTest_Capture_Approved()
{
//check ApiLoginid / TransactionKey
string sError = CheckApiLoginTransactionKey();
Assert.IsTrue(sError == "", sError);
//setup
decimal amount = (decimal)30.12;
string authCode = SendAuthOnly(amount + 1, false);
Assert.IsTrue(authCode.Trim().Length > 0);
//start testing
string responseString = "1.0|1|1|This transaction has been approved.||P||2207702802|9FE994E47A8F0F44552C5CA59D09BE79||||||||||||XXXX1111|Visa";
LocalRequestObject.ResponseString = responseString;
IGatewayResponse expected = new CardPresentResponse(responseString.Split('|'));
CardPresentGateway target = new CardPresentGateway(ApiLogin, TransactionKey, true);
IGatewayRequest request = new CardPresentCaptureOnly(authCode, "4111111111111111", "0224", amount);
string description = "CP Capture transaction approved testing";
IGatewayResponse actual = target.Send(request, description);
Assert.AreEqual(expected.Amount, actual.Amount);
Assert.AreEqual(expected.Approved, actual.Approved);
Assert.AreEqual(expected.CardNumber, actual.CardNumber);
Assert.AreEqual(expected.Message, actual.Message);
Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);
Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
}
/// <summary>
/// PriorAuthCap Transaction - Approved
/// </summary>
[Test()]
public void SendTest_PriorAuthCap_Approved()
{
//check ApiLoginid / TransactionKey
string sError = CheckApiLoginTransactionKey();
Assert.IsTrue(sError == "", sError);
//setup
decimal amount = getValidAmount();
string transID = SendAuthOnly(amount + 1, true);
Assert.IsTrue(transID.Trim().Length > 0);
Assert.IsTrue(long.Parse(transID) > 0);
//start testing
string responseString = "1.0|1|1|This transaction has been approved.||P||2207397444|37887CB02372C5074386923E7E33BB3C||||||||||||XXXX1111|Visa";
LocalRequestObject.ResponseString = responseString;
IGatewayResponse expected = new CardPresentResponse(responseString.Split('|'));
CardPresentGateway target = new CardPresentGateway(ApiLogin, TransactionKey, true);
IGatewayRequest request = new CardPresentPriorAuthCapture(transID, amount);
string description = "CP PriorAuthCap transaction approved testing";
IGatewayResponse actual = target.Send(request, description);
Assert.AreEqual(expected.Amount, actual.Amount);
Assert.AreEqual(expected.Approved, actual.Approved);
Assert.AreEqual(expected.CardNumber, actual.CardNumber);
Assert.AreEqual(expected.Message, actual.Message);
Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);
Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
}
/// <summary>
/// PriorAuthCap Transaction LessAmount - Failed
/// </summary>
[Test()]
public void SendTest_PriorAuthCap_LessAmount_Failed()
{
//check ApiLoginid / TransactionKey
string sError = CheckApiLoginTransactionKey();
Assert.IsTrue(sError == "", sError);
//setup
decimal amount = getValidAmount();
string transID = SendAuthOnly(amount - 1, true);
Assert.IsTrue(transID.Trim().Length > 0);
Assert.IsTrue(long.Parse(transID) > 0);
//start testing
string responseString = "1.0|3|47|The amount requested for settlement cannot be greater than the original amount authorized.||P||0|723B86547E0A4F9D9A2293081DA46A70|||||||||||||Visa";
LocalRequestObject.ResponseString = responseString;
IGatewayResponse expected = new CardPresentResponse(responseString.Split('|'));
CardPresentGateway target = new CardPresentGateway(ApiLogin, TransactionKey, true);
IGatewayRequest request = new CardPresentPriorAuthCapture(transID, amount);
string description = "CP PriorAuthCap transaction approved testing";
IGatewayResponse actual = target.Send(request, description);
Assert.AreEqual(expected.Amount, actual.Amount);
Assert.AreEqual(expected.Approved, actual.Approved);
Assert.AreEqual(expected.CardNumber, actual.CardNumber);
Assert.AreEqual(expected.Message, actual.Message);
Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);
Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
Assert.IsTrue(long.Parse(actual.TransactionID) == 0);
}
private string SendAuthOnly(decimal amount, bool returnTransID)
{
string responseString = "1.0|1|1|This transaction has been approved.|N8IV1Z|Y||2207395117|4BA6F435F8046E347710457856F3BAD1||||||||||||XXXX1111|Visa";
LocalRequestObject.ResponseString = responseString;
CardPresentGateway target = new CardPresentGateway(ApiLogin, TransactionKey, true);
IGatewayRequest request = new CardPresentAuthorizationRequest(amount, "4111111111111111", "02", "24");
string description = "CP Auth transaction approved testing";
IGatewayResponse response = target.Send(request, description);
if (response.Approved)
{
if (returnTransID)
{
return response.TransactionID;
}
else
{
return response.AuthorizationCode;
}
}
else
{
return "";
}
}
}
}