public void ParseHl2Achievements()
        {
            string xml = File.ReadAllText("hl2Achievements.xml");

            AchievementXmlParser parser = new AchievementXmlParser();

            parser.Parse(xml);
        }
        public void ParseValid()
        {
            string xml = File.ReadAllText("achievements.xml");

            AchievementXmlParser      parser       = new AchievementXmlParser();
            IEnumerable <Achievement> achievements = parser.Parse(xml, 1);

            Assert.That(achievements.Any());
        }
        public void ParseValid()
        {
            string xml = File.ReadAllText("achievements.xml");

            AchievementXmlParser      parser       = new AchievementXmlParser();
            IEnumerable <Achievement> achievements = parser.Parse(xml);

            Assert.That(achievements.Any());
            Assert.That(achievements.Any(a => a.Name == "Fried Piper" && a.Closed));
            Assert.That(achievements.Any(a => a.Name == "Cl0wnd" && !a.Closed));
        }
        public void ParseTf2MagnakayDeathFromAboveNotClosed()
        {
            string xml = File.ReadAllText("achievements2.xml");

            AchievementXmlParser      parser       = new AchievementXmlParser();
            IEnumerable <Achievement> achievements = parser.Parse(xml, 2);

            // does not contain Death from Above
            Assert.That(achievements.Any(a => a.Id == 273), Is.False);

            // does not contain First Blood
            Assert.That(achievements.Any(a => a.Id == 270), Is.False);
        }
        public void ParseClosedValid()
        {
            string xml = File.ReadAllText("achievements.xml");

            AchievementXmlParser          parser       = new AchievementXmlParser();
            IEnumerable <UserAchievement> achievements = parser.ParseClosed(xml);

            Assert.That(achievements.Any());
            Assert.That(achievements.All(a => a.SteamUserId == "nullreference"));
            Assert.That(achievements.Any(a => a.Name == "Fried Piper" && a.Closed));
            Assert.That(!achievements.Any(a => !a.Closed));
            Assert.That(achievements.Any(a => a.Name == "Midnight Rider" && a.Closed && a.Date.Ticks == 1261871228));
        }
        public void ParseClosedValid()
        {
            string xml = File.ReadAllText("achievements.xml");

            AchievementXmlParser          parser       = new AchievementXmlParser();
            IEnumerable <UserAchievement> achievements = parser.ParseClosed(xml);

            DateTime expectedUnlockDate = new DateTime(1970, 1, 1).AddSeconds(1261871228);

            Assert.That(achievements.Any());
            Assert.That(achievements.All(a => a.SteamUserId == "nullreference"));
            Assert.That(achievements.Any(a => a.Achievement.Name == "Fried Piper" && a.Closed));
            Assert.That(!achievements.Any(a => !a.Closed));
            Assert.That(
                achievements.Any(a => a.Achievement.Name == "Midnight Rider" && a.Closed && a.Date.Ticks == expectedUnlockDate.Ticks));
        }
        public void ParseNotValid()
        {
            AchievementXmlParser parser = new AchievementXmlParser();

            Assert.Throws <XmlException>(() => parser.Parse("asdf asdf asdf asdf", 1));
        }
        public void UpdateNewUserAchievements()
        {
            Mock <IAchievementManager>    achievementManagerMock = new Mock <IAchievementManager>();
            Mock <ISteamCommunityManager> communityManagerMock   = new Mock <ISteamCommunityManager>();

            // expect
            User user = new User {
                FacebookUserId = 1234, SteamUserId = "user1"
            };

            Data.User dataUser = new Data.User {
                FacebookUserId = 1234, SteamUserId = "user1"
            };
            achievementManagerMock.Setup(rep => rep.GetUser(user.FacebookUserId))
            .Returns(dataUser).Verifiable();

            AchievementXmlParser   achievementXmlParser = new AchievementXmlParser();
            List <UserAchievement> userAchievements     =
                achievementXmlParser.ParseClosed(File.ReadAllText("cssAchievements.xml")).ToList();

            userAchievements.ForEach(
                userAchievement =>
                userAchievement.Game =
                    new Game
            {
                Id       = 240,
                ImageUrl =
                    "http://media.steampowered.com/steamcommunity/public/images/apps/10/af890f848dd606ac2fd4415de3c3f5e7a66fcb9f.jpg",
                Name           = "Counter-Strike: Source",
                PlayedRecently = true,
                StatsUrl       =
                    String.Format("http://steamcommunity.com/id/{0}/games/?xml=1", user.SteamUserId),
                StoreUrl = "http://store.steampowered.com/app/10"
            });

            communityManagerMock.Setup(rep => rep.GetAchievements(user.SteamUserId))
            .Returns(new List <UserAchievement>()).Verifiable();

            achievementManagerMock.Setup(rep => rep.GetUser(user.SteamUserId))
            .Returns(dataUser).Verifiable();
            achievementManagerMock.Setup(rep => rep.UpdateAchievements(It.IsAny <IEnumerable <Data.UserAchievement> >()))
            .Returns(5).Verifiable();

            ICollection <Game> games = new GameXmlParser().Parse(File.ReadAllText("games.xml"));

            communityManagerMock.Setup(rep => rep.GetGames(user.SteamUserId))
            .Returns(games).Verifiable();

            Achievement[] dataAchievements = new[] { new Achievement {
                                                         Description = "x", GameId = 1, Id = 1,
                                                     } };
            achievementManagerMock.Setup(
                rep => rep.GetUnpublishedAchievements(user.SteamUserId, DateTime.UtcNow.Date.AddDays(-2)))
            .Returns(dataAchievements).Verifiable();
            achievementManagerMock.Setup(
                rep =>
                rep.UpdateHidden(user.SteamUserId, It.IsAny <IEnumerable <int> >()))
            .Verifiable();

            // execute
            IAchievementService service =
                new AchievementService(achievementManagerMock.Object, communityManagerMock.Object);

            service.UpdateNewUserAchievements(user);

            // verify
            achievementManagerMock.Verify();
            communityManagerMock.Verify();
        }