public async Task CacheLoad()
        {
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());
            TestingResourcesHelper.InjectCachedQueriesData(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Load();

            var queryCacheService = ServiceResolver.GetService <IQueryCacheService>() as
                                    AOEMatchDataProvider.Services.Default.QueryCacheService;     //cast to specified service to get access for internal fields/methods

            queryCacheService.Load();

            Assert.IsTrue(queryCacheService.Queries.CachedQueries.ContainsKey(productRequest), "Cache should exists");

            //CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(5000);

            //var requestResponseWrapper = await queryCacheService.GetOrUpdate(productRequest, cancellationTokenSource.Token, DateTime.UtcNow.AddDays(1));

            //if (!requestResponseWrapper.IsSuccess)
            //    Assert.Fail("Request failed");

            //Assert.IsTrue(queryCacheService.Queries.CachedQueries.ContainsKey(productRequest), "Cache exists");
        }
示例#2
0
        public void IncompleteUsersDataProcessingFromMatchData()
        {
            var responseRaw       = TestingResourcesHelper.GetApiResoponses("MatchDetailsValid.json");
            var processingService = ServiceResolver.GetService <IUserDataProcessingService>();

            var stringResources = JsonConvert.DeserializeObject <AoeNetAPIStringResources>(TestingResourcesHelper.GetApiResoponses("ApiStringResources.json"));

            Match match = processingService.ProcessMatch(responseRaw, stringResources);

            Assert.AreEqual(match.Users.Count, 2, "Users in match count is incorrect");

            //make sure other fields was processed as expected

            //test both players profile IDs
            Assert.IsNotNull(match.Users.First().UserGameProfileId, "Player[0] profile id wasn't processed");
            Assert.IsNotNull(match.Users.Last().UserGameProfileId, "Player[1] profile id wasn't processed");

            //test both players names
            Assert.IsNotNull(match.Users.First().Name, "Player[0] name wasn't processed");
            Assert.IsNotNull(match.Users.Last().Name, "Player[1] name wasn't processed");

            //validate color property (have to be set)
            Assert.IsNotNull(match.Users.First().Color, "Player[0] color is wasn't processed");
            Assert.IsNotNull(match.Users.Last().Color, "Player[1] color is wasn't processed");

            //validate user match types and match type
            Assert.AreEqual(match.MatchType, MatchType.RandomMap);
            Assert.AreEqual(match.Users.First().MatchType, MatchType.RandomMap);
            Assert.AreEqual(match.Users.Last().MatchType, MatchType.RandomMap);
        }
        public async Task SampleRequestCache()
        {
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());
            var requestTestingService = ServiceResolver.GetService <IRequestService>() as RequestTestingService;

            //return match in progress
            requestTestingService.AddTestingRule(
                new System.Text.RegularExpressions.Regex("https://reqres.in/api/products/3"),
                RequestTestingService.RequestTestingServiceMode.ReturnPredefinedResult,
                new RequestResponseWrapper()
            {
                ResponseContent = TestingResourcesHelper.GetApiResoponses("Product3.json"),
                IsSuccess       = true
            });

            var queryCacheService = ServiceResolver.GetService <IQueryCacheService>() as AOEMatchDataProvider.Services.Default.QueryCacheService; //cast to specified service to get access for internal props

            queryCacheService.Load();

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(timeout);

            var requestResponseWrapper = await queryCacheService.GetOrUpdate(productRequest, cancellationTokenSource.Token, DateTime.UtcNow.AddYears(1000));

            if (!requestResponseWrapper.IsSuccess)
            {
                Assert.Fail("Request failed");
            }

            Assert.IsTrue(queryCacheService.Queries.CachedQueries.ContainsKey(productRequest), "Cache should exists");

            var requestResponseWrapperFromCache = await queryCacheService.GetOrUpdate(productRequest, cancellationTokenSource.Token, DateTime.UtcNow.AddYears(1000));

            Assert.AreEqual(requestResponseWrapper, requestResponseWrapperFromCache);
        }
