Saturday, December 20, 2008

Object Mocking in F# with Rhino Mocks

Near the end of Oct. 2008, I posted an entry entitled Mocking F#.  While that post may be helpful to some, others may be looking for an example of how to dynamically mock objects from tests written in F#.  This post will attempt to provide that example.  In addition, it will provide another example of a BDD approach using some of the functionality in SpecUnit (a previous example is here).

Since the types being tested have not changed from those provided in the Mocking F# post, I will not be re-posting them here. 

#light
namespace FSharpMockExample.Services.Specs
open FSharpMockExample.Services
open FSharpMockExample.Entities
open FSharpMockExample.Data
open NUnit.Framework
open SpecUnit
open Rhino.Mocks

[<TestFixture>]
[<Concern("Customer Balance Calculation")>]
type behaves_like_context_with_customer_balance_calculation() = 
    inherit ContextSpecification()
    [<DefaultValue(false)>]
    val mutable customerService : ICustomerService
    [<DefaultValue(false)>]
    val mutable mocks : MockRepository
    override this.Context () = 
        this.mocks <- new MockRepository()
        ignore None

[<TestFixture>]
[<Concern("Customer Balance Calculation")>]
type When_calculating_balance_with_starting_balance_of_fifty_and_ten_percent_discount() = 
    inherit behaves_like_context_with_customer_balance_calculation()
    override this.Because () = 
        this.mocks <- new MockRepository()
        let cAgs = [||]
        let customerDao = this.mocks.DynamicMock<ICustomerDao>(cAgs)
        let customer = new Customer(1, "XYZ Company", 50.00M)
        Expect.Call(customerDao.GetById(1)).Return(customer) |> ignore
        this.customerService <- new CustomerService(customerDao) 
    [<Observation>]
    member this.should_have_a_calculated_balance_of_forty_five() = 
        this.mocks.ReplayAll();
        this.customerService.CalculateBalaceWithDiscount(1, 0.1M).ShouldEqual(45M) |> ignore
        this.mocks.VerifyAll();


6 comments:

  1. [u][b]Xrumer[/b][/u]

    [b]Xrumer SEO Professionals

    As Xrumer experts, we have been using [url=http://www.xrumer-seo.com]Xrumer[/url] for a long immediately for the time being and know how to harness the enormous power of Xrumer and build it into a Bills machine.

    We also yield the cheapest prices on the market. Diverse competitors devise cost 2x or even 3x and a a pile of the term 5x what we responsibility you. But we believe in providing prominent help at a debilitated affordable rate. The whole point of purchasing Xrumer blasts is because it is a cheaper alternative to buying Xrumer. So we aim to abide by that bit in cognizant and afford you with the cheapest standing possible.

    Not solitary do we take the best prices but our turnaround time for your Xrumer posting is wonderful fast. We compel secure your posting done ahead of you know it.

    We also provide you with a sated log of well-heeled posts on different forums. So that you can catch a glimpse of over the extent of yourself the power of Xrumer and how we have harnessed it to benefit your site.[/b]


    [b]Search Engine Optimization

    Using Xrumer you can think to see thousands upon thousands of backlinks exchange for your site. Myriad of the forums that your Location you force be posted on bear great PageRank. Having your link on these sites can categorically expropriate establish up some top-grade grade recoil from links and as a matter of fact as well your Alexa Rating and Google PageRank rating through the roof.

    This is making your position more and more popular. And with this developing in popularity as familiarly as PageRank you can think to lead your site definitely filthy high in those Search Locomotive Results.
    Above

    The amount of traffic that can be obtained nearby harnessing the power of Xrumer is enormous. You are publishing your site to tens of thousands of forums. With our higher packages you may equivalent be publishing your locality to HUNDREDS of THOUSANDS of forums. Imagine 1 post on a stylish forum last will and testament almost always get 1000 or so views, with signify 100 of those people visiting your site. Now create tens of thousands of posts on in demand forums all getting 1000 views each. Your freight longing withdraw because of the roof.

    These are all targeted visitors that are interested or exotic about your site. Deem how innumerable sales or leads you can fulfil with this great loads of targeted visitors. You are line for line stumbling upon a goldmine bright to be picked and profited from.

    Keep in mind, Above is Money.
    [/b]

    GO YOUR TWOPENNY ERUPTION TODAY:


    http://www.xrumer-seo.com

    ReplyDelete
  2. [B]NZBsRus.com[/B]
    Forget Idle Downloads Using NZB Files You Can Easily Search High Quality Movies, PC Games, MP3s, Applications & Download Them @ Fast Rates

    [URL=http://www.nzbsrus.com][B]Newsgroup Search[/B][/URL]

    ReplyDelete
  3. [B]NZBsRus.com[/B]
    Lose Slow Downloads Using NZB Files You Can Hastily Find High Quality Movies, Games, MP3 Albums, Applications & Download Them at Dashing Rates

    [URL=http://www.nzbsrus.com][B]NZB Search[/B][/URL]

    ReplyDelete
  4. [B]NZBsRus.com[/B]
    No More Sluggish Downloads Using NZB Downloads You Can Easily Find Movies, Games, MP3 Albums, Applications & Download Them @ Blazing Rates

    [URL=http://www.nzbsrus.com][B]NZB Search[/B][/URL]

    ReplyDelete
  5. Infatuation casinos? reading this result [url=http://www.realcazinoz.com]casino[/url] instruction and move evasively online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
    you can also jerk our untested [url=http://freecasinogames2010.webs.com]casino[/url] forgo at http://freecasinogames2010.webs.com and be the conqueror in original spondulix !
    another in [url=http://www.ttittancasino.com]casino spiele[/url] within an eyelash of is www.ttittancasino.com , as opposed to of german gamblers, watch freed online casino bonus.

    ReplyDelete
  6. Hey buddy very interesting article about Object Mocking in F# with Rhino Mocks I would like to have any update about it, thanks for sharing!!!

    ReplyDelete