<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>The Agileer</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/agileer/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/agileer/feed.xml</link>
    <description>Doug Seelinger&amp;#039;s blog</description>
    <lastBuildDate>Tue, 18 Jul 2017 16:25:27 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Polyglot Programmer</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/polyglot-programmer</link>
      <pubDate>Mon, 17 Jul 2017 16:48:25 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/?p=1285</guid>
      <description><![CDATA[I've been on a something of a language kick lately.

Here is, in no order that I can articulate, a...]]></description>
      <content:encoded><![CDATA[I've been on a something of a language kick lately.

Here is, in no order that I can articulate, a list of the languages that I'd like to be fluent in:
<ul>
 	<li>Assembly Language</li>
 	<li>C</li>
 	<li>C++</li>
 	<li>Java</li>
 	<li>C#</li>
 	<li>JavaScript</li>
 	<li>TypeScript</li>
 	<li>F#</li>
 	<li>R</li>
 	<li>Go</li>
 	<li>Python</li>
 	<li>Ruby</li>
 	<li>Lisp</li>
</ul>
I've actually coded professionally in the following languages:
<ul>
 	<li>Assembly Language</li>
 	<li>C</li>
 	<li>C++</li>
 	<li>C#</li>
 	<li>JavaScript</li>
 	<li>Visual Basic/VB.NET</li>
 	<li>(edit - and how could I forget the early years of my career with PL/I on the DEC VAX?!? - apparently pretty easily, since it didn't even cross my mind. Suppressed memories, I think.)</li>
</ul>
And of those, I'd say I'm only currently fluent in:
<ul>
 	<li>C#</li>
 	<li>JavaScript (more client-side than Node.js servers)</li>
 	<li>VB.NET (though this one's fading fast)</li>
</ul>
And finally, those others that I can go beyond a simple Hello World program are:
<ul>
 	<li>TypeScript</li>
 	<li>Python</li>
 	<li>F#</li>
</ul>
...but not by much.

You may have noticed that I left Visual Basic/VB.NET off the list of "languages I'd like to be fluent in". Also, I'm not including things like Bash, PowerShell, Gulp, Grunt, etc.

So part of this might be an attempt to recapture my mis-spent youth. Nostalgia? Perhaps. Pride? Maybe, but like I said, my current list of fluent languages is pretty small for going into my 30th year of professional software development. Part of that is the nature of my work. Since about 1996 I've been very Microsoft-centric, actually joining Microsoft in 2008.  So for most of that time, venturing out of the MS-space has been frowned upon by the powers-that-be, though attitudes are definitely changing in the past few years.

My major in college was Computer Science, not Management of Information Systems, or IT, or anything like that. As such, I've always wanted to go through the <a href="https://en.wikipedia.org/wiki/The_Art_of_Computer_Programming">The Art of Computer Programming (TAOCP) </a>and work the programs that demonstrate the algorithms, if not the math itself. I still suck at math, but I'm still trying to learn.

As I started to go through TAOCP, I found that it uses a made-up version of assembler. Now I haven't coded assembler since probably my first job on a DEC VAX, and nothing extensive since my Operating Systems class in my junior year at college, in which we built and demonstrated a (somewhat) complete operating system on a PDP-11 - probably the last time I was able to effectively pull an all-nighter, by the way.

That OS class "squeezed" people, and I'm convinced that was its purpose - to see if this was really what we wanted to do with our lives. I loved it. But when you get squeezed, like an orange, the real you comes out! One night I saw this very quiet guy, who always seemed to understand what was going on in class, and he was debugging his OS on the PDP-11 and 3/4 through the night he slams both fists down on the keyboard, causing about 5-6 keys to go flying through the air (don't worry - they went back on, likely loosened by years of such tantrums). Ah, the memories.

So, assembly language. It's been years, and I've never tried it on an "IBM PC", as a lot of the old assembly language sites I've been perusing still seem to call it. It's been interesting just getting started. It also makes you appreciate where languages have gone in the past 30-40 years. But it's also fun. I'll try to keep you posted on my progress. My real goal is to do each of the algorithms in ALL of the exercises in TAOCP - likely a lifelong project at this point.

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>To mock or not to mock, that is the question! (or, when to use dependency injection)</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/to-mock-or-not-to-mock-that-is-the-question-or-when-to-use-dependency-injection</link>
      <pubDate>Mon, 10 Jul 2017 18:15:42 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/?p=1266</guid>
      <description><![CDATA[When unit testing, I often use the terms "mocking" and "dependency injection" interchangeably. Now,...]]></description>
      <content:encoded><![CDATA[When unit testing, I often use the terms "<a href="https://wiki.c2.com/?MockObject">mocking</a>" and "<a href="https://martinfowler.com/articles/injection.html">dependency injection</a>" interchangeably. Now, I know that they are different, however, given that a mock object assumes some sort of dependency injection is involved, I hope you'll forgive me. However, dependency injection without mocking implies that you're not unit testing, <a href="https://blogs.msdn.microsoft.com/agileer/2017/06/23/why-are-we-still-not-unit-testing/">and that's just plain wrong</a>.

Also, if we're stuck with a static typing language and testing with a class that can't be easily mocked (no interface or super-class to grab onto for mocking purposes), we could actually be talking about a testing isolation framework, where we are able to present substitute objects for those objects that can't normally be mocked, usually via some code-injection technique (like <a href="https://www.typemock.com/">TypeMock </a>or <a href="https://msdn.microsoft.com/en-us/library/hh549176.aspx">Microsoft Fakes Shims</a>), and still loosely refer to that as mocking.

So when testing, when do we choose to mock (either classic mock/stub or isolation) and when should we leave well enough alone to avoid mucking up both the test and production design?

Let's take a classic object-oriented example, such as with a "Car" object. A car object might have an engine object, an electrical system object, wheel objects, among others. In the simple case, we'd want to leave the object graph alone and not introduce a bunch of dependency injection and mock objects in the tests. By "simple case", we mean that there is no need to have special classes that represent a carbon fuel engine, another class to represent an electric engine, and yet another class that might represent a "hybrid" engine, which might all represented by an IEngine interface (in the case of C#). By the way, if there's no immediate requirement for such an IEngine interface, but you think it might be useful in the future, just hold on, hombre - You aren't gonna need it (<a href="https://www.martinfowler.com/bliki/Yagni.html">YAGNI</a>). Don't add code unless it's an absolute requirement, and make it as simple as possible.

So in the case of a simple Car object and a simple Engine object, just skip the dependency injection and mocking the engine. Introducing dependency injection is not "as simple as possible", but rather, it introduces additional complexity.

"But, but, but... who's going to create the Engine object?" you might ask in a querulous voice. Simple (see what I did there?), let the Car create the engine.

(Gasp!)(sputter!) "But that's agile and object oriented blasphemy!" Meh... not so much. Remember, this is just a simple set of objects, which is how it should always start out anyways. Until dependency injection is an actual requirement (and one that's not simply in your own mind), You Aren't Gonna Need It!

So in the case of simple component objects, let the composite object construct its own simple component objects. Your code and tests should become much simpler.

You say, "But then I 'm not isolating my unit tests to a single object! How will I know where something breaks?" Well, given that you're practicing <a href="https://www.amazon.com/gp/product/0321146530?ie=UTF8&amp;tag=martinfowlerc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321146530">TDD</a> (and you are, aren't you), then you'll know that the problem was with the last few lines of code you just wrote, right?

"So, then perhaps it is better to not mock at all," you may well say. But let's not throw out the baby with the bathwater, as the saying goes. There are plenty of situations where dependency injection and mock objects are useful, such as in the case of a true interface requirement, where multiple implementations to fulfill a particular contract (interface) are required, or when crossing process boundaries, thus causing side-effects from your unit tests (a big no-no) and making your unit tests run slowly, which can be a drag in itself.

Bottom line, if you're introducing an interface for no other reason other than <span style="text-decoration: underline">it's what you always do when you're testing</span>, then please reconsider. Is there a way to simplify your design such that it doesn't require mocks? But if you're:
<ul>
 	<li>working with interfaces for more than just testing reasons,</li>
 	<li>or your component objects cross process boundaries,</li>
 	<li>or calls against your component have are not idempotent (likely using a shim)</li>
</ul>
...then by all means, use dependency injection or a shim.]]></content:encoded>
    </item>
    <item>
      <title>How to unit test the Bot Framework</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/how-to-unit-test-the-bot-framework</link>
      <pubDate>Mon, 26 Jun 2017 14:36:45 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/?p=1255</guid>
      <description><![CDATA[Today, let's test the Microsoft Bot Framework.

One of the first things I like to do when...]]></description>
      <content:encoded><![CDATA[Today, let's test the <a href="https://dev.botframework.com/">Microsoft Bot Framework</a>.

One of the first things I like to do when attempting to grasp a new framework (well, new to me) is to attempt to unit test the "Hello world" version of the framework. This can give a vague level of complexity to the overall framework, or at least the most basic version to get started, and is just a good exercise overall, I believe. You <em><span style="text-decoration: underline"><strong>are</strong></span></em>, after all, <a href="https://blogs.msdn.microsoft.com/agileer/2017/06/23/why-are-we-still-not-unit-testing/">unit testing your code</a>, aren't you?

In today's exercise, we'll be unit testing the <strong>RootDialog</strong> object, and in particular, just the <strong>MessageReceivedAsync</strong> method,  as it comes straight from the default template in Visual Studio. This should give us a flavor of the testability of the <a href="https://dev.botframework.com/">Microsoft Bot Framework</a> overall. I'll be using v3.8.2, which is the latest version as of this writing. The Bot Framework was a little more complex than some to get started unit testing with, which made it an interesting challenge. As usual, mocking the right objects was the challenge. In unit testing, the easiest solution would be if there was no need to mock anything at all, just instantiate objects as would happen in the end to end application and be on your way. However, the Bot Framework, is heavily littered with interfaces, and I was not able to find concrete implementations of those interfaces with which to easily test (more about this later). So mocking it is - or so I thought at first.

The one good thing about a plethora of interfaces in a .NET library is that you have the feeling that it was built with testability in mind, or at least you hope so. There are, of course, other reasons to use interfaces, but the trend over the last ten years or so has been that we should be able to "mock all dependent objects" in our tests. This goes a bit overboard in my opinion, and tends to clutter our tests with (perhaps) unnecessary "plumbing code". If a dependent object is pretty simple and doesn't cross any process boundaries (i.e. it wouldn't make the test slow to a relative crawl), then just instantiate the dependent object and complete your test as quickly and simply as possible. I find the idea of this akin to when we first learned about database normalization - we immediately attempted to normalize our databases to the nth degree (literally) until we realized that it made querying them a slow process, and then learned to judiciously de-normalize the data to improve query performance. So it goes with mocking - the better we initially learned our mocking lessons, the more we intertwined our tests with mocks everywhere, to the detriment of the maintainability of our test code. The moral of  this story is, "Don't just automatically mock-all-the-things."

However, with the Bot Framework, it appeared that we would be mocking pretty much every dependent object and parameter - interfaces everywhere:

[csharp]
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;

namespace MisthavenBot.Dialogs
{
    [Serializable]
    public class RootDialog : IDialog&lt;object&gt;;
    {
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);
            return Task.CompletedTask;
        }

        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable&lt;object&gt; result)
        {
            var message = await result as Activity;

            int length = (message.Text ?? string.Empty).Length;

            await context.PostAsync($&quot;You sent {message.Text} which was {length} characters&quot;);

            context.Wait(MessageReceivedAsync);
        }
    }
}
[/csharp]

I initially chose <a href="https://github.com/Moq/moq4">Moq</a> as my mocking framework because, well, I just like Moq. It takes a lot of the heavy lifting out of mocking and you can write more concise mocking code with it than others I've worked with. However, I quickly ran into a problem. I was having a problem mocking <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.dialogs.extensions.postasync?view=botbuilder-3.8"><strong>IDialogContext.PostAsync</strong></a>. After a frustratingly long amount of time, I came to realize that that method was actually an extension method (Remember, Doug, 'F1' is your friend). As you may or may not know, <a href="https://stackoverflow.com/questions/2295960/mocking-extension-methods-with-moq#_=_">you can't simply mock an extension method</a>. I'm not aware of any particular reason that it needs to be an extension method. The Bot Framework team owns both the <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.dialogs.idialogcontext?view=botbuilder-3.8"><strong>IDialogContext</strong></a> interface (and presumably any of the standard implementers of this interface) and the extension code that includes <strong>PostAsync</strong>. Why not then merge the two and have a more testable result? Perhaps the thought was to have a clever way to give an interface actual implementation code for any derived class? That's what an extension method with an interface for the "this" object actually achieves. Then why not use an abstract class? Perhaps the answer to that is that the Bot Framework likes to use interfaces so much that it uses multiple interfaces per object - for interfaces themselves, even. For example, <strong>IDialogContext</strong> implements both <strong>IBotToUser</strong> and <strong>IDialogStack</strong>. It's a legitimate design. Since .NET does not support multiple inheritance, such ends are similarly achieved via multiple interfaces.

"But wait," you say. "The nice API docs say that <strong>IDialogContext</strong> is realized in the concrete <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.dialogs.internals.dialogcontext?view=botbuilder-3.8"><strong>DialogContext</strong></a> object. Why not just use that?"

That's true. But the <strong>DialogContext</strong> constructor takes an <strong>IBotToUser</strong> object, an <strong>IBotData</strong> object, an <strong>IDialogStack</strong> object, an <strong>IActivity</strong> object, and a <strong>CancellationToken</strong>.

"Well, is that insurmountable?" you ask.

Let's look at a reasonable implementation for the first object, <strong>IBotToUser</strong>, which to me is <strong>BotToUserTextWriter</strong>. The constructor for that takes another <strong>IBotToUser</strong> and a <strong>TextWriter</strong> object. Things are getting recursively difficult and it's time to cut bait and mock.

But as I said, extension methods can't be mocked. So what are we to do? We "mock" the impossible with the <a href="https://msdn.microsoft.com/en-us/library/hh549175.aspx">Microsoft Fakes Framework</a>. In particular, we'll be using a combination of Stubs, for the things that CAN be mocked, with Shims, for the things that normally could not be mocked. Thus, our successful first test of our <strong>RootDialog</strong> object now looks like:

[csharp]
using Microsoft.Bot.Builder.Dialogs.Fakes;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Builder.Internals.Fibers.Fakes;
using Microsoft.Bot.Connector;
using Microsoft.QualityTools.Testing.Fakes;
using MisthavenBot.Dialogs;
using System.Threading.Tasks;
using Xunit;

namespace MisthavenBot.Tests
{
    public class RootDialogTests
    {
        string _actualText = null;

        [Fact]
        public async Task It_should_start_with_the_initial_text()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var it = new RootDialog();
                StubIDialogContext fakeContext = FakeTheContext();
                StubIAwaitable&lt;object&gt; fakeWaitable = FakeTheWaitable();

                // Act 
                await it.MessageReceivedAsync(fakeContext, fakeWaitable);

                // Assert
                Assert.Equal(&quot;You sent Message from User which was 17 characters&quot;, _actualText);
            }
        }

        private StubIDialogContext FakeTheContext()
        {
            var fakeContext = new StubIDialogContext();
            Microsoft.Bot.Builder.Dialogs.Fakes.ShimExtensions.PostAsyncIBotToUserStringStringCancellationToken =
                (botToUser, text, locale, cancellationToken) =&gt;
                {
                    _actualText = text;
                    return Task.CompletedTask;
                };
            return fakeContext;
        }

        private static StubIAwaitable&lt;object&gt; FakeTheWaitable()
        {
            var fakeWaiter = new StubIAwaiter&lt;object&gt;
            {
                GetResult = () =&gt; new Activity { Text = &quot;Message from User&quot; },
                IsCompletedGet = () =&gt; true
            };

            var fakeWaitable = new StubIAwaitable&lt;object&gt;
            {
                GetAwaiter = () =&gt; fakeWaiter
            };
            return fakeWaitable;
        }
    }
}

