Paulo Morgado

.NET Development & Architecture

This Blog

Syndication

Search

Tags

News

Unit Test Today! Get Typemock Isolator!

Projects

Books

 

Visitors

Visitor Locations

Community

Email Notifications

Archives

Profile

Disclaimer

The opinions and viewpoints expressed in this site are mine and do not necessarily reflect those of Microsoft, my employer or any community that I belong to. Any code or opinions are offered as is. Products or services mentioned are purchased by me, made available to me by my employer or the manufacturer/vendor which doesn't influence my opinion in any way.

January 2008 - Posts

TypeMock: How to Make Reflective Mocks More Natural

Like I said before, this as been on the back of my mind for a while.

A while back I introduced a way to get the MethodInfo of a method in a strongly typed way using LINQ, and that's how I'm going to make Reflective Mocks more Natural.

Well, it's as easy as this:

public static class MockExtender
{
    public static IParameters ExpectAndReturn<T1, T2, TResult>(this IMockControl mock, Expression<Func<T1, T2, TResult>> expression, object ret, params Type[] genericTypes)
    {
        return mock.ExpectAndReturn((expression.Body as MethodCallExpression).Method.Name, ret, genericTypes);
    }
}

(For now, I'll leave to someone else the implementation of the rest of the overloads)

With this implementation it's possible to handle static classes (a limitation of Fredrik's implementation).

As for private methods, just let Visual Studio (2008, in this sample) and TypeMock do their magic.

So, to test this class:

public static class Class1
{
    public static string PublicMethod(string param1, int param2)
    {
        return PrivateMethod(param2, param1);
    }

    private static string PrivateMethod(int param2, string param1)
    {
        throw new NotImplementedException();
    }
}

We just write this test:

[TestMethod()]
public void PublicMethodTest()
{
    string param1 = "param";
    int param2 = 5;
    string expected = "return";
    string actual;

    Mock targetMock = MockManager.Mock(typeof(Class1));

    targetMock.ExpectAndReturn((int i, string s) => ClassLibrary1.Class1_Accessor.PrivateMethod(i, s), expected).Args(param2, param1);

    actual = Class1.PublicMethod(param1, param2);

    Assert.AreEqual(expected, actual);
}

How about this for clean and simple?

Posted Thu, Jan 31 2008 23:56 by Paulo Morgado | 2 comment(s)

BUG UPDATE: Using Custom Identities in ASP.NET fails when using the ASP.NET Development Server

Sometime ago I reported this bug. Looks like there's a workaround for it. Find more about it here.

Posted Tue, Jan 29 2008 23:14 by Paulo Morgado | with no comments

TypeMock: Making Reflective Mocks More Natural

I've been thinking about this for a while. Seems like someone beat me to it.

Posted Tue, Jan 29 2008 22:46 by Paulo Morgado | 2 comment(s)

Is Testing The Ultimate Goal?

Whenever you throw TDD without worshiping it you turn yourself immediately in a victim of religious fundamentalists. TDD is a gift from god, it's good, it's cool and should never be questioned. It's a dogma.

