Videos of my presentations at #NDC2010 and #QConLondon2010

From NDC2010 – IronRuby – A brave new world for .Net
Video: http://streaming.ndc2010.no/tcs/?id=7A0F3A2B-AD46-47E8-8748-5BAF9611B4E3
Slides: http://www.slideshare.net/BenHalluk/ironruby-a-brave-new-world-for-net-ndc2010
From NDC2010 – Testing C# and ASP.NET Applications with Ruby
Video: http://streaming.ndc2010.no/tcs/?id=C6611670-4B70-42B3-9C2B-86D576338350
Slides: http://www.slideshare.net/BenHalluk/testing-aspnet-and-c-using-ruby-ndc2010
From QCon London 2010 – Testing C# and ASP.NET Applications with Ruby
Video: http://www.infoq.com/presentations/hall-testing-with-ruby
Slides: http://blog.benhall.me.uk/2010/03/qcon-london-2010-testing-c-and-aspnet.html

While QCon and NDC sessions have the same title, QCon was more focused on the why with NDC2010 being more focused on the how. Don’t forget, if you want to know more about Testing ASP.net there is a (great) book available – http://www.testingaspnet.com/

QCon London 2010 – Testing C# and ASP.net using Ruby

Last week I had the amazing honour of presenting at QCon London 2010 on Testing ASP.net using Ruby. QCon was an amazing conference with some truly amazing speakers, and I did feel a little out of place 🙂

Nonetheless, it was a great experience. A huge thank you to Josh Graham from HashRocket who organised the track and invited me to speak!

For those who are interested, my slides are below. Within the next six months the video should be online too.

Testing ASP.net using Ruby – CodeMash session

This week I went over to CodeMash, an amazing community and cross-language conference in the US. I had some amazing conversations, meet some amazing people and gave a session on Testing ASP.net using Ruby.

I would like to say thank you to everyone who attended and the organisers for giving me the opportunity to speak. If you have any questionscomments, then please give me a shout, Twitter is the best way.

The code I used during the demo can be found on GitHub – http://github.com/BenHall/Kona 

I created a tag so you can download the zip of the code, now and in the future without being affected by other changes – http://github.com/BenHall/Kona/zipball/CodeMash_2010. In future I plan to keep working on this code as a sample so you might want to keep an eye on the repository. 

Also, if you would like to know more about Testing ASP.net web applications, then I recommend you take a look at the book I co-authored, check out http://www.testingaspnet.com

RSpec, IronRuby and RubyMine

RSpec, IronRuby and RubyMine is an amazing combination. Here is a screenshot of an example I’m currently working on…

Rubymine_tests_passing

All I do is execute the Rake command below, which exists in my rakefile.rb. Rubymine does the rest! Very cool.

desc "Run all examples"
Spec::Rake::SpecTask.new('examples') do |t|
  t.spec_files = FileList['examples/**/*.rb']
end

Dynamic Languages and .NET – Developer Day Scotland slides and code samples

This weekend I was in Glasgow presenting my ‘dynamic languages and .NET’ presentation at DeveloperDay Scotland. I demonstrated how you can take advantage of IronRuby as a language, but also how you could host the DLR within your own application to enhance your feature set. I had a great time and the conference was a great success. A massive thank you to Colin Mackay and the others for organising the event, as well as everyone who attended my session.

Slides can be found below, hosted via SlideShare. Code samples can be downloaded here. Photos can be found here.

I was also involved in the Database Testing panel. Very interesting discussion on how to test databases, thank you to everyone who attend the discussion.

One slight disappointment, Gary Short left before giving his IronSmalltalk grok talk – http://www.flickr.com/photos/colinangusmackay/3496808871/

Next up, DDD South West.

Embedding IronRuby and the DLR into Red Gate’s SQL Data Generator

Over the past few months there has been a lot of discussions online about how embedding the DLR (Dynamic Language Runtime) into your application opens up some amazing use cases. For example, Phil Haack recently wrote about how ASP.net MVC views can be stored in the database thanks for the DLR.  Resolver Systems have been doing with with great success.

Tonight, my latest article for Simple Talk was published. The article explains how I went about creating a new generator for SQL Data Generator which allows the user to define the data to be generated based on IronRuby code.  I think this is an amazing use case, both for SQL Data Generator and the DLRIronRuby. By taking advantage of the DLR, we have opened up some extremely useful use-cases within the application. To find out more take a look at the article on Simple Talk.

An example of the generator in action is shown in the screenshot.

IronRuby_SDG 

The article includes the source code and binaries for the SQL Data Generator example generator which you can start using within your project.

NOTE: This Plug-in generator is provided ‘as-is’ and is completely unsupported.

MSDN Magazine: Getting Started With IronRuby And RSpec, Part 1

February2009

My latest article has been published in this months MSDN Magazine. The article is an introduction to IronRuby, finishing with an initial focus on how you can use RSpec and IronRuby together to test C# applications. 

Using IronRuby to test C# applications is an interesting concept and I look forward to seeing how people use the two technologies in the future.

image

