FakeItEasy - The easy mocking library for .NET

A .Net dynamic fake framework for creating all types of fake objects, mocks, stubs etc. Context-aware fluent interface guides the developer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace FakeItEasyQuickstart
{
    using FakeItEasy;
    using NUnit; // any test framework will do

    public class SweetToothTests
    {
        [Test]
        public void BuyTastiestCandy_should_buy_top_selling_candy_from_shop
        {
            // make some fakes for the test
            var lollipop = A.Fake<ICandy>();
            var shop = A.Fake<ICandyShop>();

            // set up a call to return a value
            A.CallTo(() => shop.GetTopSellingCandy()).Returns(lollipop);

            // use the fake as an actual instance of the faked type
            var developer = new SweetTooth();
            developer.BuyTastiestCandy(shop);

            // asserting uses the exact same syntax as when configuring calls—
            // no need to learn another syntax
            A.CallTo(() => shop.BuyCandy(lollipop)).MustHaveHappened();
        }
    }
}

Visual Studio Tips

Jeremy Hutchinson listed out series of tips to be more productive in Visual Studio.

I was not aware of tip #2 - $exception Pseudovariable - Viewing uncaptured exception while debugging. Visual studio has a pseudo variable $exception in the debug mode which will hold the details of the last exception. To explore $exception, let’s create a small project:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
static void Main(string[] args)
{
    Object foo = null;

    string bar;
    try
    {
        bar = foo.ToString();
    }
    catch (Exception)
    {
        // Oh! What cause this exception?
        bar = null;
    }
}

Put a breakpoint at line 13 and run above code. The code will throw an exception and pause the execution in catch block. Now here you can use $exception variable to inspect exception details.

Visual Studio - $exception variable

Visual Studio - $exception variable

SQL SERVER - Stored Procedure sp_datatype_info to Get Supported Data Types

Sometimes you need to know more information about various data types supports by your SQL Server version. Information like if the specific data type is searchable or not, or it’s maximum precision, or if it’s case sensitive or not. sp_datatype_info system SP comes handy to retrieve such information.

1
2
3
4
5
USE master;
GO

EXEC sp_datatype_info;
GO
sp_datatype_info