public void PublishUserAchievements()
        {
            User user = new User {
                SteamUserId = "user1", FacebookUserId = 1, AccessToken = "token", AutoUpdate = true
            };

            _userServiceMock.Setup(service => service.GetUser(user.SteamUserId))
            .Returns(user)
            .Verifiable();

            _achievementServiceMock.Setup(service => service.UpdateAchievements(user.SteamUserId, null))
            .Returns(1)
            .Verifiable();
            _achievementServiceMock.Setup(
                service => service.GetUnpublishedAchievements(user.SteamUserId, DateTime.UtcNow.AddDays(-2).Date, null))
            .Returns(
                new List <Achievement>
            {
                new Achievement
                {
                    Id          = 1,
                    Name        = "achievement 1",
                    Description = "x",
                    ImageUrl    = "http://example.com/a.jpg",
                    Game        =
                        new Game
                    {
                        Id       = 1,
                        Name     = "game 1",
                        ImageUrl = "http://example.com/g.jpg",
                        StatsUrl = "http://example.com/stats",
                        StoreUrl = "http://example.com/store"
                    }
                }
            })
            .Verifiable();

            _publisherMock.Setup(pub => pub.Publish(It.IsAny <User>(), It.IsAny <IDictionary <string, object> >()))
            .Verifiable();

            _achievementServiceMock.Setup(service => service.PublishAchievements(user.SteamUserId, new List <int> {
                1
            }))
            .Returns(true)
            .Verifiable();

            _manager.PublishUserAchievements(user.SteamUserId);

            _achievementServiceMock.Verify();
            _publisherMock.Verify();
            _userServiceMock.Verify();
        }
Esempio n. 2
0
        public void PublishUserAchievements()
        {
            User user = new User {
                SteamUserId = "user1", FacebookUserId = 1, AccessToken = "token", AutoUpdate = true
            };

            _userServiceMock.ExpectAndReturn("GetUser", user, "user1");
            _achievementServiceMock.ExpectAndReturn("UpdateAchievements", 1, "user1");
            _achievementServiceMock.ExpectAndReturn("GetUnpublishedAchievements",
                                                    new List <SimpleAchievement>
            {
                new SimpleAchievement
                {
                    Id          = 1,
                    Name        = "achievement 1",
                    Description = "x",
                    ImageUrl    = "http://example.com/a.jpg",
                    Game        =
                        new Game
                    {
                        Id       = 1,
                        Name     = "game 1",
                        ImageUrl = "http://example.com/g.jpg",
                        StatsUrl = "http://example.com/stats",
                        StoreUrl = "http://example.com/store"
                    }
                }
            },
                                                    "user1", DateTime.UtcNow.AddDays(-2).Date);
            _publisherMock.Expect("Publish");
            _achievementServiceMock.ExpectAndReturn("PublishAchievements", true, "user1", new List <int> {
                1
            });

            _manager.PublishUserAchievements(user.SteamUserId);

            _achievementServiceMock.Verify();
            _publisherMock.Verify();
            _userServiceMock.Verify();
        }
Esempio n. 3
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string logPath = context.Server.MapPath("~/App_Data/AutoUpdate");
                _log = new AutoUpdateLogger(logPath);

                IUnityContainer container = ContainerManager.Container;
                _manager = new AutoUpdateManager(container.Resolve <IAchievementService>(),
                                                 container.Resolve <IUserService>(),
                                                 container.Resolve <IFacebookPublisher>(), _log);

                bool authorized = context.Request["auth"] == Properties.Settings.Default.AutoUpdateAuthKey;
                if (!authorized)
                {
                    _log.Log("Invalid auth key");
                    context.Response.Write("Invalid auth key");
                }
                else
                {
                    string method = context.Request["method"];

                    if (method == "GetAutoUpdateUsers")
                    {
                        _log.Log("Getting auto update users");

                        string users = _manager.GetAutoUpdateUsers();

                        _log.Log(users);

                        _log.Flush();

                        context.Response.Write(users);
                    }
                    else if (method == "PublishUserAchievements")
                    {
                        string userName = context.Request["user"];

                        _manager.PublishUserAchievements(userName);

                        _log.Flush();

                        context.Response.Write(userName + " published.");

                        // delete logs more than two weeks old
                        _log.Delete(DateTime.UtcNow.AddDays(-14).Date);
                    }
                    else
                    {
                        context.Response.Write("Invalid method");
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Log(ex);
                _log.Write(context.Response);
            }
            finally
            {
                _manager.Dispose();
                _log.Flush();
            }
        }