-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathArbSubscriptionSampleTest.cs
More file actions
162 lines (142 loc) · 6.63 KB
/
ArbSubscriptionSampleTest.cs
File metadata and controls
162 lines (142 loc) · 6.63 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
namespace AuthorizeNet.Api.Controllers.SampleTest
{
using System;
using AuthorizeNet.Api.Contracts.V1;
using AuthorizeNet.Api.Controllers;
using AuthorizeNet.Api.Controllers.Bases;
using AuthorizeNet.Api.Controllers.Test;
using AuthorizeNet.Util;
using NUnit.Framework;
[TestFixture]
public class ArbSubscriptionSampleTest : ApiCoreTestBase {
[TestFixtureSetUp]
public new static void SetUpBeforeClass()
{
ApiCoreTestBase.SetUpBeforeClass();
}
[TestFixtureTearDown]
public new static void TearDownAfterClass()
{
ApiCoreTestBase.TearDownAfterClass();
}
[SetUp]
public new void SetUp() {
base.SetUp();
}
[TearDown]
public new void TearDown() {
base.TearDown();
}
[Test]
public void SampleCodeGetSubscriptionList()
{
LogHelper.info(Logger, "Sample GetSubscriptionList");
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;
//create a subscription
var createRequest = new ARBCreateSubscriptionRequest
{
refId = RefId,
subscription = ArbSubscriptionOne,
};
var createController = new ARBCreateSubscriptionController(createRequest);
createController.RequestId = Guid.NewGuid();
createController.Execute();
var createResponse = createController.GetApiResponse();
Assert.IsNotNull(createResponse.subscriptionId);
LogHelper.info(Logger, "Created Subscription: {0}", createResponse.subscriptionId);
var subscriptionId = createResponse.subscriptionId;
//get subscription details
var getRequest = new ARBGetSubscriptionStatusRequest
{
refId = RefId,
subscriptionId = subscriptionId
};
var getController = new ARBGetSubscriptionStatusController(getRequest);
var getResponse = getController.ExecuteWithApiResponse();
Assert.IsNotNull(getResponse.status);
Logger.info(String.Format("Subscription Status: {0}", getResponse.status));
//get subscription list that contains only the subscription created above.
var listRequest = new ARBGetSubscriptionListRequest
{
refId = RefId,
searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive,
sorting = new ARBGetSubscriptionListSorting
{
orderDescending = true,
orderBy = ARBGetSubscriptionListOrderFieldEnum.createTimeStampUTC,
},
paging = new Paging
{
limit = 500,
offset = 1,
},
};
var listController = new ARBGetSubscriptionListController(listRequest);
var listResponse = listController.ExecuteWithApiResponse();
LogHelper.info(Logger, "Subscription Count: {0}", listResponse.totalNumInResultSet);
Assert.IsTrue(0 < listResponse.totalNumInResultSet);
//validation of list
var subscriptionsArray = listResponse.subscriptionDetails;
foreach (var aSubscription in subscriptionsArray)
{
Assert.IsTrue(0 < aSubscription.id);
LogHelper.info(Logger, "Subscription Id: {0}, Status:{1}, PaymentMethod: {2}, Amount: {3}, Account:{4}",
aSubscription.id, aSubscription.status, aSubscription.paymentMethod, aSubscription.amount, aSubscription.accountNumber);
}
//cancel subscription
var cancelRequest = new ARBCancelSubscriptionRequest
{
merchantAuthentication = CustomMerchantAuthenticationType,
refId = RefId,
subscriptionId = subscriptionId
};
var cancelController = new ARBCancelSubscriptionController(cancelRequest);
var cancelResponse = cancelController.ExecuteWithApiResponse(TestEnvironment);
Assert.IsNotNull(cancelResponse.messages);
Logger.info(String.Format("Subscription Cancelled: {0}", subscriptionId));
}
[Test]
public void ARBGetSubscriptionSampleTest()
{
LogHelper.info(Logger, "Sample GetSubscriptionList");
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;
//create a subscription
var createRequest = new ARBCreateSubscriptionRequest
{
refId = RefId,
subscription = ArbSubscriptionOne,
};
var createController = new ARBCreateSubscriptionController(createRequest);
createController.Execute();
var createResponse = createController.GetApiResponse();
Assert.IsNotNull(createResponse.subscriptionId);
LogHelper.info(Logger, "Created Subscription: {0}", createResponse.subscriptionId);
var subscriptionId = createResponse.subscriptionId;
//get subscription details
var getRequest = new ARBGetSubscriptionRequest
{
refId = RefId,
subscriptionId = subscriptionId
};
var getController = new ARBGetSubscriptionController(getRequest);
var getResponse = getController.ExecuteWithApiResponse();
Assert.IsNotNull(getResponse.subscription);
Logger.info(String.Format("Subscription Name : {0}", getResponse.subscription.name));
Assert.AreEqual(ArbSubscriptionOne.name, getResponse.subscription.name);
Assert.AreEqual(ArbSubscriptionOne.amountSpecified, getResponse.subscription.amountSpecified);
//cancel subscription
var cancelRequest = new ARBCancelSubscriptionRequest
{
merchantAuthentication = CustomMerchantAuthenticationType,
refId = RefId,
subscriptionId = subscriptionId
};
var cancelController = new ARBCancelSubscriptionController(cancelRequest);
var cancelResponse = cancelController.ExecuteWithApiResponse(TestEnvironment);
Assert.IsNotNull(cancelResponse.messages);
Logger.info(String.Format("Subscription Cancelled: {0}", subscriptionId));
}
}
}