Пример #1
0
        /// <summary>
        /// Shows how to update account settings.
        /// </summary>
        /// <param name="twitterCtx">TwitterContext</param>
        static void UpdateAccountSettingsDemo(TwitterContext twitterCtx)
        {
            Account acct = twitterCtx.UpdateAccountSettings(null, true, 20, 6, null, null);

            SleepTime sleep = acct.Settings.SleepTime;
            Console.WriteLine(
                "Enabled: {0}, Start: {1}, End: {2}",
                sleep.Enabled, sleep.StartHour, sleep.EndHour);
        }
        public void UpdateAccountSettings_Invokes_Executor_Execute()
        {
            var authMock = new Mock<ITwitterAuthorizer>();
            var execMock = new Mock<ITwitterExecute>();
            execMock.SetupGet(exec => exec.AuthorizedClient).Returns(authMock.Object);
            execMock.Setup(exec =>
                exec.PostToTwitter(
                    It.IsAny<string>(),
                    It.IsAny<Dictionary<string, string>>(),
                    It.IsAny<Func<string, Account>>()))
                .Returns(SettingsResponse);
            var ctx = new TwitterContext(authMock.Object, execMock.Object, "", "");
            var parameters = new Dictionary<string, string>
            {
                { "trend_location_woeid", "1" },
                { "sleep_time_enabled", "True" },
                { "start_sleep_time", "20" },
                { "end_sleep_time", "6" },
                { "time_zone", "MST" },
                { "lang", "en" }
            };

            Account acct = ctx.UpdateAccountSettings(1, true, 20, 6, "MST", "en");

            execMock.Verify(exec =>
                exec.PostToTwitter(
                    "https://api.twitter.com/1.1/account/settings.json",
                    parameters,
                    It.IsAny<Func<string, Account>>()),
                Times.Once());
            Assert.NotNull(acct);
            Settings settings = acct.Settings;
            Assert.NotNull(settings);
            Assert.Equal("en", settings.Language);
        }