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"));
        }
        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"));
        }
        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));
        }
        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));
        }
        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));
        }
        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);
        }