コード例 #1
0
        public void ItShouldThrowCommunicationExceptionForCommunicationError()
        {
            // Arrange
            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>()))
            .Throws(new CommunicationException("API exception occured", null));
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            var ex = (CommunicationException)Assert.Throws(typeof(CommunicationException),
                                                           () => payments.Continue(MerchantData, _continuation));

            // Assert
            Assert.That(ex.Message, Is.EqualTo("API exception occured"));
        }
コード例 #2
0
        public void ItShouldThrowArgumentExceptionForInvalidTransactionId()
        {
            // Arrange
            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>()))
            .Throws(new ArgumentNullException());
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            var ex = (ArgumentNullException)Assert.Throws(typeof(ArgumentNullException),
                                                          () => payments.Continue(null, _continuation));

            // Assert
            Assert.That(ex.ParamName, Is.EqualTo("MerchantData"));
        }
コード例 #3
0
        public void ItShouldThrowServerExceptionForServerError()
        {
            // Arrange
            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>()))
            .Throws(new InternalServerException(HttpStatusCode.InternalServerError, ""));
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            var ex = (InternalServerException)Assert.Throws(typeof(InternalServerException),
                                                            () => payments.Continue(MerchantData, _continuation));

            // Assert
            Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.InternalServerError));
        }
コード例 #4
0
        public void ItShouldThrowRuleExceptionForBusinessRuleViolation()
        {
            // Arrange
            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>()))
            .Throws(new BusinessRuleException(HttpStatusCode.PaymentRequired, ""));
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            var ex = (BusinessRuleException)Assert.Throws(typeof(BusinessRuleException),
                                                          () => payments.Continue(MerchantData, _continuation));

            // Assert
            Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.PaymentRequired));
        }
コード例 #5
0
        public void ItShouldThrowUnothorizedExceptionForInvalidPermissions()
        {
            // Arrange
            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>()))
            .Throws(new UnauthorizedException(HttpStatusCode.Unauthorized, ""));
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            var ex = (UnauthorizedException)Assert.Throws(typeof(UnauthorizedException),
                                                          () => payments.Continue(MerchantData, _continuation));

            // Assert
            Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.Unauthorized));
        }
コード例 #6
0
        public void ItShouldThrowBadRequestExceptionForInvalidRequest()
        {
            // Arrange
            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>()))
            .Throws(new InvalidRequestException(HttpStatusCode.PaymentRequired, ""));
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            var ex = (InvalidRequestException)Assert.Throws(typeof(InvalidRequestException),
                                                            () => payments.Complete(TrnId, _payment));

            // Assert
            Assert.That(ex.StatusCode, Is.EqualTo((int)HttpStatusCode.PaymentRequired));
        }
コード例 #7
0
        public void ItShouldHaveATransactionIdForASuccessfulPayment()
        {
            // Arrange
            var webresult = new WebCommandResult <string> {
                Response = @"{""id"":""10000000""}"
            };

            _executer.Setup(e => e.ExecuteCommand(It.IsAny <ExecuteWebRequest>())).Returns(webresult);

            Beanstream.MerchantId = 100000000;
            Beanstream.ApiKey     = "F6EF00BDB80748358D52D8605CDC7027";
            Payments payments = Beanstream.Payments();

            payments.Repository = new HttpWebRequest(_executer.Object);

            // Act
            dynamic result = payments.Continue(MerchantData, _continuation);
            var     id     = (int)JObject.Parse(result).id;

            // Assert
            Assert.AreEqual(id, 10000000);
        }