Just so you know…

This test will never pass, no matter how hard you try:

“template.ShouldNotBeTheSameAs(template);”

Might be time for me to call it a night.

About Jeremy Miller

Jeremy is the Chief Software Architect at Dovetail Software, the coolest ISV in Austin. Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy is the author of the open source StructureMap tool for Dependency Injection with .Net, StoryTeller for supercharged acceptance testing in .Net, and one of the principal developers behind FubuMVC. Jeremy's thoughts on all things software can be found at The Shade Tree Developer at http://codebetter.com/jeremymiller.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://schambers.lostechies.com Sean Chambers

    I’ve had a couple of those nights. They quickly end in me kicking me in my own ass.

  • http://codebetter.com/blogs/jeremy.miller Jeremy D. Miller

    @Brian,

    SpecUnit is what you’re looking for;-)

  • Brian

    Oh. I don’t have ‘ShouldNotBeTheSameAs’ in my test framework so I thought it was some method you could get going – but that makes since now that I realize it’s a part of your testing framework. Context is everything I guess.

    Sorry. Brain dead today anyway so maybe it’s time for me to call it a night too.

  • http://codebetter.com/blogs/jeremy.miller Jeremy D. Miller

    @Brian,

    Um, thanks for the comment, BUT YOU COMPLETELY MISSED THE POINT! That sample code was from an obviously incorrectly written unit test. As in, duh, of course the test isn’t passing.

  • Brian

    Not sure what you’re getting at….

    Assuming you’re just needing to do a reference check to ensure to items are not the same, extend Template with this exetension method:

    static bool ShouldNotBeTheSameAs(this Template template, Template compare)
    {
    bool areSame = false;

    if(template == null && compare == null)
    {
    areSame = true;
    }
    else if(template != null && compare != null)
    {
    areSame = object.ReferenceEqual(template, compare);
    }

    //Looking for ‘not same as’ so invert the return
    return !areSame;
    }

    Then tests:

    [TestMethod()]
    public void ShouldNotBeTheSameAsTest_BothObjectsNull_ExpectFalse()
    {
    bool expected = false;
    Template test = null;
    bool actual = test.ShouldNotBeTheSameAs(null);
    Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void ShouldNotBeTheSameAs_OneNull_OneNotNull_ExpectTrue()
    {
    bool expected = true;
    Template test = new Template();
    bool actual = test.ShouldNotBeTheSameAs(null);
    Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void ShouldNotBeTheSameAs_PointerToSameObject_ExpectFalse()
    {
    bool expected = false;
    Template test = new Template();
    bool actual = test.ShouldNotBeTheSameAs(test);
    Assert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void ShouldNotBeTheSameAs_PointerToClonedObject_ExpectTrue()
    {
    bool expected = true;
    Template test = new Template();
    Template clone = Clone(test);
    bool actual = test.ShouldNotBeTheSameAs(clone);
    Assert.AreEqual(expected, actual);
    }

    public Template Clone(Template t)
    {
    //TODO: Use binary serialization to create a deep clone
    }

    Maybe you were trying to point something out that I’m just to brain dead today to figure out…