Frans Bouma complains about it and the lack of scientific proof of the fact that TDD is really useful and good. Phil Haack throws a paper at him (which I haven't read - just looked at) but, from his own comments, doesn't dismiss Frans's point.

Why are we testing code anyway? What does it prove? According to Frans, not much. I'll have to agree with Frans on this. In summary, first you need to prove (or have proof) that what you are going to code is the right thing. Only then you can prove that you've done it correctly.

This goes even further when frameworks like TypeMock are considered too powerful. They are seen as evil in the eyes of the purists. Roy Osherove questions his readers and TypeMock community about this.

While we have to have in mind Frans' post about correctness provability, Travis does make a good point when he questions "Design for testability vs. API as a deliverable".

My bottom line in this subject is that testing tools are just tools like any other tools use in software development. The fact that they are becoming so good and powerful just changes what tools we use and how we use them.

I like compiled languages because they give me confidence over interpreted languages, because I can assert that although my code might have some errors on what it does it doesn't have any errors on how it was written.

On another level, unit testing and mock frameworks give me confidence that my code will do exactly what I intended it to do. Which might still not be correct.

Posted Mon, Jan 28 2008 1:15 by Paulo Morgado | 2 comment(s)

Filed under: , ,

WCSF geekSpeak: Download Available At MSEVENTS

For those who missed my webcast (and wanted to watch it) it's available to download at the MSEVENTS site.

Posted Sun, Jan 27 2008 23:25 by Paulo Morgado | with no comments

Custom Generators For SQL Data Generator 1.0 Beta

SQL Data Generator will be a great tool when redgate releases it.

David Connell has a detailed post on how to build your own generator where he explains the concepts and ideas behind developing generators for SQL Data Generator 1.0 Beta.

Andrew Clarke also has a nice example with it's Waffle Generator.

Posted Sun, Jan 27 2008 23:11 by Paulo Morgado | 2 comment(s)

Filed under: , , ,

TypeMock Basic Introduction Screencast at Facebook

Roy Osherove done a nice introductory 10 minute screencast that shows some basic features in TypeMock.

Posted Sun, Jan 27 2008 22:42 by Paulo Morgado | with no comments

Naming Conventions For Unit Testing

Reading Roy Osherove's post about naming conventions for unit testing I have to say that it all makes sense to me.

I just want to add that for property testing I use the corresponding method names: get_Property and set_Property.

Posted Sun, Jan 27 2008 22:13 by Paulo Morgado | with no comments

New Weblog at ASP.NET

Responding to Joe Stagner's invitation to blog at the ASP.NET blogging community, I've set up a new blog.

My new blog is at http://weblogs.asp.net/PauloMorgado/ and will be a mirror of my pre existing blog in "English" at MSMVPS. The syndication feed will be the same for both blogs (http://feeds.feedburner.com/PauloMorgadoEN) like I already have for my two blogs in Portuguese [^][^][^].

Posted Sun, Jan 27 2008 21:24 by Paulo Morgado | with no comments

Filed under: , ,

WCSF geekSpeak: Online Resources

Here is the list of topics covered in the WCSF geekSpeak webcast:

  1. Contextual Auto Complete Bundle
    Demo code: WCSF geekSpeak: Contextual Auto Complete Bundle Demo Code
  2. Validation Bundle
    Demo code: WCSF geekSpeak: Validation Bundle Demo Code
  3. Real-Time Search Bundle
    Demo code: WCSF geekSpeak: Real-Time Search Bundle Demo Code
  4. MVP Bundle
  5. Modularity Bundle
  6. Page Flow Application Block
  7. E-Commerce Catalog
  8. EventBroker extension

And here is a list of online resources:

Posted Thu, Jan 24 2008 0:46 by Paulo Morgado | with no comments

WCSF geekSpeak: Real-Time Search Bundle Demo Code

This demo e based on the demo included in the Real-Time Search Bundle download.

The demo includes an entry form with two implementations:

  1. Using an Update Panel.
  2. Using the WCSF's Real-Time Search Monitor.

Posted Wed, Jan 23 2008 23:51 by Paulo Morgado | 2 comment(s)

WCSF geekSpeak: Validation Bundle Demo Code

This demo e based on the demo included in the Validation Bundle download.

The demo includes an entry form with three implementations:

  1. Using the traditional server-side validation.
  2. Using server-side validation with the Enterprise Library's Validation Application Block.
  3. Using server-side validation with the Enterprise Library's Validation Application Block and the WCSF's Server-Side Validation Extender.

Posted Wed, Jan 23 2008 23:46 by Paulo Morgado | 3 comment(s)

WCSF geekSpeak: Contextual Auto Complete Bundle Demo Code

This demo e based on the demo included in the Contextual Auto Complete Bundle download.

The demo includes an entry form with three implementations:

  1. Using the traditional auto post back model
  2. Using an update panel
  3. Using the Contextual Auto Complete Extender.

Posted Wed, Jan 23 2008 23:26 by Paulo Morgado | 3 comment(s)

WCSF geekSpeak: Registration Open

There was a problem with the registration for this webcast, but it's now solved.

Posted Fri, Jan 18 2008 22:27 by Paulo Morgado | 2 comment(s)

TypeMock Snippets For Visual Studio

I've just created a set of code snippets for Visual Studio for my most used features of TypeMock. Feel free to use it.

Posted Sun, Jan 13 2008 23:37 by Paulo Morgado | 9 comment(s)

Newspaper Style Template for FeedDemon 2.6

I have built a newspaper style template for FeedDemon 2.6 based the supplied Blue Vista but making better use of screen space and adding the post categories to the news item header.

Feel free to use it. There's one caveat though, I couldn't find out why, sometimes, there are categories missing.

Posted Sat, Jan 12 2008 23:26 by Paulo Morgado | 1 comment(s)

Filed under:

FeedDemon 2.6 is out

The latest release of the NewsGator's FeedDemon is out and it's now free. Check out the release notes.

Posted Sat, Jan 12 2008 22:40 by Paulo Morgado | with no comments

Filed under:

Enterprise Library V4 Product Backlog

Check out the Enterprise Library V4 Product Backlog.

Posted Sat, Jan 12 2008 22:07 by Paulo Morgado | with no comments

Free e-books on the Visual Studio 2008 Learning Portal

Microsoft is offering free e-books (or, at least some chapters) in the Visual Studio 2008 Learning Portal.

Posted Thu, Jan 3 2008 0:23 by Paulo Morgado | 6 comment(s)