Esempio n. 1
0
        public void Init()
        {
            this.mockOptions      = new Mock <IOptions <AppSettings> >();
            this.mockCacheService = new Mock <ICacheService>();

            var appSettings = new AppSettings()
            {
                PetFinderBaseUrl   = "https://api.petfinder.com/v2",
                PetFinderAnimalUrl = "apple",
            };

            this.mockOptions.Setup(x => x.Value).Returns(appSettings);

            var content = new StringContent(JsonConvert.SerializeObject(new TokenResponse()
            {
                AccessToken = "123",
                ExpiresIn   = DateTime.Now.Hour,
                TokenType   = "access",
            }), Encoding.UTF8, "application/json");
            //Mocking the httpclient handler bc we're using httpclientfactory CreateClient method to create the client
            var httpClient = MockHttpHandler.GetClientWithHandler(content);

            this.mockClient = new Mock <IHttpClientFactory>(MockBehavior.Strict);
            this.mockClient.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(httpClient);
            this.authService = new PetFinderAuthService(mockClient.Object, mockOptions.Object, mockCacheService.Object);
        }
Esempio n. 2
0
        public void Init()
        {
            this.mockOptions = new Mock <IOptions <AppSettings> >();
            var appSettings = new AppSettings()
            {
                PetFinderBaseUrl   = "https://api.petfinder.com/v2",
                PetFinderAnimalUrl = "apple",
            };

            this.mockOptions.Setup(x => x.Value).Returns(appSettings);

            this.mockAuth = new Mock <IPetFinderAuthService>();

            //Mocking the httpclient handler bc we're using httpclientfactory CreateClient method to create the client

            var httpClient = MockHttpHandler.GetClientWithHandler();

            this.mockClient = new Mock <IHttpClientFactory>(MockBehavior.Strict);
            this.mockClient.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(httpClient);
            this.petFinderService = new PetFinderApiService(mockClient.Object, mockOptions.Object, mockAuth.Object);
        }