Show Menu

RhinoMocks Cheat Sheet by

Example for RhinoMocks Mocking Framework
development     c-     programming     tdd

Example Code

public interface ISalesTaxService
    Dictionary<string, decimal> GetSalesTaxByPostalCode(string country);

public class SalesTaxLogic
    private readonly Dictionary<string, decimal> _salesTaxByPostalCode;

    public SalesTaxLogic(ISalesTaxService salesTaxService, string country)
        _salesTaxByPostalCode = salesTaxService.GetSalesTaxByPostalCode(country);

    public decimal CalcSalesTax(string postalCode, decimal orderTotal)
        return Math.Round(_salesTaxByPostalCode[postalCode] * orderTotal, 2, MidpointRounding.AwayFromZero);


public class InvoiceLogicTests
    public void When_Calculating_Sales_Tax_It_Should_Not_Be_Zero()
        ISalesTaxService salesTaxServiceMock = MockRepository.GenerateMock<ISalesTaxService>();
        Dictionary<string, decimal> salesTaxRates = new Dictionary<string, decimal>();
        salesTaxRates.Add("43229", .0675M);
        salesTaxServiceMock.Stub(o => o.GetSalesTaxByPostalCode(null)).IgnoreArguments().Return(salesTaxRates).Repeat.Any();

        SalesTaxLogic salesTaxLogic = new SalesTaxLogic(salesTaxServiceMock, "USA");

        decimal orderSalesTax = salesTaxLogic.CalcSalesTax("43229", 19.95M);

        Assert.AreNotEqual(0, orderSalesTax);
        salesTaxServiceMock.AssertWasCalled(o => o.GetSalesTaxByPostalCode("USA"));

Download the RhinoMocks Cheat Sheet

1 Page

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors! is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!



No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Regular Expressions Cheat Sheet
            Clean Code Cheat Sheet by Urs Enzler

          More Cheat Sheets by GregFinzer

          Node Package Manager Cheat Sheet
          MOQ Cheat Sheet
          Yarn Package Manager Cheat Sheet