1.11 Constructing TwitterContext with ITwitterExecute

Jul 15, 2009 at 3:11 PM

Hi,

I come across using oAuth and trying to construct twitter context. Anybody able to provide me sample on how to construct with ITwitterExecute. It seem like I cannot find any example from demo.

 

Thanks

Ervin

Coordinator
Jul 15, 2009 at 6:30 PM

Hi Ervin,

The reason I added the constructor with ITwitterExecute was so that I could use dependency injection to mock the object for testing. Normally, you wouldn't ever use this constructor yourself.  If you look inside of the LinqToTwitterTests project, there is a file called TwitterContextText that has a field named m_twitterExecute of type ITwitterExecute.  Here's the on-line link:

http://linqtotwitter.codeplex.com/SourceControl/changeset/view/56275#608697

If you look at MyTestInitialize, where I initialize the tests, you can see that I assign a mock to m_twitterExecute.

In the TwitterContext constructor, I automatically set TwitterExecutor, which is ITwitterExecute, to a new instance of TwitterExecute, which is ITwitterExecute, if there is not an instance of ITwitterExecute passed in (i.e. the parameter is null).

When using LINQ to Twitter, you can instantiate the constructor as shown in the Program.cs example's in Main.  

Joe

Jul 16, 2009 at 5:11 AM

Hi Joe,

I will have a try on changeset version of 56275. Currently I am working on ASP.NET MVC with OAuth, I found the previous version is very convenient by just injecting IOAuthTwitter into TwitterContext's constructor. Unfortunately it is no longer exist in latest change set. I tried WebOAuthAuthorization, but it is only workable in web form.

Noticed that in version 1.11.0.0, TwitterContext is not auto inject twiter executor.

Ervin

Jul 16, 2009 at 2:56 PM

Ervin,

I'd be happy to fix WebOAuthAuthorization for ASP.NET MVC, but I wonder if you can elaborate on why you say it's only workable in web forms?  Until I write an MVC sample I won't know first hand, so you might be able to give me a head start.

The only non-MVC'ish thing I can see WebOAuthAuthorization doing is it does a Response.Redirect.  While MVC likes to return an ActionResult that redirects instead, and I can fix that, to my knowledge that doesn't break anything in MVC.  So is there something else?

Jul 16, 2009 at 3:26 PM

aarnott,

That would be nice. Yes MVC's only problem with your mentioned above. I am happily to test it after you fix it. :)

Jul 16, 2009 at 3:59 PM

Done.  Check out the latest changeset and use MvcOAuthAuthorization.

How's that for response time? :)

 

(btw, response time might plummet because I'm heading out on a three day trip.)

Jul 17, 2009 at 5:14 AM

aarnott,

I am able to plug in MvcOAuthAuthorization perfectly in asp.net mvc. Do let me know if you need the demo project file.

Thanks

Coordinator
Jul 17, 2009 at 2:16 PM

Awesome

Oct 2, 2009 at 3:28 PM

Is there an MVC demo project file anywhere... or included in the latest release?

Thanks