Browsing all articles in Product
Oct
12
Comments

Mocking Extension Methods

Author Eli Lopian    Category Product, TDD     Tags

With Orcas and TypeMock 4.1 you can now mock Extension methods, easily.

Suppose we added a new method to int that return the Roman Number equivalent of that number:

public static class Extend { public static string RomanNumber(this int number) { // do complex logic return romanString; } }

Now we use this method in our code

string romanNumber = 2010.RomanNumber();

Here is how we mock this.

Reflective Mocks (Community Edition)

We mock that actual static extension method

Mock extentionMethodMock = MockManager.Mock(typeof(Extend)); extentionMethodMock.ExpectAndReturn("RomanNumber","MCMLIX");

Natural Mocks (Professional Edition)

We just call the extension method

using (RecordExpectations rec = new RecordExpectations()) { rec.ExpectAndReturn( 2010.RomanNumber(), "MCMLIX"); }

Checking Arguments

Care should be taken when Checking Arguments as the first argument is the instance of the type we are extending, suppose the extension method takes another argument

public static class Extend { public static string RomanNumber(this int number, bool upperCase) { // do complex logic return romanString; } }
 

Here is how we validate the arguments.

Reflective Mocks (Community Edition)

We have to implicitly ignore the first argument

// first arg is instance, second must be false Mock extentionMethodMock = MockManager.Mock(typeof(Extend)); extentionMethodMock.ExpectAndReturn("RomanNumber","MCMLIX"). Args(Check.IsAny(),false);

Natural Mocks (Professional Edition)

TypeMock automatically handles the first argument

using (RecordExpectations rec = new RecordExpectations()) { // TypeMock knows that this is an extension method and ignores first
// argument automatically
rec.ExpectAndReturn( 2010.RomanNumber(false), "MCMLIX") .CheckArguments(false); }
 
Oct
12
Comments

NCover 2.0

Author Eli Lopian    Category Product     Tags

imagePeter Waldschmidt has announced the release a new commercial version of NCover. NCover is now developed in  a new company called Gnoso. The new NCover is a complete Code Coverage Solution and combines Grant Drake’s NCoverExplorer

To use NCover 2.0 with TypeMock.NET, you will need to install TypeMock version 4.1. This now includes a option to link with NCover 2.0.
Now with Ncover 2.0 and TypeMock you can test and measure your 64 bit code! Both tools support 64 bit architectures and are integrated together.

Remember that all .NET 2.0+ code will run automatically in 64 bit and all .NET 1.1 code will always run in 32 bit mode.
To run .NET 2.0+ code in 32 bit, you must set the 32 bit flag of the executable.

Here is how:

corflags.exe /32BIT+ <path-to-executable>

Jamie has already created a TestDriven.Net version (2.9) that combines NCover 2.0 and TypeMock when running your tests.

Oct
12
Comments

TypeMock 4.1 Released

Author Eli Lopian    Category Product     Tags

Syndicated from the TypeMock Announcement Forum.

We have released TypeMock 4.1.

A few of the new features included in this release are:
Arrow Support of .NET 3.5 syntax changes

    Mocking automatic properties.
      Mocking Anonymous Types.
      Mocking Lambda Expressions.
      Verifying New Initialziers.
      Mocking Extension Methods.
      Mocking LINQ statements.

    Arrow Integration API for tools developers
    New API was released to ease integrating TypeMock with other developer tools.

    Arrow Tracer Enhancement (Professional Editions)
    The tracer tool has been enhanced with the ability to pause and resume trace gathering, the ability to resize its different panes, and the marking of the start and end of each test.

    Arrow NCover 2.0 Support (Professional Editions)
    The new release of NCover tool (2.0.1) is now supported and can be linked to run with TypeMock
    Arrow Support of Visual Studio Orcas Beta 2
    TypeMock.NET can be run on Visual Studio Orcas Beta 2.
    Arrow Many fixes

    More information can be found in the Release Notes

    Sep
    19
    Comments

    Developers are seeing the value of Unit Testing

    Author Eli Lopian    Category Product, TDD     Tags

    This summer has been great for TypeMock. We are showing record growth and have topped our sales and customer base. This is a sign that development groups are seeing the value of unit testing and understanding the need to isolate parts of the code to enable unit testing.

