public async Task MakeECommercePayment_Throws_Http_Exception_For_Not_Ok_Status_Codes()
 {
     var mockHttp = MockHttp.WithStatus(500);
     var client   = new SwishClient(mockHttp, _merchantId);
     await Assert.ThrowsAsync <HttpRequestException>(() =>
                                                     client.MakeECommercePaymentAsync(_defaultECommercePaymentModel));
 }
        public async Task MakeMCommercePaymentAsync_Returns_Correct_ErrorMessage(int status, string message)
        {
            var mockHttp = MockHttp.WithStatus(status);
            var client   = new SwishClient(mockHttp, _merchantId);

            var result = await client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel);

            result.ErrorMessage.Should().Contain(message);
            result.ErrorCode.Should().Be(status.ToString());
        }
        public async Task GetPaymeentStatus_Returns_Correct_ErrorMessage(int status, string message)
        {
            var mockHttp = MockHttp.WithStatus(status);
            var client   = new SwishClient(mockHttp, _merchantId);

            var result = await client.GetPaymentStatus(SwishId);

            result.ErrorMessage.Should().Contain(message);
            result.ErrorCode.Should().Be(status.ToString());
        }
        public async Task MakeMCommercePaymentAsync_Returns_Correct_ErrorMessage_For_422(string errorCode, string errorMessage, string content)
        {
            var mockHttp = MockHttp.WithStatusAndContent(422, content);
            var client   = new SwishClient(mockHttp, _merchantId);

            var result = await client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel);

            result.ErrorMessage.Should().Contain(errorMessage);
            result.ErrorCode.Should().Be(errorCode);
        }
        public async Task MakeECommercePayment_Throws_Swich_Exception_When_Status_Code_Is_422()
        {
            var errorMsg  = "Testing error";
            var mockHttp  = MockHttp.WithStatusAndContent(422, errorMsg);
            var client    = new SwishClient(mockHttp, _merchantId);
            var exception = await Assert.ThrowsAsync <HttpRequestException>(() =>
                                                                            client.MakeECommercePaymentAsync(_defaultECommercePaymentModel));

            Assert.Equal(errorMsg, exception.Message);
        }
        public async Task MakeRefund_Returns_Location_Header_Values()
        {
            string refundId       = "ABC2D7406ECE4542A80152D909EF9F6B";
            string locationHeader = $"https://mss.swicpc.bankgirot.se/swishcpcapi/v1/refunds/{refundId}";
            var    headerValues   = new Dictionary <string, string>()
            {
                { "Location", locationHeader }
            };
            var responseMessage = Create201HttpJsonResponseMessage(_defaultRefund, headerValues);
            var client          = new SwishClient(MockHttp.WithResponseMessage(responseMessage), _merchantId);

            // Act
            var response = await client.MakeRefundAsync(_defaultRefund);

            // Assert
            Assert.Equal(response.Location, locationHeader);
            Assert.Equal(response.Id, refundId);
        }
        public async Task MakeMCommercePayment_Returns_Location_And_Token_Header_VaLues()
        {
            string paymentId      = "AB23D7406ECE4542A80152D909EF9F6B";
            string locationHeader = $"https://mss.swicpc.bankgirot.se/swishcpcapi/v1/paymentrequests/{paymentId}";
            var    headerValues   = new Dictionary <string, string>()
            {
                { "Location", locationHeader },
                { "PaymentRequestToken", "f34DS34lfd0d03fdDselkfd3ffk21" }
            };
            var responseMessage = Create201HttpJsonResponseMessage(_defaultMCommercePaymentModel, headerValues);
            var client          = new SwishClient(MockHttp.WithResponseMessage(responseMessage), _merchantId);

            // Act
            var response = await client.MakeMCommercePaymentAsync(_defaultMCommercePaymentModel);

            // Assert
            Assert.Equal(locationHeader, response.Location);
            Assert.Equal(paymentId, response.Id);
            Assert.Equal("f34DS34lfd0d03fdDselkfd3ffk21", response.Token);
        }
        public async Task MakeECommercePayment_Should_Fix_PayerAlias()
        {
            string paymentId      = "AB23D7406ECE4542A80152D909EF9F6B";
            string locationHeader = $"https://mss.swicpc.bankgirot.se/swishcpcapi/v1/paymentrequests/{paymentId}";
            var    headerValues   = new Dictionary <string, string>()
            {
                { "Location", locationHeader }
            };

            _defaultECommercePaymentModel.PayerAlias = "0701234567";
            var responseMessage = Create201HttpJsonResponseMessage(_defaultECommercePaymentModel, headerValues);
            var mockHttp        = MockHttp.WithResponseMessage(responseMessage);
            var client          = new SwishClient(mockHttp, _merchantId);

            // Act
            var response = await client.MakeECommercePaymentAsync(_defaultECommercePaymentModel);

            // Assert
            var body = await mockHttp.LastRequest.Content.ReadAsStringAsync();

            var request = JsonConvert.DeserializeObject <ECommercePaymentModel>(body);

            Assert.Equal("46701234567", request.PayerAlias);
        }