<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" version="2.0">
  <channel>
    <title>Dot Net What Not - Silverlight</title>
    <link>http://dotnetwhatnot.pixata.co.uk/</link>
    <description>My rambling thoughts on exploring the .NET framework and related technologies</description>
    <language>en-gb</language>
    <copyright>AY Silver</copyright>
    <lastBuildDate>Thu, 28 Jul 2011 19:55:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>dasblog@example.com</managingEditor>
    <webMaster>dasblog@example.com</webMaster>
    <item>
      <trackback:ping>http://dotnetwhatnot.pixata.co.uk/Trackback.aspx?guid=a016b44d-2ea0-4ee0-b9f0-91372bd18f6d</trackback:ping>
      <pingback:server>http://dotnetwhatnot.pixata.co.uk/pingback.aspx</pingback:server>
      <pingback:target>http://dotnetwhatnot.pixata.co.uk/PermaLink,guid,a016b44d-2ea0-4ee0-b9f0-91372bd18f6d.aspx</pingback:target>
      <dc:creator>AY Silver</dc:creator>
      <wfw:comment>http://dotnetwhatnot.pixata.co.uk/CommentView,guid,a016b44d-2ea0-4ee0-b9f0-91372bd18f6d.aspx</wfw:comment>
      <wfw:commentRss>http://dotnetwhatnot.pixata.co.uk/SyndicationService.asmx/GetEntryCommentsRss?guid=a016b44d-2ea0-4ee0-b9f0-91372bd18f6d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you’ve read my recent diatribes, you will be relived to know that this will be
a very short post! It wasn’t going to be, but thankfully all the problems I was going
to describe have been solved very simply.
</p>
        <p>
Whilst tinkering around with my first Lightswitch application, I wanted to move some
code into a separate class library, so it could be reused around the application.
Naively, I added a C'# class library to the solution, moved the code over and then
couldn’t add a reference to it from my Lightswitch project.
</p>
        <p>
Whilst wondering what was going on, it dawned on me that Lightswitch is really just
Silverlight underneath, so needs a Silverlight class library, not a normal .NET class
library. I deleted the one I had just created, and added a new Silverlight C# class
library. This time, I was able to add a reference and use the code from my Lightswitch
application. Phew, one problem solved.
</p>
        <p>
I then decided to write some unit tests for the class. That’s where I ran into the
next problem. Normally, I just right-click a method, and choose “Create unit tests”
from the context menu. Trouble was, there wasn’t a “Create unit tests” option there.
</p>
        <p>
I spent rather longer than I should trying to work out how to do this, and failed.
I even tried adding my own project and making into a test project, but that failed
as I couldn’t add references to the appropriate test libraries. This is one of those
occasions when you really wonder why Microsoft split Silverlight off from the rest
of the .NET framework.
</p>
        <p>
Anyway, the good news is that I just discovered that if you install the <a title="Click here to go to the Silverlight Toolkit April 2010 home page" href="http://silverlight.codeplex.com/releases/view/43528" rel="nofollow" target="_blank">Silverlight
Toolkit April 2010</a>, you get new Visual Studio templates for unit testing Silverlight
applications. They don’t work in quite the same way as normal unit tests, in that
the tests themselves run in a Silverlight web application, but the basic principles
are the same. You can even use the same code, and the same test attributes as you
do in your normal tests.
</p>
        <p>
Apparently, you can even test the UI with this framework, but I haven’t tried that.
Needless to say, the fact that I could test my class library was enough to make me
happy, and keep this blog post a lot shorter than it would have been - although it’s
still a lot longer than it should have been, given the actual amount of useful information
it contained! I must learn to be more concise.
</p>
        <img width="0" height="0" src="http://dotnetwhatnot.pixata.co.uk/aggbug.ashx?id=a016b44d-2ea0-4ee0-b9f0-91372bd18f6d" />
      </body>
      <title>Unit testing a Lightswitch application</title>
      <guid isPermaLink="false">http://dotnetwhatnot.pixata.co.uk/PermaLink,guid,a016b44d-2ea0-4ee0-b9f0-91372bd18f6d.aspx</guid>
      <link>http://dotnetwhatnot.pixata.co.uk/2011/07/28/UnitTestingALightswitchApplication.aspx</link>
      <pubDate>Thu, 28 Jul 2011 19:55:00 GMT</pubDate>
      <description>&lt;p&gt;
If you’ve read my recent diatribes, you will be relived to know that this will be
a very short post! It wasn’t going to be, but thankfully all the problems I was going
to describe have been solved very simply.
&lt;/p&gt;
&lt;p&gt;
Whilst tinkering around with my first Lightswitch application, I wanted to move some
code into a separate class library, so it could be reused around the application.
Naively, I added a C'# class library to the solution, moved the code over and then
couldn’t add a reference to it from my Lightswitch project.
&lt;/p&gt;
&lt;p&gt;
Whilst wondering what was going on, it dawned on me that Lightswitch is really just
Silverlight underneath, so needs a Silverlight class library, not a normal .NET class
library. I deleted the one I had just created, and added a new Silverlight C# class
library. This time, I was able to add a reference and use the code from my Lightswitch
application. Phew, one problem solved.
&lt;/p&gt;
&lt;p&gt;
I then decided to write some unit tests for the class. That’s where I ran into the
next problem. Normally, I just right-click a method, and choose “Create unit tests”
from the context menu. Trouble was, there wasn’t a “Create unit tests” option there.
&lt;/p&gt;
&lt;p&gt;
I spent rather longer than I should trying to work out how to do this, and failed.
I even tried adding my own project and making into a test project, but that failed
as I couldn’t add references to the appropriate test libraries. This is one of those
occasions when you really wonder why Microsoft split Silverlight off from the rest
of the .NET framework.
&lt;/p&gt;
&lt;p&gt;
Anyway, the good news is that I just discovered that if you install the &lt;a title="Click here to go to the Silverlight Toolkit April 2010 home page" href="http://silverlight.codeplex.com/releases/view/43528" rel="nofollow" target="_blank"&gt;Silverlight
Toolkit April 2010&lt;/a&gt;, you get new Visual Studio templates for unit testing Silverlight
applications. They don’t work in quite the same way as normal unit tests, in that
the tests themselves run in a Silverlight web application, but the basic principles
are the same. You can even use the same code, and the same test attributes as you
do in your normal tests.
&lt;/p&gt;
&lt;p&gt;
Apparently, you can even test the UI with this framework, but I haven’t tried that.
Needless to say, the fact that I could test my class library was enough to make me
happy, and keep this blog post a lot shorter than it would have been - although it’s
still a lot longer than it should have been, given the actual amount of useful information
it contained! I must learn to be more concise.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://dotnetwhatnot.pixata.co.uk/aggbug.ashx?id=a016b44d-2ea0-4ee0-b9f0-91372bd18f6d" /&gt;</description>
      <comments>http://dotnetwhatnot.pixata.co.uk/CommentView,guid,a016b44d-2ea0-4ee0-b9f0-91372bd18f6d.aspx</comments>
      <category>LightSwitch</category>
      <category>Silverlight</category>
      <category>Unit testing</category>
    </item>
  </channel>
</rss>