public async Task CreateSavedSearchAsync_Invokes_Executor_Execute() { const string Query = "#LinqToTwitter"; TwitterContext ctx = InitializeTwitterContextMock(); var tcsResponse = new TaskCompletionSource <string>(); tcsResponse.SetResult(SavedSearchResponse); execMock.SetupGet(exec => exec.Authorizer).Returns(authMock.Object); execMock.Setup(exec => exec.PostToTwitterAsync <SavedSearch>( It.IsAny <string>(), It.IsAny <IDictionary <string, string> >(), It.IsAny <CancellationToken>())) .Returns(tcsResponse.Task); var parameters = new Dictionary <string, string> { { "query", Query } }; SavedSearch search = await ctx.CreateSavedSearchAsync("#LinqToTwitter"); execMock.Verify(exec => exec.PostToTwitterAsync <SavedSearch>( "https://api.twitter.com/1.1/saved_searches/create.json", parameters, It.IsAny <CancellationToken>()), Times.Once()); Assert.IsNotNull(search); Assert.AreEqual(Query, search.Name); Assert.AreEqual(Query, search.Query); }
public async Task CreateSavedSearchAsync_Throws_On_Missing_Query() { TwitterContext ctx = InitializeTwitterContextMock(); var ex = await L2TAssert.Throws <ArgumentException>( async() => await ctx.CreateSavedSearchAsync(null)); Assert.AreEqual("query", ex.ParamName); }
static async Task CreateSavedSearchAsync(TwitterContext twitterCtx) { SavedSearch savedSearch = await twitterCtx.CreateSavedSearchAsync("linq"); if (savedSearch != null) { Console.WriteLine( "ID: {0}, Search: {1}", savedSearch.IDResponse, savedSearch.Query); } }
public async Task CreateSavedSearchAsync_WithRawResult_Succeeds() { TwitterContext ctx = InitializeTwitterContextMock(); var tcsResponse = new TaskCompletionSource <string>(); tcsResponse.SetResult(SavedSearchResponse); execMock.SetupGet(exec => exec.Authorizer).Returns(authMock.Object); execMock.Setup(exec => exec.PostToTwitterAsync <SavedSearch>( It.IsAny <string>(), It.IsAny <IDictionary <string, string> >(), It.IsAny <CancellationToken>())) .Returns(tcsResponse.Task); await ctx.CreateSavedSearchAsync("#LinqToTwitter"); Assert.AreEqual(SavedSearchResponse, ctx.RawResult); }