Example #1
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);
        }
Example #3
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");
        }
Example #4
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");
        }
Example #5
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();
        }
Example #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);
            }
        }