コード例 #1
0
        public void ShouldReturnErrorMessageWhenPassingNullRequest()
        {
            //Arrange
            AuthorizationTransaction authTransaction = new AuthorizationTransaction(null, null, logger, null);
            //Act
            AuthorizationResponse response = authTransaction.Execute(null);

            //Assert
            Assert.AreEqual("Ocorreu um erro na chamada da transação de autorização. Verifique o log de erro para mais detalhes", response.ReturnMessage);
        }
コード例 #2
0
        public void ShouldNotCallParseMessageToResponseWhenStatusCodeIsNotSuccess()
        {
            //Arrange
            AuthorizationRequest authRequest = new AuthorizationRequest()
            {
                Payment = new Payment()
                {
                    Amount = 10000
                }
            };
            //Mock Formatter
            var formatterMock = new Mock <IFormatter <AuthorizationRequest, AuthorizationResponse, string> >();

            formatterMock.Setup(f => f.ParseMessageToResponse(It.IsAny <string>()));
            formatterMock.Setup(f => f.ParseRequestToMessage(It.IsAny <AuthorizationRequest>()));
            //Mock Service
            var serviceMock = new Mock <HttpServiceBase <AuthorizationRequest, HttpResponseMessage> >(MockBehavior.Strict, new Credential(), "urlFake");

            serviceMock.Setup(s => s.Execute(It.IsAny <AuthorizationRequest>())).Returns(new HttpResponseMessage()
            {
                Content = new StringContent("teste"), StatusCode = System.Net.HttpStatusCode.NotFound
            });
            //Mock Validator
            var validatorMock = new Mock <BaseValidator <AuthorizationRequest> >(logger);

            validatorMock.Setup(v => v.ValidateField(authRequest)).Returns(true);

            AuthorizationTransaction authTransaction = new AuthorizationTransaction(formatterMock.Object, serviceMock.Object, logger, validatorMock.Object);

            //Act
            authTransaction.Execute(authRequest);
            //Assert
            formatterMock.Verify(f => f.ParseMessageToResponse(It.IsAny <string>()), Times.Never);
            formatterMock.Verify(f => f.ParseRequestToMessage(It.IsAny <AuthorizationRequest>()), Times.Once);
            serviceMock.Verify(s => s.Execute(It.IsAny <AuthorizationRequest>()), Times.Once);
        }