| [982] | 1 | using System;
|
|---|
| 2 | using System.Collections.Specialized;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using adMoto.Payments.Core;
|
|---|
| [970] | 5 | using adMoto.Payments.Core.Data;
|
|---|
| 6 | using adMoto.Payments.Core.Interfaces;
|
|---|
| [982] | 7 | using adMoto.Payments.Test.Fakes;
|
|---|
| 8 | using adMoto.Payments.Web.Controllers;
|
|---|
| [970] | 9 | using NUnit.Framework;
|
|---|
| [911] | 10 | using MvcContrib.TestHelper;
|
|---|
| 11 | using System.Web.Mvc;
|
|---|
| 12 |
|
|---|
| [982] | 13 | namespace adMoto.Payments.Test.Controllers
|
|---|
| [911] | 14 | {
|
|---|
| [969] | 15 | [TestFixture]
|
|---|
| [982] | 16 | // ReSharper disable InconsistentNaming
|
|---|
| 17 | public class eCardControllerTests
|
|---|
| 18 | // ReSharper restore InconsistentNaming
|
|---|
| [911] | 19 | {
|
|---|
| [984] | 20 | private readonly TestDataHelper _testDataHelper = new TestDataHelper();
|
|---|
| [982] | 21 | private IRepository<PotwierdzeniaEcard> _repConfirm;
|
|---|
| [985] | 22 | // private IRepository<PlatnosciEcard> _repPayment;
|
|---|
| [984] | 23 | private const string CODE_OK = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| 24 | private const string CODE_BAD = "payment_declined"; //transakcja odrzucona
|
|---|
| 25 |
|
|---|
| [982] | 26 | private eCardController CreateController()
|
|---|
| 27 | {
|
|---|
| 28 | _repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| [911] | 29 |
|
|---|
| [982] | 30 | var builder = new TestControllerBuilder();
|
|---|
| [984] | 31 | return builder.CreateController<eCardController>(_repConfirm);
|
|---|
| [982] | 32 | }
|
|---|
| [911] | 33 |
|
|---|
| [982] | 34 | [Test]
|
|---|
| 35 | [Category("Unit")]
|
|---|
| 36 | public void Status_Returns_True_When_Passing_Correct_Request_Data()
|
|---|
| 37 | {
|
|---|
| 38 | var controller = CreateController();
|
|---|
| 39 | const string dateFormat = "yyyy-MM-dd HH:mm:ss.fff";
|
|---|
| 40 | var dateTime = DateTime.Now.ToString(dateFormat);
|
|---|
| 41 | var formValues = new NameValueCollection {
|
|---|
| 42 | {"MERCHANTNUMBER", "1"},
|
|---|
| 43 | {"ORDERNUMBER", "2"},
|
|---|
| 44 | {"COMMTYPE", "3"},
|
|---|
| 45 | {"CURRENTSTATE", "4"},
|
|---|
| 46 | {"PREVIOUSSTATE", "5"},
|
|---|
| 47 | {"PAYMENTTYPE", "1"},
|
|---|
| 48 | {"EVENTTYPE", "0"},
|
|---|
| 49 | {"PAYMENTNUMBER", "1"},
|
|---|
| 50 | {"APPROVALCODE", "6"},
|
|---|
| 51 | {"VALIDATIONCODE", "7"},
|
|---|
| 52 | {"BIN", "8"},
|
|---|
| 53 | {"AUTHTIME", dateTime},
|
|---|
| 54 | {"TYPE", "9"},
|
|---|
| 55 | {"WITHCVC", "10"}};
|
|---|
| 56 | controller.Request.Form.Add(formValues);
|
|---|
| 57 |
|
|---|
| 58 | var result = controller.Status() as ContentResult;
|
|---|
| 59 |
|
|---|
| 60 | Assert.That(result.Content.Contains("OK"));
|
|---|
| [911] | 61 |
|
|---|
| [982] | 62 | var paymentConfirmation = _repConfirm.FindAll().First();
|
|---|
| 63 | Assert.That(paymentConfirmation.MERCHANTNUMBER, Is.EqualTo("1"));
|
|---|
| 64 | Assert.That(paymentConfirmation.ORDERNUMBER, Is.EqualTo(2));
|
|---|
| 65 | Assert.That(paymentConfirmation.COMMTYPE, Is.EqualTo("3"));
|
|---|
| 66 | Assert.That(paymentConfirmation.CURRENTSTATE, Is.EqualTo("4"));
|
|---|
| 67 | Assert.That(paymentConfirmation.PREVIOUSSTATE, Is.EqualTo("5"));
|
|---|
| 68 | Assert.That(paymentConfirmation.APPROVALCODE, Is.EqualTo("6"));
|
|---|
| 69 | Assert.That(paymentConfirmation.VALIDATIONCODE, Is.EqualTo("7"));
|
|---|
| 70 | Assert.That(paymentConfirmation.BIN, Is.EqualTo("8"));
|
|---|
| 71 | Assert.That(paymentConfirmation.TYPE, Is.EqualTo("9"));
|
|---|
| 72 | Assert.That(paymentConfirmation.WITHCVC, Is.EqualTo("10"));
|
|---|
| 73 | Assert.That(paymentConfirmation.PAYMENTTYPE, Is.True);
|
|---|
| 74 | Assert.That(paymentConfirmation.EVENTTYPE, Is.False);
|
|---|
| 75 | Assert.That(paymentConfirmation.PAYMENTNUMBER, Is.True);
|
|---|
| 76 | Assert.That(paymentConfirmation.AUTHTIME.Value.ToString(dateFormat), Is.EqualTo(dateTime));
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | [Test]
|
|---|
| 80 | [Category("Unit")]
|
|---|
| 81 | public void Status_Returns_False_And_Throws_FormatException_When_Passing_OrderNumber_In_Wrong_Format()
|
|---|
| 82 | {
|
|---|
| 83 | var controller = CreateController();
|
|---|
| 84 | var valueCollection = new NameValueCollection {{"ORDERNUMBER", "fdsf"}};
|
|---|
| 85 | controller.Request.Form.Add(valueCollection);
|
|---|
| 86 |
|
|---|
| 87 | var result = controller.Status() as ContentResult;
|
|---|
| 88 |
|
|---|
| 89 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 90 | Assert.That(result.Content.Contains("FALSE"));
|
|---|
| 91 | Assert.That(result.Content.Contains("FormatException"));
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | [Test]
|
|---|
| 95 | [Category("Unit")]
|
|---|
| 96 | public void Status_Returns_False_And_Throws_FormatException_When_Passing_PaymentType_In_Wrong_Format()
|
|---|
| 97 | {
|
|---|
| 98 | var controller = CreateController();
|
|---|
| 99 | var valueCollection = new NameValueCollection { { "PAYMENTTYPE", "32hvhsvhv" } };
|
|---|
| 100 | controller.Request.Form.Add(valueCollection);
|
|---|
| 101 |
|
|---|
| 102 | var result = controller.Status() as ContentResult;
|
|---|
| 103 |
|
|---|
| 104 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 105 | Assert.That(result.Content.Contains("FALSE"));
|
|---|
| 106 | Assert.That(result.Content.Contains("FormatException"));
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | [Test]
|
|---|
| 110 | [Category("Unit")]
|
|---|
| 111 | public void Status_Returns_False_And_Throws_FormatException_When_Passing_EventType_In_Wrong_Format()
|
|---|
| 112 | {
|
|---|
| 113 | var controller = CreateController();
|
|---|
| 114 | var valueCollection = new NameValueCollection { { "EVENTTYPE", "32hvhsvhv" } };
|
|---|
| 115 | controller.Request.Form.Add(valueCollection);
|
|---|
| 116 |
|
|---|
| 117 | var result = controller.Status() as ContentResult;
|
|---|
| 118 |
|
|---|
| 119 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 120 | Assert.That(result.Content.Contains("FALSE"));
|
|---|
| 121 | Assert.That(result.Content.Contains("FormatException"));
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | [Test]
|
|---|
| 125 | [Category("Unit")]
|
|---|
| 126 | public void Status_Returns_False_And_Throws_OverflowException_When_Passing_OrderNumer_Greater_Than_Integer()
|
|---|
| 127 | {
|
|---|
| 128 | var controller = CreateController();
|
|---|
| 129 | var valueCollection = new NameValueCollection { { "ORDERNUMBER", "12311111111111111" } };
|
|---|
| 130 | controller.Request.Form.Add(valueCollection);
|
|---|
| 131 |
|
|---|
| 132 | var result = controller.Status() as ContentResult;
|
|---|
| 133 |
|
|---|
| 134 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 135 | Assert.That(result.Content.Contains("FALSE"), "Response should contain FALSE");
|
|---|
| 136 | Assert.That(result.Content.Contains("OverflowException"), "Response should contain OverflowException");
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | [Test]
|
|---|
| 140 | [Category("Unit")]
|
|---|
| 141 | public void Status_Returns_False_And_Throws_SqlException_When_Passing_ValidationCode_Longer_Than_Three_Characters()
|
|---|
| 142 | {
|
|---|
| 143 | var controller = CreateController();
|
|---|
| 144 | var valueCollection = new NameValueCollection { { "VALIDATIONCODE", "1234" } };
|
|---|
| 145 | controller.Request.Form.Add(valueCollection);
|
|---|
| 146 |
|
|---|
| 147 | var result = controller.Status() as ContentResult;
|
|---|
| 148 |
|
|---|
| 149 | Assert.That(_repConfirm.Count(), Is.EqualTo(0), "Should not have any items");
|
|---|
| 150 | Assert.That(result.Content.Contains("FALSE"), "Response should contain FALSE");
|
|---|
| 151 | Assert.That(result.Content.Contains("ArgumentException"), "Response should contain SqlException");
|
|---|
| 152 | }
|
|---|
| [985] | 153 |
|
|---|
| [984] | 154 | /*[Test]
|
|---|
| 155 | [Category("Unit")]
|
|---|
| 156 | public void Status_Action_Saves_Correct_Transaction()
|
|---|
| 157 | {
|
|---|
| 158 | //Arrange
|
|---|
| 159 | _repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 160 | var payment = _testDataHelper.CreateNewPayment(2, false, DateTime.Now, 12345);
|
|---|
| 161 | _repPayment.Insert(payment);
|
|---|
| 162 | _repPayment.SubmitChanges();
|
|---|
| 163 |
|
|---|
| 164 | var controller = CreateController();
|
|---|
| 165 | var valueCollection = new NameValueCollection {
|
|---|
| 166 | {"MERCHANTNUMBER", "1"},
|
|---|
| 167 | {"ORDERNUMBER", "2"},
|
|---|
| 168 | {"AUTHTIME", DateTime.Now.ToString()},
|
|---|
| 169 | {"CURRENTSTATE", CODE_OK}};
|
|---|
| 170 | controller.Request.Form.Add(valueCollection);
|
|---|
| 171 |
|
|---|
| 172 | //Act
|
|---|
| 173 | controller.Status();
|
|---|
| 174 | var confirm = _repConfirm.Find(o => o.ORDERNUMBER == 2).SingleOrDefault();
|
|---|
| 175 |
|
|---|
| 176 | //Assert
|
|---|
| 177 | Assert.That(confirm.MERCHANTNUMBER, Is.EqualTo("1"));
|
|---|
| 178 |
|
|---|
| 179 | //Act
|
|---|
| 180 | var paymentAfterUpdate = _repPayment.FindOne(2);
|
|---|
| 181 | System.Diagnostics.Debug.WriteLine("Status musi byc 'true'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 182 |
|
|---|
| 183 | //Assert
|
|---|
| 184 | Assert.That(paymentAfterUpdate.Status, Is.EqualTo(true));
|
|---|
| 185 | }*/
|
|---|
| 186 | /*[Test]
|
|---|
| 187 | [Category("Unit")]
|
|---|
| 188 | public void Status_Action_Payment_Is_Not_Update_When_Currentstate_Is_CODE_BAD()
|
|---|
| 189 | {
|
|---|
| 190 | //Arrange
|
|---|
| 191 | _repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
|
|---|
| 192 | var payment = _testDataHelper.CreateNewPayment(2, false, DateTime.Now, 12345);
|
|---|
| 193 | _repPayment.Insert(payment);
|
|---|
| 194 | _repPayment.SubmitChanges();
|
|---|
| 195 |
|
|---|
| 196 | var controller = CreateController();
|
|---|
| 197 | var valueCollection = new NameValueCollection {
|
|---|
| 198 | {"MERCHANTNUMBER", "1"},
|
|---|
| 199 | {"ORDERNUMBER", "2"},
|
|---|
| 200 | {"AUTHTIME", DateTime.Now.ToString()},
|
|---|
| 201 | {"CURRENTSTATE", CODE_BAD}};
|
|---|
| 202 | controller.Request.Form.Add(valueCollection);
|
|---|
| 203 |
|
|---|
| 204 | //Act
|
|---|
| 205 | controller.Status();
|
|---|
| 206 | var confirm = _repConfirm.Find(o => o.ORDERNUMBER == 2).SingleOrDefault();
|
|---|
| 207 |
|
|---|
| 208 | //Assert
|
|---|
| 209 | Assert.That(confirm.MERCHANTNUMBER, Is.EqualTo("1"));
|
|---|
| 210 |
|
|---|
| 211 | //Act
|
|---|
| 212 | var paymentAfterUpdate = _repPayment.FindOne(2);
|
|---|
| 213 | System.Diagnostics.Debug.WriteLine("Status musi byc 'false'. Jest " + paymentAfterUpdate.Status);
|
|---|
| 214 |
|
|---|
| 215 | //Assert
|
|---|
| 216 | Assert.That(paymentAfterUpdate.Status, Is.EqualTo(true));
|
|---|
| 217 | }*/
|
|---|
| 218 |
|
|---|
| 219 | }
|
|---|
| [982] | 220 | } |
|---|