| 1 | using System;
|
|---|
| 2 | using System.Collections.Specialized;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using adMoto.Payments.Core;
|
|---|
| 5 | using adMoto.Payments.Core.Data;
|
|---|
| 6 | using adMoto.Payments.Core.Interfaces;
|
|---|
| 7 | using adMoto.Payments.Test.Fakes;
|
|---|
| 8 | using adMoto.Payments.Web.Controllers;
|
|---|
| 9 | using NUnit.Framework;
|
|---|
| 10 | using MvcContrib.TestHelper;
|
|---|
| 11 | using System.Web.Mvc;
|
|---|
| 12 |
|
|---|
| 13 | namespace adMoto.Payments.Test.Controllers
|
|---|
| 14 | {
|
|---|
| 15 | [TestFixture]
|
|---|
| 16 | // ReSharper disable InconsistentNaming
|
|---|
| 17 | public class eCardControllerTests
|
|---|
| 18 | // ReSharper restore InconsistentNaming
|
|---|
| 19 | {
|
|---|
| 20 | private IRepository<PotwierdzeniaEcard> _repConfirm;
|
|---|
| 21 |
|
|---|
| 22 | private eCardController CreateController()
|
|---|
| 23 | {
|
|---|
| 24 | _repConfirm = new Repository<PotwierdzeniaEcard>(new FakeDataContext());
|
|---|
| 25 |
|
|---|
| 26 | var builder = new TestControllerBuilder();
|
|---|
| 27 | return builder.CreateController<eCardController>(_repConfirm);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | [Test]
|
|---|
| 31 | [Category("Unit")]
|
|---|
| 32 | public void Status_Returns_True_When_Passing_Correct_Request_Data()
|
|---|
| 33 | {
|
|---|
| 34 | var controller = CreateController();
|
|---|
| 35 | const string dateFormat = "yyyy-MM-dd HH:mm:ss.fff";
|
|---|
| 36 | var dateTime = DateTime.Now.ToString(dateFormat);
|
|---|
| 37 | var formValues = new NameValueCollection {
|
|---|
| 38 | {"MERCHANTNUMBER", "1"},
|
|---|
| 39 | {"ORDERNUMBER", "2"},
|
|---|
| 40 | {"COMMTYPE", "3"},
|
|---|
| 41 | {"CURRENTSTATE", "4"},
|
|---|
| 42 | {"PREVIOUSSTATE", "5"},
|
|---|
| 43 | {"PAYMENTTYPE", "1"},
|
|---|
| 44 | {"EVENTTYPE", "0"},
|
|---|
| 45 | {"PAYMENTNUMBER", "1"},
|
|---|
| 46 | {"APPROVALCODE", "6"},
|
|---|
| 47 | {"VALIDATIONCODE", "7"},
|
|---|
| 48 | {"BIN", "8"},
|
|---|
| 49 | {"AUTHTIME", dateTime},
|
|---|
| 50 | {"TYPE", "9"},
|
|---|
| 51 | {"WITHCVC", "10"}};
|
|---|
| 52 | controller.Request.Form.Add(formValues);
|
|---|
| 53 |
|
|---|
| 54 | var result = controller.Status() as ContentResult;
|
|---|
| 55 |
|
|---|
| 56 | Assert.That(result.Content.Contains("OK"));
|
|---|
| 57 |
|
|---|
| 58 | var paymentConfirmation = _repConfirm.FindAll().First();
|
|---|
| 59 | Assert.That(paymentConfirmation.MERCHANTNUMBER, Is.EqualTo("1"));
|
|---|
| 60 | Assert.That(paymentConfirmation.ORDERNUMBER, Is.EqualTo(2));
|
|---|
| 61 | Assert.That(paymentConfirmation.COMMTYPE, Is.EqualTo("3"));
|
|---|
| 62 | Assert.That(paymentConfirmation.CURRENTSTATE, Is.EqualTo("4"));
|
|---|
| 63 | Assert.That(paymentConfirmation.PREVIOUSSTATE, Is.EqualTo("5"));
|
|---|
| 64 | Assert.That(paymentConfirmation.APPROVALCODE, Is.EqualTo("6"));
|
|---|
| 65 | Assert.That(paymentConfirmation.VALIDATIONCODE, Is.EqualTo("7"));
|
|---|
| 66 | Assert.That(paymentConfirmation.BIN, Is.EqualTo("8"));
|
|---|
| 67 | Assert.That(paymentConfirmation.TYPE, Is.EqualTo("9"));
|
|---|
| 68 | Assert.That(paymentConfirmation.WITHCVC, Is.EqualTo("10"));
|
|---|
| 69 | Assert.That(paymentConfirmation.PAYMENTTYPE, Is.True);
|
|---|
| 70 | Assert.That(paymentConfirmation.EVENTTYPE, Is.False);
|
|---|
| 71 | Assert.That(paymentConfirmation.PAYMENTNUMBER, Is.True);
|
|---|
| 72 | Assert.That(paymentConfirmation.AUTHTIME.Value.ToString(dateFormat), Is.EqualTo(dateTime));
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | [Test]
|
|---|
| 76 | [Category("Unit")]
|
|---|
| 77 | public void Status_Returns_False_And_Throws_FormatException_When_Passing_OrderNumber_In_Wrong_Format()
|
|---|
| 78 | {
|
|---|
| 79 | var controller = CreateController();
|
|---|
| 80 | var valueCollection = new NameValueCollection {{"ORDERNUMBER", "fdsf"}};
|
|---|
| 81 | controller.Request.Form.Add(valueCollection);
|
|---|
| 82 |
|
|---|
| 83 | var result = controller.Status() as ContentResult;
|
|---|
| 84 |
|
|---|
| 85 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 86 | Assert.That(result.Content.Contains("FALSE"));
|
|---|
| 87 | Assert.That(result.Content.Contains("FormatException"));
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | [Test]
|
|---|
| 91 | [Category("Unit")]
|
|---|
| 92 | public void Status_Returns_False_And_Throws_FormatException_When_Passing_PaymentType_In_Wrong_Format()
|
|---|
| 93 | {
|
|---|
| 94 | var controller = CreateController();
|
|---|
| 95 | var valueCollection = new NameValueCollection { { "PAYMENTTYPE", "32hvhsvhv" } };
|
|---|
| 96 | controller.Request.Form.Add(valueCollection);
|
|---|
| 97 |
|
|---|
| 98 | var result = controller.Status() as ContentResult;
|
|---|
| 99 |
|
|---|
| 100 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 101 | Assert.That(result.Content.Contains("FALSE"));
|
|---|
| 102 | Assert.That(result.Content.Contains("FormatException"));
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | [Test]
|
|---|
| 106 | [Category("Unit")]
|
|---|
| 107 | public void Status_Returns_False_And_Throws_FormatException_When_Passing_EventType_In_Wrong_Format()
|
|---|
| 108 | {
|
|---|
| 109 | var controller = CreateController();
|
|---|
| 110 | var valueCollection = new NameValueCollection { { "EVENTTYPE", "32hvhsvhv" } };
|
|---|
| 111 | controller.Request.Form.Add(valueCollection);
|
|---|
| 112 |
|
|---|
| 113 | var result = controller.Status() as ContentResult;
|
|---|
| 114 |
|
|---|
| 115 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 116 | Assert.That(result.Content.Contains("FALSE"));
|
|---|
| 117 | Assert.That(result.Content.Contains("FormatException"));
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | [Test]
|
|---|
| 121 | [Category("Unit")]
|
|---|
| 122 | public void Status_Returns_False_And_Throws_OverflowException_When_Passing_OrderNumer_Greater_Than_Integer()
|
|---|
| 123 | {
|
|---|
| 124 | var controller = CreateController();
|
|---|
| 125 | var valueCollection = new NameValueCollection { { "ORDERNUMBER", "12311111111111111" } };
|
|---|
| 126 | controller.Request.Form.Add(valueCollection);
|
|---|
| 127 |
|
|---|
| 128 | var result = controller.Status() as ContentResult;
|
|---|
| 129 |
|
|---|
| 130 | Assert.That(_repConfirm.Count(), Is.EqualTo(0));
|
|---|
| 131 | Assert.That(result.Content.Contains("FALSE"), "Response should contain FALSE");
|
|---|
| 132 | Assert.That(result.Content.Contains("OverflowException"), "Response should contain OverflowException");
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | [Test]
|
|---|
| 136 | [Category("Unit")]
|
|---|
| 137 | public void Status_Returns_False_And_Throws_SqlException_When_Passing_ValidationCode_Longer_Than_Three_Characters()
|
|---|
| 138 | {
|
|---|
| 139 | var controller = CreateController();
|
|---|
| 140 | var valueCollection = new NameValueCollection { { "VALIDATIONCODE", "1234" } };
|
|---|
| 141 | controller.Request.Form.Add(valueCollection);
|
|---|
| 142 |
|
|---|
| 143 | var result = controller.Status() as ContentResult;
|
|---|
| 144 |
|
|---|
| 145 | Assert.That(_repConfirm.Count(), Is.EqualTo(0), "Should not have any items");
|
|---|
| 146 | Assert.That(result.Content.Contains("FALSE"), "Response should contain FALSE");
|
|---|
| 147 | Assert.That(result.Content.Contains("ArgumentException"), "Response should contain SqlException");
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | } |
|---|