示例#4
0
        public void ExpireTime()
        {
            //make sure all entries will be deleted
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("sessionKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.AfterSession);
            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);
            storageService.Create("nonExpiredKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Expire, DateTime.UtcNow + new TimeSpan(24, 0, 0));

            //make sure entry will be expired
            storageService.Create("expiredKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Expire, DateTime.UtcNow + new TimeSpan(0, 0, 0, 0, 5));
            Thread.Sleep(10);

            //test expierd entry
            Assert.ThrowsException <EntryExpiredException>(() =>
            {
                storageService.Get("expiredKey");
            }, "Expired entry have to throw exception during R/W operations");

            Assert.ThrowsException <EntryExpiredException>(() =>
            {
                storageService.Update("expiredKey", StorageValueWrapper.FromValue(2));
            }, "Expired entry have to throw exception during R/W operations");

            storageService.UpdateExpireDate("expiredKey", DateTime.UtcNow + new TimeSpan(24, 0, 0));
            storageService.Update("expiredKey", StorageValueWrapper.FromValue(5));

            //test if reseted entry will be changed as expected
            Assert.AreEqual(storageService.Get <StorageValueWrapper>("expiredKey").value, 5);

            //save data
            storageService.Flush();

            //reset service(es)
            Cleanup();
            Init();

            storageService = ServiceResolver.GetService <IStorageService>();
            storageService.Load();

            Assert.IsFalse(storageService.Has("sessionKey"), "Session key shouldn't be saved and loaded");
            Assert.AreEqual(storageService.Get <StorageValueWrapper>("infiniteKey").value, 1, "Inifinite key should be aviable");
        }
示例#5
0
        public void MatchState()
        {
            var processingService = ServiceResolver.GetService <IUserDataProcessingService>();

            var stringResources = JsonConvert.DeserializeObject <AoeNetAPIStringResources>(TestingResourcesHelper.GetApiResoponses("ApiStringResources.json"));

            Match matchFinished   = processingService.ProcessMatch(TestingResourcesHelper.GetApiResoponses("MatchFinished.json"), stringResources);
            Match matchInProgress = processingService.ProcessMatch(TestingResourcesHelper.GetApiResoponses("MatchInProgress.json"), stringResources);

            //todo: rewrite assertion fail description messages to better describe testing properties roles
            //check is match finished
            Assert.IsNotNull(matchFinished.Finished, "Match state wasn't processed correctly");
            Assert.IsNull(matchInProgress.Finished, "Match state wasn't processed correctly"); //have to be null

            //same as above but using property
            Assert.IsTrue(matchInProgress.IsInProgress, "Match state wasn't processed correctly");
            Assert.IsFalse(matchFinished.IsInProgress, "Match state wasn't processed correctly");
        }
示例#6
0
        public void Init()
        {
            ServiceResolver.SetupServicesForIMatchProcessingService(TestContext);

            var storageService = ServiceResolver.GetService <IStorageService>();

            //setup app resources
            if (!storageService.Has("stringResources"))
            {
                var stringResources = JsonConvert.DeserializeObject <AoeNetAPIStringResources>(TestingResourcesHelper.GetApiResoponses("ApiStringResources.json"));
                storageService.Create("stringResources", stringResources, StorageEntryExpirePolicy.AfterSession);
            }

            if (!storageService.Has("settings"))
            {
                storageService.Create("settings", TestingResourcesHelper.GetTestingSettings(), StorageEntryExpirePolicy.AfterSession);
            }
        }
示例#7
0
        public void FlushLoad()
        {
            //make sure all entries will be deleted
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);

            //save data
            storageService.Flush();

            //reset service(es)
            Cleanup();
            Init();

            storageService = ServiceResolver.GetService <IStorageService>();
            storageService.Load();

            Assert.AreEqual(storageService.Get <StorageValueWrapper>("infiniteKey").value, 1, "Inifinite key should be aviable");
        }
示例#8
0
        public void TestDeserializedStorageEntityExpireRule()
        {
            //make sure all entries will be deleted
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);

            //save data
            storageService.Flush();

            //reset service(es)
            Cleanup();
            Init();

            storageService = ServiceResolver.GetService <IStorageService>();
            storageService.Load();

            Assert.AreEqual(storageService.GetExpirePolicy("infiniteKey"), StorageEntryExpirePolicy.Never, "Created and loaded expire policies should be same");
        }
示例#9
0
        public void UserDataByLadderRequest()
        {
            var processingService = ServiceResolver.GetService <IUserDataProcessingService>();

            var stringResources = JsonConvert.DeserializeObject <AoeNetAPIStringResources>(TestingResourcesHelper.GetApiResoponses("ApiStringResources.json"));

            var ladderRandomMap = processingService.ProcessUserRankFromLadder(
                TestingResourcesHelper.GetApiResoponses("LeadboardRandomMapValid.json"),
                Ladders.RandomMap,
                stringResources
                );

            var ladderTeamRandomMap = processingService.ProcessUserRankFromLadder(
                TestingResourcesHelper.GetApiResoponses("LeadbordTeamRandomMapValid.json"),
                Ladders.TeamRandomMap,
                stringResources
                );

            Assert.AreEqual(ladderRandomMap.Elo, 2279, "Rating should be same as declarated with response");
            Assert.AreEqual(ladderTeamRandomMap.Elo, 2432, "Rating should be same as declarated with response");
        }
示例#10
0
        public async Task TestMatchProcessingValidMatch()
        {
            var requestTestingService = ServiceResolver.GetService <IRequestService>() as RequestTestingService;
            var matchService          = ServiceResolver.GetService <IMatchProcessingService>();

            //return match in progress response
            requestTestingService.AddTestingRule(
                new System.Text.RegularExpressions.Regex("https://aoe2.net/api/player/lastmatch?"),
                RequestTestingService.RequestTestingServiceMode.ReturnPredefinedResult,
                new RequestResponseWrapper()
            {
                ResponseContent = TestingResourcesHelper.GetApiResoponses("MatchInProgress.json"),
                IsSuccess       = true
            });

            var matchState = await matchService.TryUpdateCurrentMatch();

            Assert.IsTrue(matchState == MatchUpdateStatus.SupportedMatchType);

            requestTestingService.ClearCustomRules();
        }