I’m really pleased to have been published within the magazine. I have been reading it since I started with .Net so it feels a little strange to know that I’m actually one of the authors…

I still need to get my hands on a physical copy.

Read it here:

http://msdn.microsoft.com/en-us/magazine/dd434651.aspx

Keep an eye out for part 2 in next months edition.

IronTwitter – Sending a tweet from the IronRuby REPL

In my previous post, I discussed how to parse XML from a REST service. As it happens, the REST service I was interested in was the Twitter API. My aim was to use IronRuby to update my Twitter status from the REPL (Read-eval-print loop) – the interactive console. The result is IronTwitter 🙂

While I’m no expert on REST, I understand that you simply ping a URL with a correctly formed URL and process the response in the correct format (xml, json etc).

One of the great things about IronRuby is the REPL, this is the ir.exe console application and allows you to interact with the language and .net at runtime, they are very simple – type a line, hit enter and the line is executed.  They are great for executing quick lines of code, or learning how do a task in the language. I used the REPL a lot while creating the XML parser as I could easily modify the code dynamically to see if something worked as I expected.

Interacting with IronTwitter

Interacting with IronTwitter is very easy. First you need to reference the library.

require ‘IronTwitter’

You then need to construct the object, providing your username and password

@twitter = IronTwitter.new ‘username’, ‘password’

The IronTwitter object has a method called update which has a parameter for your new status. Under the covers, it calls the API and updates your status. However, in order to make this easier to type, I added an alias for the method called t. To update your status, you simply type.

@twitter.t “Hello from IronTwitter!”

This will send a request to ‘http://twitter.com/statuses/update.xml?status=Hello from IronTwitter!’ and your twitter status will be updated.

We can now start taking advantage of IronRuby and we can start constructing tweets dynamically!  For example, if we had a method which counted all the files and directories, we could tweet the result.

def count(dir)
   num = 1
   Dir[dir + ‘/*’].each do |d|
     if File.file? d
       num = num + 1
     else
       num = num + count(d)
     end
   end
   return num
end

All we would need to do is call the method and join the response onto the string argument for the method.

twitter.t ‘The number of files currently in %TEMP% is ‘ + count(‘C:/Users/BENHAL~1/AppData/Local/Temp’).to_s

While this isn’t the most interesting tweet, it’s an interesting concept. You can see my various test tweets at http://twitter.com/ben_hall_test, note my main twitter account is http://twitter.com/ben_hall.

image

After being able to send a tweet, I wanted to see how to process the response. The API has a FriendsTimeline method, this will return the timeline you see on your twitter homepage, the tweets of you and the people your following. Using my xml wrapper, when you call the method friends_timeline, you then use a block to process each status, which is a monkey patched XmlElement object from the Xml Parser I created.

>>> @twitter.friends_timeline {|status| puts status.get(‘text’)}
Hello from IronTwitter!
…..

Under the covers of IronTwitter

While that is very interesting, what happens under the covers is more relevant. When dealing with the API, there are two important items, the first is the url, the second is the options. For update, I send a request to ‘statuses/update.xml’ with a parameter status containing my message.

def update(msg)
  url = “
http://twitter.com/statuses/update.xml”
  options = { :status => msg }
  send_request url, options
end
alias :t :update

This is then passed into my send_request method, this uses the WebRequest object from System.Net to send the correctly formatted request.

def send_request(url, options)
  requestUrl = convert url, options
  request = WebRequest.Create(requestUrl)
  request.Method = “POST”;
  request.ContentType=”application/x-www-form-urlencoded”;
  request.ContentLength = 0;
  request.UserAgent = “IronTwitter”
  request.Credentials = NetworkCredential.new(@username, @password)

  @response = request.GetResponse
end

The URL which is requested looks like this. As we use HTTPAuth, your status is updated.

http://twitter.com/statuses/update.xml?status=Hello from IronTwitter!

A similar approach is taken when it comes to the friends timeline.  First, I’ve used an optional parameter so you can define the limit of statuses returned – by default it is 20. The method then takes a block, this is used to process the request.  If a block is not provided, I raise an exception. I then use the Xml Parser I created to start processing the xml response.

def friends_timeline(tweetCount=20, &b) 
  url = “http://twitter.com/statuses/friends_timeline.xml”
  options = { :count => tweetCount }
  send_request url, options

  readStream = System::IO::StreamReader.new(@response.GetResponseStream)
  doc = Document.new(readStream.read_to_end)
  if block_given?
    doc.elements(‘statuses/status’) do |status|
        b.call status
    end
  else
    raise ‘Block required for processing statuses’
  end
end

From the calling code, I simply access the elements on the node and output them to the screen.

twitter.friends_timeline do |status|
      status.node(‘user’) {|u| print u.get(‘name’) }
      print ‘    ‘
      puts status.get(‘text’)
end

The name and the status of the user is then sent to the console, the result being this:

E:IronTwitter>ir sample.rb
Ben Hall    This is a test tweet

Download the code and sample from here. I’ve also uploaded the code to the MSDN Code Gallery

Technorati Tags: ,