Ejemplo n.º 1
0
        public void GenerateAudienceForTokenClientTest(string endpoint, string endpointMask,
                                                       FakeHttpServerResponse serverResponse, string midPopAudience, string miniPopAudience)
        {
            const string   midPopCountryCode  = "us";
            const string   miniPopCountryCode = "pu";
            const string   recordKey          = "someRecordKey";
            FakeHttpServer server             = null;

            if (!string.IsNullOrEmpty(serverResponse?.Body))
            {
                server = new FakeHttpServer(Port, new[] { serverResponse });
                server.Start();
            }

            using var httpClient = new HttpClient { Timeout = new TimeSpan(0, 0, 30) };
            var tokenClient = new FakeTokenClient();

            using var dao = HttpDao.NewDao(EnvId, tokenClient, httpClient, endpoint, endpointMask, s_endpoint);
            //midpop
            Assert.ThrowsAsync <StorageServerException>(async() =>
                                                        await dao.ReadRecordAsync(midPopCountryCode, recordKey).ConfigureAwait(false));
            Assert.AreEqual(midPopAudience, tokenClient.Audience);
            //minipop
            Assert.ThrowsAsync <StorageServerException>(async() =>
                                                        await dao.ReadRecordAsync(miniPopCountryCode, recordKey).ConfigureAwait(false));
            Assert.AreEqual(miniPopAudience, tokenClient.Audience);
            server?.Stop();
        }
Ejemplo n.º 2
0
        public void ReLoadCountryListTest()
        {
            const string shortCountryListJson = "{\n" +
                                                "  \"countries\": [\n" +
                                                "    {\n" +
                                                "      \"direct\": true,\n" +
                                                "      \"id\": \"US\",\n" +
                                                "      \"name\": \"United States\",\n" +
                                                "      \"region\": \"amer\",\n" +
                                                "      \"status\": \"active\",\n" +
                                                "      \"type\": \"mid\"\n" +
                                                "    }]" +
                                                "}";
            var shortCountryListResponse = new FakeHttpServerResponse(200, shortCountryListJson);
            var longCountryListResponse  = new FakeHttpServerResponse(200, CountryLoadResponse);

            var server = new FakeHttpServer(Port,
                                            new[] { shortCountryListResponse, longCountryListResponse });

            using var httpClient = new HttpClient { Timeout = new TimeSpan(0, 0, 1) };
            server.Start();

            using var dao = HttpDao.NewDao(EnvId, new ApiKeyTokenClient("token"), httpClient,
                                           endPointMask: ".localhost",
                                           countriesEndPoint: s_endpoint, updateInterval: 1);
            var popList = dao.GetPopDictionaryClone();

            Assert.IsNotNull(popList);
            Assert.AreEqual(1, popList.Count);
            Assert.AreEqual("US", popList[0].Id);
            Thread.Sleep(2_000);
            Assert.ThrowsAsync <StorageServerException>(async() =>
                                                        await dao.DeleteRecordAsync("us", Guid.NewGuid().ToString()).ConfigureAwait(false));
            popList = dao.GetPopDictionaryClone();
            Assert.IsNotNull(popList);
            Assert.AreEqual(2, popList.Count);
            server.Stop();
        }