[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/signnow/SignNow.NET/develop/SignNow.Net.Test/SignNowTestBase.cs [Back]  [Original]

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Bogus;
using Moq;
using Moq.Protected;
using SignNow.Net.Interfaces;
using SignNow.Net.Service;

namespace UnitTests
{
    public abstract class SignNowTestBase
    {
        protected static Faker Faker => new Faker();
        protected static Uri ApiBaseUrl => new Uri("https://api-eval.signnow.com/");

        private static readonly string BaseTestDataPath = "../../../TestData/"
            .Replace('/', Path.DirectorySeparatorChar);

        protected static readonly string PdfFileName = "DocumentUpload.pdf";
        protected static readonly string TxtFileName = "DocumentUpload.txt";

        protected static string PdfFilePath => Path.Combine($"{BaseTestDataPath}Documents", PdfFileName);
        protected static string TxtFilePath => Path.Combine($"{BaseTestDataPath}Documents", TxtFileName);

        /// 
        /// Create Mock for HttpClient
        /// 
        /// Json response that you want to be returned
        /// Http status that you expect
        /// 
        protected ISignNowClient SignNowClientMock(string jsonResponse, HttpStatusCode code = HttpStatusCode.OK)
        {
            var handlerMock = new Mock(MockBehavior.Strict);

            handlerMock
                .Protected()
                .Setup("SendAsync", ItExpr.IsAny(), ItExpr.IsAny())
                .ReturnsAsync(new HttpResponseMessage
                {
                    StatusCode = code,
                    Content = new StringContent(jsonResponse)
                })
                .Verifiable();

            // use real http client with mocked handler here
            return new SignNowClient(new HttpClient(handlerMock.Object, true));
        }
    }
}

Web Proxy Viewer  |  New URL  |  Original Page