[/csharp]

This is far from simple for a "Hello World" level example, but it does get the job done.

Note that the use of Shims from the Microsoft Fakes framework means that we won't be able to use <a href="https://blogs.msdn.microsoft.com/visualstudio/2017/03/09/live-unit-testing-in-visual-studio-2017-enterprise/">Visual Studio 2017 Live Unit Testing</a>. Most likely the injected code from the Shim is more than Live Unit Testing can currently handle (<a href="https://developercommunity.visualstudio.com/content/problem/10436/living-unittesting-fails-when-creating-a-microsoft.html">see here</a> for more info). Interestingly enough, it appears that <a href="https://blog.ncrunch.net/post/NCrunch-V2-Beta-Is-Now-Available!.aspx">NCrunch has solved this problem</a>.]]></content:encoded>
    </item>
    <item>
      <title>Why are we still not unit testing?</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/why-are-we-still-not-unit-testing</link>
      <pubDate>Fri, 23 Jun 2017 21:24:41 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/?p=1245</guid>
      <description><![CDATA[Unit testing. At least unit testing.

I thought this was a solved problem, people. Agile has come...]]></description>
      <content:encoded><![CDATA[Unit testing. At <em>least<strong> </strong></em><span style="text-decoration: underline"></span>unit testing.

I thought this was a solved problem, people. Agile has come out of the shadows and dominated the techie buzzword machine for years now. Everyone is doing Scrum now, right?

Well, OK, they're usually doing "ScrumBut". "We're doing Scrum, but we're not demoing our software to the customer." Or, "We're doing Scrum, BUT we're not doing the team code ownership thing." Usually, it just means that some of the team gathers on a semi-regular basis to do a "standup". But that's a rant for another time.

Unit testing. Why are we still not writing tests? I was invited by a US state a couple years ago to review some software for which they were getting ready to shell out a substantial sum of money. They wanted to know if the code was worth the dough. They owned the code - but there was not a single unit test in all of the 200K+ lines of code for the product. When we presented our findings, the lack of tests, which could assure the customer that the code was executing according to the requirements, was a primary factor in their rejection of the product.

Another customer asked us to assist them in migrating several dozen apps from on-premises to Azure. We went through dozens of interviews and not one of those apps had unit testing. Each interview sounded the same type of refrain,  "We're going to start testing soon."  "That's something we're working on."  "We know that we haven't done the best job with testing." If they are to take advantage of the DevOps scenarios we're proposing, they'll need to be assured that their software is performing the way they think it should be (eg. it's tested) before they can even consider DevOps.

We all see the benefits of testing, right? Are we lazy? Are we pressured by management to "just build features" and "no time for testing"? Unless you just don't care if your code works, that's got to cause all sorts of anxiety. Sometimes this happens, though, even at Microsoft Consulting Services. Several months ago I was asked to review one of our projects that was experiencing... "customer dissatisfaction", let's say. No tests. Even at MCS? We have our own Playbook that stresses the importance of testing, and that if testing is not supported by the project or customer, <strong>it is reason to walk away from that customer.</strong>

Got tests? Ah, I can finally sleep at night. Peace. Assurance - and dare I say, "rigor"?

I've been doing this agile thing for about 14 years now. I watch trends, I practice the craft - and doing so has its momentum. I admit, I am not objective when it comes to testing. You better have some major facts behind your assertions (no testing pun intended) that testing is contraindicated for software and they better be easy to see, because I've lived this, like I said, for the past 14 years. I see the benefits. I am comforted by the fact that people maintaining the code I've written over the years - my code, the team's code - can be assured that it's still working, because all they have to do is to run the tests. Green is good.]]></content:encoded>
    </item>
    <item>
      <title>NCrunch + Debug.Print() = Almost a REPL</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/ncrunch-debug-print-almost-a-repl</link>
      <pubDate>Fri, 07 Jun 2013 07:04:00 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/2013/06/07/ncrunch-debug-print-almost-a-repl/</guid>
      <description><![CDATA[I remember back in the mid-90's when I could launch a compile cycle&nbsp;on my C++ program and then...]]></description>
      <content:encoded><![CDATA[<p>I remember back in the mid-90's when I could launch a compile cycle&nbsp;on my C++ program and then go to lunch.&nbsp; It might be done by the time I returned.&nbsp; I'm sure that SOMEWHERE in the world there are still projects like that, but they're definitely not in the mainstream like they used to be.&nbsp; The days of waiting for long compile cycles are over.&nbsp;</p>
<p>In fact, it seems that we don't even have to wait on the compile cycle at all anymore to get feedback on whether the code we just wrote is working.&nbsp; At least not with <a href="https://www.ncrunch.net/">NCrunch</a>.&nbsp; If you haven't discovered NCrunch yet, I'm sorry for you, because it's now my second favorite Visual Studio extension next to <a href="https://www.jetbrains.com/resharper/">ReSharper</a>.&nbsp; NCrunch <em><span style="text-decoration: underline;"><strong>continually</strong></span></em> runs your tests as you type them.&nbsp; No need to even CTRL-SHFT-B, much less CTRL-R,&nbsp;A.&nbsp;This is almost instantaneous feedback on the last character you typed in your code.&nbsp; And it's even smarter than that.&nbsp; Before I had ever used NCrunch I used to think that it simply would save me from having to type CTRL-R, A.&nbsp; Not so.&nbsp; You'll find yourself pondering whether this is almost a new paradigm&nbsp;-&nbsp;this instantaneous feedback.</p>
<p>Of course, you can still write terrible tests and rob yourself of instantaneous feedback.&nbsp; NCrunch <em>can</em> run integration tests, which tend to take longer (not that integration tests are bad, they're essential!), but&nbsp;NCrunch's&nbsp;usefulness is primarily in running your quick unit tests for immediate feedback.&nbsp; So have NCrunch ignore those long-running tests and get instant feedback on success/failure, code coverage, and profile times of your tests.&nbsp; You can un-ignore your long-running tests (or just CTRL-R, A) every once in a while to confirm you haven't broken integration before pushing your changes to your main source control.</p>
<p>NCrunch isn't perfect, and there's plenty of room for stability improvements (or maybe I just don't know how to set it up correctly), but I'd rather have a rocket-ship that I have to get out and kick every once in a while than have a horse and buggy that plods along forever.&nbsp; At some point the "Tortoise and the Hare"&nbsp;analogy breaks down, and the NCrunch bunny definitely breaks the analogy.</p>
<p>Now, on to the true purpose of this post.&nbsp; Because of the instantaneous feedback that NCrunch gives you, you can almost treat it like a <a href="https://en.wikipedia.org/wiki/REPL">REPL</a>.&nbsp; Using this technique I find myself going into the debugger even less than I did after adopting TDD.&nbsp; Not sure what you need to do with a specific class in the Base Class Library?&nbsp; Need to "spike" a test?&nbsp; Try simply putting one or two judicious uses of Debug.Print() and look at the <strong>NCrunch Tests</strong> window. Select your test (you have to select the "checkbox over the eyeball" toolbar button to show passing tests) and in the gray area below you'll see the debug output of your test.&nbsp; Not what you expected?&nbsp; Change your code, try a new method from the object's IntelliSense list - all things that are much harder to do when debugging.&nbsp; You'll get feedback faster and learn faster.</p>
<p>For example, I had some data that I wanted to verify&nbsp;inside of a&nbsp;<a href="https://en.wikipedia.org/wiki/SOAP">SOAP</a> Message response, but I didn't really know what data was in there.&nbsp; To me, it looked like angle brackets and namespaces had exploded everywhere (ah the joys of SOAP). &nbsp;Then I thought of Linq-to-XML.&nbsp; I knew little more about Linq-to-XML than the simple fact that it exists.&nbsp; A quick Bing of some&nbsp;<a title="MSDN overview docs on Linq-toXML" href="https://msdn.microsoft.com/en-us/library/bb387061.aspx">MSDN docs as an overview of Linq-to-XML</a>&nbsp;showed me the basics. So now it's time to experiment.</p>
<p>It was simple.&nbsp; Like I said, just create a test and in the <strong>NCrunch Tests</strong> window, select the test and watch the test output area as you edit the test (notice the current name of the test reflects my ignorance of what I'm wanting to test, not strict TDD, no, but that's what happens when you're "<a href="https://c2.com/cgi/wiki?SpikeSolution">spiking</a>"):</p>
<pre style="background: white; color: black; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: #2b91af;">TestMethod</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">void</span>&nbsp;WhenCtorInvoked_ThenMessageShouldBeUhhhhhhh()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;context&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: #2b91af;">EnumerationContext</span>();
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;sut&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: #2b91af;">PullMessage</span>(context,&nbsp;50);
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;element&nbsp;=&nbsp;sut.Message.GetBody&lt;<span style="color: #2b91af;">XElement</span>&gt;();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2b91af;">Debug</span>.Print(element.ToString());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
</pre>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/23/2018.NCrunchTests.PNG" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-23/2018.NCrunchTests.PNG"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/13/23/2018.NCrunchTests.PNG" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-13-23/2018.NCrunchTests.PNG" alt="" border="0" /></a></p>
<p>Still quite a few angle brackets, but certainly not as bad as the whole SOAP message!</p>
<p>Hope this helps,<br />Doug</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>The CORRECT Way to Code a Custom Exception Class</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/the-correct-way-to-code-a-custom-exception-class</link>
      <pubDate>Fri, 17 May 2013 13:36:00 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/2013/05/17/the-correct-way-to-code-a-custom-exception-class/</guid>
      <description><![CDATA[There is a lot of advice out there on how to go about building your own custom exception...]]></description>
      <content:encoded><![CDATA[<p>There is a lot of advice out there on how to go about building your own custom exception classes.&nbsp; A lot of these sources are at least partially correct. Some are totally wrong.&nbsp; Some even advocate abandoning the base System.Exception class altogether, but that&rsquo;s throwing the baby out with the bathwater, in my opinion.&nbsp; None that I've seen show how to serialize/deserialize your custom exception class should it have additional data in it's subclass. It&rsquo;s enough to make one despair of ever finding the &ldquo;right&rdquo; way to build an exception class.&nbsp;</p>
<p>A lot of the confusion around exceptions comes about if you&rsquo;ve ever actually tried to serialize an exception using an Xml-based serializer.&nbsp; You <em>are </em>testing the code you write, correct? When attempting to serialize your nice new exception class with something like XmlSerializer, the serializer will simply choke, stating that it can&rsquo;t serialize any class that has an IDictionary member.&nbsp; And System.Exception has an IDictionary in it.&nbsp; Yet every piece of literature coming out of Microsoft says that we should build custom exceptions (sub-typed from Exception, and not ApplicationException) and mark them as [Serializable].&nbsp; What gives?&nbsp; Well, there are more serializers in the world than just the XML-based serializers, and that&rsquo;s when it&rsquo;s important to serialize exceptions.&nbsp; The System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, for example,&nbsp;serializes exceptions just fine.</p>
<p>So, how do you derive from Exception correctly, particularly if you&rsquo;ve got additional information in your custom exception class?&nbsp; I thought you&rsquo;d never ask.</p>
<pre style="background: white; color: black; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">Serializable</span>]
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">class</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>&nbsp;:&nbsp;<span style="color: darkblue;">Exception</span>
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">string</span>&nbsp;<span style="color: purple;">ResourceReferenceProperty</span>&nbsp;{&nbsp;<span style="color: darkcyan;">get</span>;&nbsp;<span style="color: darkcyan;">set</span>;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: blue;">string</span>&nbsp;message)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<span style="color: darkblue;">base</span>(message)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: blue;">string</span>&nbsp;message,&nbsp;<span style="color: darkblue;">Exception</span>&nbsp;inner)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<span style="color: darkblue;">base</span>(message,&nbsp;inner)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">protected</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: darkblue;">SerializationInfo</span>&nbsp;info,&nbsp;<span style="color: darkblue;">StreamingContext</span>&nbsp;context)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<span style="color: darkblue;">base</span>(info,&nbsp;context)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: purple;">ResourceReferenceProperty</span>&nbsp;=&nbsp;info.<span style="color: darkcyan;">GetString</span>(<span style="color: #a31515;">"ResourceReferenceProperty"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">SecurityPermission</span>(<span style="color: darkblue;">SecurityAction</span>.<span style="color: purple; font-weight: bold;">Demand</span>,&nbsp;<span style="color: purple;">SerializationFormatter</span>&nbsp;=&nbsp;<span style="color: blue;">true</span>)]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">override</span>&nbsp;<span style="color: blue;">void</span>&nbsp;<span style="color: darkcyan;">GetObjectData</span>(<span style="color: darkblue;">SerializationInfo</span>&nbsp;info,&nbsp;<span style="color: darkblue;">StreamingContext</span>&nbsp;context)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">if</span>&nbsp;(info&nbsp;==&nbsp;<span style="color: blue;">null</span>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">throw</span>&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">ArgumentNullException</span>(<span style="color: #a31515;">"</span><span style="color: #a31515;">info</span><span style="color: #a31515;">"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;info.<span style="color: darkcyan;">AddValue</span>(<span style="color: #a31515;">"ResourceReferenceProperty"</span>,&nbsp;<span style="color: purple;">ResourceReferenceProperty</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">base</span>.<span style="color: darkcyan;">GetObjectData</span>(info,&nbsp;context);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;}
</pre>
<pre>&nbsp;<span style="font-family: arial,helvetica,sans-serif;">&nbsp;And here are the tests that drive it to completion (updated to show better testing methods):</span></pre>
<pre>&nbsp;</pre>
<pre style="background: white; color: black; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">TestClass</span>]
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">class</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredExceptionTests</span>
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">TestMethod</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">void</span>&nbsp;<span style="color: darkcyan;">AuthorizationRequiredException_default_ctor</span>()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Arrange</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">const</span>&nbsp;<span style="color: blue;">string</span>&nbsp;<span style="color: purple; font-weight: bold;">expectedMessage</span>&nbsp;=&nbsp;<span style="color: #a31515;">"Exception&nbsp;of&nbsp;type&nbsp;'MyApp.Exceptions.AuthorizationRequiredException'&nbsp;was&nbsp;thrown."</span>;
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Act</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;sut&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>();
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Assert</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">IsNull</span>(sut.<span style="color: purple;">ResourceReferenceProperty</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">IsNull</span>(sut.<span style="color: purple;">InnerException</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(<span style="color: purple; font-weight: bold;">expectedMessage</span>,&nbsp;sut.<span style="color: purple;">Message</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">TestMethod</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">void</span>&nbsp;<span style="color: darkcyan;">AuthorizationRequiredException_ctor_string</span>()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Arrange</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">const</span>&nbsp;<span style="color: blue;">string</span>&nbsp;<span style="color: purple; font-weight: bold;">expectedMessage</span>&nbsp;=&nbsp;<span style="color: #a31515;">"message"</span>;
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Act</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;sut&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: purple; font-weight: bold;">expectedMessage</span>);
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Assert</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">IsNull</span>(sut.<span style="color: purple;">ResourceReferenceProperty</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">IsNull</span>(sut.<span style="color: purple;">InnerException</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(<span style="color: purple; font-weight: bold;">expectedMessage</span>,&nbsp;sut.<span style="color: purple;">Message</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">TestMethod</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">void</span>&nbsp;<span style="color: darkcyan;">AuthorizationRequiredException_ctor_string_ex</span>()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Arrange</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">const</span>&nbsp;<span style="color: blue;">string</span>&nbsp;<span style="color: purple; font-weight: bold;">expectedMessage</span>&nbsp;=&nbsp;<span style="color: #a31515;">"message"</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;innerEx&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">Exception</span>(<span style="color: #a31515;">"foo"</span>);
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Act</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;sut&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: purple; font-weight: bold;">expectedMessage</span>,&nbsp;innerEx);
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Assert</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">IsNull</span>(sut.<span style="color: purple;">ResourceReferenceProperty</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(innerEx,&nbsp;sut.<span style="color: purple;">InnerException</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(<span style="color: purple; font-weight: bold;">expectedMessage</span>,&nbsp;sut.<span style="color: purple;">Message</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">TestMethod</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">void</span>&nbsp;<span style="color: darkcyan;">AuthorizationRequiredException_serialization_deserialization_test</span>()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Arrange</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;innerEx&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">Exception</span>(<span style="color: #a31515;">"foo"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;originalException&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: #a31515;">"message"</span>,&nbsp;innerEx)&nbsp;{&nbsp;<span style="color: purple;">ResourceReferenceProperty</span>&nbsp;=&nbsp;<span style="color: #a31515;">"MyReferenceProperty"</span>&nbsp;};
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;buffer&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: blue;">byte</span>[4096];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;ms&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">MemoryStream</span>(buffer);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;ms2&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">MemoryStream</span>(buffer);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;formatter&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">BinaryFormatter</span>();
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Act</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;formatter.<span style="color: darkcyan;">Serialize</span>(ms,&nbsp;originalException);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;deserializedException&nbsp;=&nbsp;(<span style="color: darkblue;">AuthorizationRequiredException</span>)formatter.<span style="color: darkcyan;">Deserialize</span>(ms2);
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Assert</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(originalException.<span style="color: purple;">ResourceReferenceProperty</span>,&nbsp;deserializedException.<span style="color: purple;">ResourceReferenceProperty</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(originalException.<span style="color: purple;">InnerException</span>.<span style="color: purple;">Message</span>,&nbsp;deserializedException.<span style="color: purple;">InnerException</span>.<span style="color: purple;">Message</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: darkblue;">Assert</span>.<span style="color: darkcyan;">AreEqual</span>(originalException.<span style="color: purple;">Message</span>,&nbsp;deserializedException.<span style="color: purple;">Message</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">TestMethod</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: darkblue;">ExpectedException</span>(<span style="color: blue;">typeof</span>(<span style="color: darkblue;">ArgumentNullException</span>))]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">void</span>&nbsp;<span style="color: darkcyan;">AuthorizationRequiredException_GetObjectData_throws_exception_when_info_null</span>()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Arrange</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">var</span>&nbsp;sut&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">AuthorizationRequiredException</span>(<span style="color: #a31515;">"message"</span>)&nbsp;{&nbsp;<span style="color: purple;">ResourceReferenceProperty</span>&nbsp;=&nbsp;<span style="color: #a31515;">"MyReferenceProperty"</span>&nbsp;};
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Act</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;ReSharper&nbsp;disable&nbsp;AssignNullToNotNullAttribute</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sut.<span style="color: darkcyan;">GetObjectData</span>(<span style="color: blue;">null</span>,&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: darkblue;">StreamingContext</span>());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;ReSharper&nbsp;restore&nbsp;AssignNullToNotNullAttribute</span>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;Assert</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green;">//&nbsp;[ExpectedException(typeof(ArgumentNullException))]</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
</pre>
<pre>&nbsp;</pre>
<p>If you use this code as a template for creating your custom exceptions, you won&rsquo;t go too far wrong, I think.</p>
<p>As far as XML-based serializers goes, I hope that the Base Class Library team will take some time and just fix the "chokes on IDictionary" issue.&nbsp; Frankly, it's quite embarrassing.</p>]]></content:encoded>
    </item>
    <item>
      <title>Starting Up with Windows Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/starting-up-with-windows-azure</link>
      <pubDate>Thu, 30 Aug 2012 09:03:57 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/2012/08/30/starting-up-with-windows-azure/</guid>
      <description><![CDATA[I'm not new to Windows Azure, but I would definitely like to learn more.&#160; Really, the landscape...]]></description>
      <content:encoded><![CDATA[<p>I'm not new to Windows Azure, but I would definitely like to learn more.&#160; Really, the landscape has changed a lot in the last year or so, making &quot;knowing Azure&quot; about as complex as &quot;knowing Microsoft&quot; was about 10-15 years ago. Let's start off with some definitions.</p>  <h1>X as a Service</h1>  <p>&quot;Software as a Service&quot; (SaaS), &quot;Platform as a Service&quot; (PaaS), &quot;Infrastructure as a Service&quot; (IaaS); the computing world is absolutely going the way of subscription &quot;services&quot; - the cloud.&#160; So what does Windows Azure offer?&#160; Well, if you count Office 365, all of them.&#160; If not, then it offers both PaaS and IaaS, with IaaS receiving the most press, recently, as it fills a gap in more easily allowing &quot;Private Cloud&quot; users to migrate to the &quot;Public Cloud&quot; </p>  <h1>How Do I Start?</h1>  <p>Well, first you'll need a Windows Azure subscription.&#160; At the time of this writing, you can get a free 90-day subscription at <a href="https://www.windowsazure.com/">https://www.windowsazure.com/</a></p>  <p>Next, you'll need something to deploy software to Windows Azure with.&#160; The easiest to get started with is Visual Studio 2012 at <a title="Visual Studio 2012" href="https://www.microsoft.com/visualstudio/en-us">https://www.microsoft.com/visualstudio/en-us</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>How to Stop Mercurial from Complaining about SSL Cert Fingerprints</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/how-to-stop-mercurial-from-complaining-about-ssl-cert-fingerprints</link>
      <pubDate>Fri, 04 May 2012 07:00:54 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/2012/05/04/how-to-stop-mercurial-from-complaining-about-ssl-cert-fingerprints/</guid>
      <description><![CDATA[I know Mercurial is just trying to be friendly and warn me that it doesn’t know if certain SSL certs...]]></description>
      <content:encoded><![CDATA[<p>I know Mercurial is just trying to be friendly and warn me that it doesn’t know if certain SSL certs are valid or not (though I wish they’d just use the Windows cert repository when on the Microsoft platform), but the little nag warnings like…</p>  <p><font face="Courier New">“warning: hg.codeplex.com certificate with fingerprint 1c:ef:1d:4f:55:57:5b:8c:ab:78:a1:72:2c:d2:1b:56:fd:64:03:19 not verified (check hostfingerprints or web.cacerts config setting)”</font></p>  <p>…are a bit monotonous.</p>  <p>And they’re probably supposed to be.&#160; However, it is pretty simple to get rid of such warnings.&#160; All you need to do is edit your mercurial.ini file.&#160; On Windows 7, this can be found at C:\users\[your account]\mercurial.ini.&#160; Or, if you’re using TortoiseHg, Open “Files | Settings” and click the “Edit File” button in the upper right corner.&#160; Then you just add the following two lines to that file:</p>  <p><font face="Courier New">[hostfingerprints]     <br />hg.codeplex.com = 1c:ef:1d:4f:55:57:5b:8c:ab:78:a1:72:2c:d2:1b:56:fd:64:03:19</font></p>  <p>Of course, this example assumes you’re referencing the CodePlex repository.&#160; All the data you need to add to the mercurial.ini file can be found in the warning message you get (bitbucket, etc.)</p>]]></content:encoded>
    </item>
    <item>
      <title>AutoFakes Is Now Live at CodePlex</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/autofakes-is-now-live-at-codeplex</link>
      <pubDate>Wed, 21 Mar 2012 16:29:00 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/2012/03/21/autofakes-is-now-live-at-codeplex/</guid>
      <description><![CDATA[After many years of just talk, I&rsquo;ve finally released my first Open Source Software project at...]]></description>
      <content:encoded><![CDATA[<p>After many years of just talk, I&rsquo;ve finally released my first Open Source Software project at CodePlex, called <a href="https://autofakes.codeplex.com/">AutoFakes</a>.&nbsp; It&rsquo;s meant for Visual Studio 11, though I suppose it would probably work in VS 10 if you have Pex/Moles installed, but definitely haven&rsquo;t tested THAT.</p>
<p>Basically, it&rsquo;s like an auto-mocking container (minus the container &ndash; there is no dependence on any IoC container).&nbsp;</p>
<p>Let&rsquo;s say you&rsquo;re doing TDD and have a class that you&rsquo;re building tests for.&nbsp; Of course, that class is being modified over time &ndash; maybe it receives new dependencies, it changes dependencies, or even has some dependencies refactored out.&nbsp; I&rsquo;ve been there and when this happens, I have to go through ALL my unit tests for the class and build new mocks for the dependencies and modify the code that instantiates your code under test.&nbsp; Not fun when you have dozens of tests for a particular class (this assumes you&rsquo;re not using a SetUp type method, which you can&rsquo;t do anyway in the case of XUnit.net).</p>
<p>What would be really cool is if there was a way to automatically construct the class you&rsquo;re testing with all mock dependencies &ndash; let the framework figure out what those dependencies are and just build the class itself without the manual work of figuring out dependencies and mocking each one.&nbsp; Well, there actually are plenty of those out there already &ndash; that is, for actual mocking frameworks like <a href="https://ayende.com/blog/tags/rhino-mocks">RhinoMocks</a>, <a href="https://code.google.com/p/moq/">Moq</a>, etc.&nbsp; The problem is that Visual Studio 11 has a cool, new mocking and isolation framework called Fakes, and there's no existing "auto mocking" type behavior out in the Internets for this new framework, yet.&nbsp; Peter Provost talks about a lot of the new VS11 unit testing features, including Fakes, <a href="https://blogs.msdn.com/b/visualstudioalm/archive/2012/03/08/what-s-new-in-visual-studio-11-beta-unit-testing.aspx">here</a>.&nbsp; There is also pretty good documentation for Fakes (at least for beta software) <a href="https://aka.ms/vs11-fakes">at MSDN</a>.</p>
<p>Given that you understand what using the Fakes Framework is like, you could create a test method something like following example:</p>
<pre>        [TestMethod]
        public void ConnectorManagerCanGetConnectors()
        {
            // Arrange
            // ConnectorManager has a dependency - IConnectorRepository
            var autofake = new AutoFake&lt;ConnectorManager&gt;();
            var stubConnector = new StubIConnector();
            autofake.Get&lt;StubIConnectorRepository&gt;().GetConnectorsString =
                filter =&gt;
                {
                    return new List&lt;IConnector&gt; {stubConnector, stubConnector};
                };


            // Act
            IList&lt;IConnector&gt; result = autofake.Target.GetConnectors("filter");

            // Assert
            Assert.AreEqual(2, result.Count);
        }</pre>
<p>Later, if my "ConnectorManager" gains or loses additional dependencies, I don't necessarily&nbsp;have to come back to this test and modify it in any way - AutoFakes will detect the new dependency (an interface or abstract class, right now) and construct the class under test correctly.</p>
<p>If you have suggestions for additions to the framework (AutoFakes, not the general Visual Studio Fakes Framework), go to the AutoFakes <a href="https://autofakes.codeplex.com/discussions">Discussion</a> or <a href="https://autofakes.codeplex.com/workitem/list/basic">Issue Tracker</a>, or just add a comment to this blog post.&nbsp; I&rsquo;ll make sure the request gets put into the appropriate area.</p>]]></content:encoded>
    </item>
    <item>
      <title>Why Won’t My Custom Cmdlets Appear?</title>
      <link>https://docs.microsoft.com/archive/blogs/agileer/why-wont-my-custom-cmdlets-appear</link>
      <pubDate>Tue, 21 Feb 2012 11:03:06 GMT</pubDate>
      <dc:creator><![CDATA[Doug Seelinger]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/agileer/2012/02/21/why-wont-my-custom-cmdlets-appear/</guid>
      <description><![CDATA[Once again, I’ve been puzzled multiple times as to why my custom cmdlets sometimes don’t appear in...]]></description>
      <content:encoded><![CDATA[<p>Once again, I’ve been puzzled multiple times as to why my custom cmdlets sometimes don’t appear in PowerShell after I’ve added them via Add-PSSnapIn.&#160; The last post didn’t stick with me, so a little more detail to drill it into my thick skull this time…</p>  <p>As it turns out, <strong>Cmdlets must have a public default constructor, of course!</strong>&#160; I sometimes forget this step when I’m in my TDD rhythm.&#160; So something like this:</p>  <div style="background-color: #515151; padding: 5px">   <pre style="color: #dfdfbf"><font face="Consolas"><span style="color: #efc986">using</span> System.Management.Automation;

<span style="color: #efc986">namespace</span> MyCmdlets
{
    [<span style="color: #8acccf">Cmdlet</span>(<span style="color: #8acccf">VerbsCommon</span>.New, <span style="color: #dfaf8f">&quot;DooDad&quot;</span>)]
    <span style="color: #efc986">public class</span><span style="color: #8acccf"> NewDooDadCommand</span> : My<span style="color: #8acccf">BaseCommand</span>
    {
        [<span style="color: #8acccf">Parameter</span>(Position = <span style="color: #6e96be">0</span>, Mandatory = <span style="color: #efc986">true</span>)]
        <span style="color: #efc986">public string</span> MyData { <span style="color: #efc986">get</span>; <span style="color: #efc986">set</span>; }

        <span style="color: #efc986">private readonly</span><span style="color: #8c8cb4"> IDooDadFactory</span> _dooDadFactory;</font></pre>

  <pre style="color: #dfdfbf"><font face="Consolas">        <span style="color: #efc986">public</span> NewDooDadCommand(<span style="color: #8c8cb4">IDooDadFactory</span> dooDadFactory )
        {
            _dooDadFactory = dooDadFactory;
        }

        ...
    }
}</font></pre>
</div>

<p>Should really look more like this:</p>

<div style="background-color: #515151; padding: 5px">
  <pre style="color: #dfdfbf"><font face="Consolas"><span style="color: #efc986">using</span> System.Management.Automation;

<span style="color: #efc986">namespace</span> MyCmdlets
{
    [<span style="color: #8acccf">Cmdlet</span>(<span style="color: #8acccf">VerbsCommon</span>.New, <span style="color: #dfaf8f">&quot;DooDad&quot;</span>)]
    <span style="color: #efc986">public class</span><span style="color: #8acccf"> NewDooDadCommand</span> : My<span style="color: #8acccf">BaseCommand</span>
    {
        [<span style="color: #8acccf">Parameter</span>(Position = <span style="color: #6e96be">0</span>, Mandatory = <span style="color: #efc986">true</span>)]
        <span style="color: #efc986">public string</span> MyData { <span style="color: #efc986">get</span>; <span style="color: #efc986">set</span>; }

        <span style="color: #efc986">private readonly</span><span style="color: #8c8cb4"> IDooDadFactory</span> _dooDadFactory;</font></pre>

  <pre style="color: #dfdfbf"><span style="color: #808080">        /// &lt;summary&gt;
        ///</span><span style="color: #7a987a"> Need this public default constructor</span><span style="color: #808080">
        /// &lt;/summary&gt;</span><span style="color: #efc986">
        public</span> NewDooDadCommand()
            :<span style="color: #efc986">this</span>(<span style="color: #8acccf">ServiceLocator</span>.GetInstance&lt;<span style="color: #8c8cb4">IDooDadFactory</span>&gt;())
        {}</pre>

  <pre style="color: #dfdfbf"><font face="Consolas">        <span style="color: #efc986">public</span> NewDooDadCommand(<span style="color: #8c8cb4">IDooDadFactory</span> dooDadFactory )
        {
            _dooDadFactory = dooDadFactory;
        }

        ...
    }
}</font></pre>
</div>]]></content:encoded>
    </item>
  </channel>
</rss>