Example #1
0
        public async Task <IEnumerable <AchievementBase> > UpdateAchievements()
        {
            var existingUnlocked = DbManager.DataAccess.Achievements().GetAchievements()
                                   .Where(it => it.IsUnlocked)
                                   .Select(it => it.Id);

            var achievementDtos = await client.GetAchievements();

            var unlockedAchievementIds = (await client.GetUnlockedAchievements())
                                         .Select(it => it.Id.ToString())
                                         .ToList();

            return(DbManager.InTransaction(transaction =>
            {
                var achievements = AchievementConverter.Convert(achievementDtos, transaction.DataAccess).ToList();
                foreach (var unlocked in achievements.Where(it => unlockedAchievementIds.Contains(it.Id)))
                {
                    unlocked.IsUnlocked = true;
                }
                foreach (var achievement in achievements)
                {
                    if (transaction.DataAccess.GetItem <AchievementBase>(achievement.Id) == null)
                    {
                        transaction.DataAccess.AddItem(achievement);
                    }
                }
                return achievements.Where(it => it.IsUnlocked && !existingUnlocked.Contains(it.Id));
            }));
        }
        public void Test_ExhibitsVisitedAchievementConversion()
        {
            var dataAccess = IoCManager.Resolve <IDataAccess>();
            var exhibitsVisitedAchievementDto = new ExhibitsVisitedAchievementDto(234, "title", "description", "imageUrl", 235, 10, 25);

            dataAccess.InTransaction <object>(transaction =>
            {
                var exhibitsVisitedAchievement = AchievementConverter.Convert(new List <AchievementDto>
                {
                    exhibitsVisitedAchievementDto
                }, transaction.DataAccess)[0] as ExhibitsVisitedAchievement;

                Assert.NotNull(exhibitsVisitedAchievement);
                Assert.AreEqual(exhibitsVisitedAchievementDto.Id.ToString(), exhibitsVisitedAchievement.Id);
                Assert.AreEqual(exhibitsVisitedAchievementDto.Description, exhibitsVisitedAchievement.Description);
                Assert.AreEqual(exhibitsVisitedAchievementDto.ThumbnailUrl, exhibitsVisitedAchievement.ThumbnailUrl);
                Assert.AreEqual(exhibitsVisitedAchievementDto.Title, exhibitsVisitedAchievement.Title);
                Assert.AreEqual(exhibitsVisitedAchievementDto.Count, exhibitsVisitedAchievement.Count);
                Assert.AreEqual(exhibitsVisitedAchievementDto.NextId?.ToString(), exhibitsVisitedAchievement.NextId);
                Assert.AreEqual(exhibitsVisitedAchievementDto.Points, exhibitsVisitedAchievement.Points);

                return(null);
            });
        }
        public void Test_RouteFinishedAchievementConversion()
        {
            var dataAccess = IoCManager.Resolve <IDataAccess>();
            var routeFinishedAchievementDto = new RouteFinishedAchievementDto(123, "title", "description", "imageUrl", 124, 25, 456);

            dataAccess.InTransaction <object>(transaction =>
            {
                var routeFinishedAchievement = AchievementConverter.Convert(new List <AchievementDto>
                {
                    routeFinishedAchievementDto
                }, transaction.DataAccess)[0] as RouteFinishedAchievement;

                Assert.NotNull(routeFinishedAchievement);
                Assert.AreEqual(routeFinishedAchievementDto.Id.ToString(), routeFinishedAchievement.Id);
                Assert.AreEqual(routeFinishedAchievementDto.Description, routeFinishedAchievement.Description);
                Assert.AreEqual(routeFinishedAchievementDto.ThumbnailUrl, routeFinishedAchievement.ThumbnailUrl);
                Assert.AreEqual(routeFinishedAchievementDto.Title, routeFinishedAchievement.Title);
                Assert.AreEqual(routeFinishedAchievementDto.NextId?.ToString(), routeFinishedAchievement.NextId);
                Assert.AreEqual(routeFinishedAchievementDto.Points, routeFinishedAchievement.Points);
                Assert.AreEqual(routeFinishedAchievementDto.RouteId, routeFinishedAchievement.RouteId);

                return(null);
            });
        }