• .NET

    Fakes, Stubs, and Mocks

    In Doing Your First Mock, Mehfuz Hossain explained why you should use mocking to improve your unit tests and then used a real world example to demonstrate this technique. In this post, I will take you down a different path using other forms of stand-ins.
  • .NET

    Doing Your First Mock

    Are you looking for a solution to your unit tests modifying data? Perhaps your unit tests are so slow that none of your teammates bother running them? You need mock objects. The following items will be covered to help you write better tests: Why Mocking – how mock objects help you Real World Example –an example of code to be tested Testing the Example –how to use mocking to test the example AAA Pattern – a pattern emerges when writing clean tests Why Mocking? Mocking is one of the most important factors in writing better unit tests. It drastically minimizes a test’s execution time and gives...
  • .NET

    JustMock. The tale continues... (Part 4)

    Last time we saw how to inject code in properties and static methods (including ones defined in static types). So far we are able to inject code in most common scenarios. In rare cases there is a need to isolate methods from mscorlib. In this post I will show you how do to this. Let's start with a demo program that I will explain in...
  • .NET

    JustMock. The tale continues... (Part 3)

    Last time we saw how we can inject code at the beginning of generic methods. Today I will show you how to inject code in properties. I will cover the syntax for static classes as well. So, let's start with a demo program that I will explain line-by-line. using System; using Telerik.CodeWeaver.Hook;   namespace ConsoleApplication4 {     public sealed class TargetClass1     {         public TargetClass1(string text)         {             Text = InitText = text;         }           public string InitText { get; private set;...
  • .NET

    JustMock. The tale continues... (Part 2)

    [Want to see JustMock in action? Register for the free webinar this Thursday, Jul 22, 11 am EST and check out What’s New in JustCode, JustMock, and OpenAccess ORM. During the live event attendees will also have the chance to win a Telerik Ultimate Collection (valued at $1999).]   In JustMock. The tale continues... (Part 1) we saw how we can inject prologue/epilogue code in .NET methods with JustMock. We covered the most simplest scenarios and some more complex ones as methods with ref/out parameters. Today I will show you how to do code injections in generic methods.Basically there is nothing new. We are already familiar with: AtStartOfAction AtStartOfFunc AtEndOfAction AtEndOfFunc etc. and last time...