    This has of course kept us all very busy.

    We are also going to release new features that support .NET 3.5. There are many feature that need to be implemented, mainly support for:

    • Extension methods
    • Initializers
    • Anonymous Types
    • Linq

    I will talk about these in another post. We are also going to release an Integration API to ease integrating TypeMock with other developer tools. 

    Aug
    19
    Comments

    Mocking Linq – Preview

    Author Eli Lopian    Category Product     Tags

    We are working on our .NET 3.5 Support. There are many new feature that have been added, we will take a look at how to mock a linq statement

    For the following code in our application

    Northwind db = new Northwind(connStr) ; var query = from c in db.Customers where c.City == "Sarasota" select new { c.Name, c.City };

    Here is how to mock this statement and return fake customers

    [TestMethod] [VerifyMocks] public void IsolateLinq() { // create fake return values var fake = new[] { new {Name="Fake 1",City="NY"}, new {Name="Fake 2",City="London"}}; using (RecordExpectations r = new RecordExpectations()) { // don't hit the database, instead return test customers Northwind db = new Northwind(connStr) ; var answer = from c in db.Customers where c.City == "not-used" select new { c.Name, c.City }; r.Return(fake); } CallClassUnderTest(); // Continue with test }

    Comments about this syntax are welcome

    Mar
    25
    Comments

    Natural Mocks becoming more intelligent

    Author Eli Lopian    Category Product, TDD     Tags

    Natural Mocks automatically mocks everything. This includes return values. So the following code:

    using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork(); recorder.Return(new SqlInt32(1)); }

    Won’t work as expected because SqlInt32 is being mocked.

    This has bugged me a few times and I simply created the return value outside the recorder.

    SqlInt32 mockValue = new SqlInt32(1)); using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork(); recorder.Return(mockValue); }

    But this is not really nice, and a few customers have pointed out that this could be annoying!

    So we are going to implement a feature that will know that you are creating a return value and will not mock it!
    This way the first code will work as expected. Of course if you want to return a mocked value you will have to create the mock before, this might lead to non backward compatibility.

    To those who want the first code to work as before (although I don’t think that anyone would), mock the return value before calling the recorded statements, and change the above code to:

    using (RecordedExpecations recorder = RecorderManager.StartRecording()) { SqlInt32 mock = new SqlInt32(1); DummyClass.DoWork(); recorder.Return(mock); }

    Of course if you are going to do that, you will have to define the behavior of the SqlInt32 and you might as well use ChainedMocks

    using (RecordedExpecations recorder = RecorderManager.StartRecording()) { DummyClass.DoWork().Value; recorder.Return(1); }

    What do you think about this feature?

    Nov
    3
    Comments

    See How Easily you can Love Your Job

    Author Eli Lopian    Category Product     Tags

    If you are reading this you are probably the developer we are looking for.

    TypeMock is expanding and we are looking for .NET developers who have a passion for Bleeding Edge Issues like Mocking (of course), Test Driven Development and Aspect Oriented Development.

    We work in a dynamic environment and we have the infrastructure to support home offices for developers who require it.

    Interested?

    Send your resume to: jobs@typemock.com

    Oct
    4
    Comments

    Price changes

    Author Eli Lopian    Category Product     Tags

    Our prices are going to rise at the beginning of Next Month. All developers who are evaluating TypeMock are highly recommend to purchase before November to enjoy our low prices.

    Price Changes: (not final)

    • Enterprise Edition Plus 1 Year Maintenance: $299
    • Professional Edition Plus 1 Year: $199
    • Annual Maintenance: $49
    Sep
    26
    Comments

    TypeMock and TestDriven.NET

    Author eli    Category Product, TDD     Tags
    TypeMock.NET and TestDriven are now sold together – for a limited time only.
    These tool complement each other and using them you can:
    Write tests with
    TypeMock.NET and Run them from within Visual Studio with TestDriven.NET
    I have been working with
    Jamie Consdale on integrating these tool even more :-)

    So watch out for more features.

    We are offering a 25% discount for the TypeMock.NET and TestDriven.NET bundle.