<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Using NMock2 in C#</title>
	<atom:link href="http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/</link>
	<description>foreach(Snippet aSnippet in CodeLog){ aSnippet.GetSolution(); }</description>
	<pubDate>Tue, 07 Sep 2010 18:32:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Settings expectations in NMock2 at Codelog</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comment-5547</link>
		<dc:creator>Settings expectations in NMock2 at Codelog</dc:creator>
		<pubDate>Tue, 05 Jan 2010 22:06:32 +0000</pubDate>
		<guid isPermaLink="false">http://codelog.blogial.com/?p=442#comment-5547</guid>
		<description>[...] of our previous articles would have given an introduction to NMocks. In here, we will try out various methods of setting [...]</description>
		<content:encoded><![CDATA[<p>[...] of our previous articles would have given an introduction to NMocks. In here, we will try out various methods of setting [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rowiss</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comment-4609</link>
		<dc:creator>rowiss</dc:creator>
		<pubDate>Thu, 17 Sep 2009 16:19:44 +0000</pubDate>
		<guid isPermaLink="false">http://codelog.blogial.com/?p=442#comment-4609</guid>
		<description>/* **************************************************
 * Test program for NMock2
 * 
 * The fragments form http://www.nmock.org/quickstart.html were used as input
 * and built together to a complete sample program that is ready to be used
 * 
 * nUnit Code was eliminated
 * 
 * Author: Roger Wissmann
 * *********************************************** */

using System;
using System.Diagnostics;           // Assert
using NMock2;                       // Nmock stuff

namespace NMock
{

    /// 
    /// Account-Definition-----------------
    /// 
    public class Account
    {
        private string m_ID;
        private double m_Amount;
        private string m_Currency;

        public Account(string id, string currency)
        {
            m_ID = id;
            m_Amount = 0;
            m_Currency = currency;
        }

        public void Withdraw(double money)
        {
            m_Amount -= money;
        }

        public void Deposit(double money)
        {
            m_Amount += money;
        }

        public double Balance
        {
            get { return m_Amount; }
        }

        public string Currency
        {
            get { return m_Currency; }
        }

    }
    /// End of Account Definition -------------

    public class Sample2
    {

        /// 
        /// Interface Definition for the Currency Services
        /// 
        public interface ICurrencyService
        {
            double GetConversionRate(string fromCurrency, string toCurrency);
        }

        // The implementation for the interface ICurrencyService is missing by intention
        // -&#62; data will be provided by the mock

        /// 
        /// Interface-Definition for the Account Services
        /// 
        public interface IAccountService
        {
            void TransferFunds(Account from, Account to, double amount);
        }


        public class AccountService : IAccountService
        {
            ICurrencyService m_CurrencyService;

            // Constructor
            public AccountService(ICurrencyService currencyService)
            {
                m_CurrencyService = currencyService;
            }

            public void TransferFundsStraight(Account from, Account to, double amount)
            {
                from.Withdraw(amount);
                to.Deposit(amount);
            }

            public void TransferFunds(Account from, Account to, double amount)
            {
                from.Withdraw(amount);
                double conversionRate = m_CurrencyService.GetConversionRate(from.Currency, to.Currency);
                double convertedAmount = amount * conversionRate;
                to.Deposit(convertedAmount);
            }
        }

 
        /// 
        /// Test
        /// 
        public class Tests
        {

            public void Test_TransferFunds()
            {
                Mockery myMock = new Mockery();

                // initialisiere Mock für das ICurrencyService-Interface
                ICurrencyService m_MockCurrencyService = myMock.NewMock();
                AccountService m_AccountService = new AccountService(m_MockCurrencyService);
 
                Account canadianAccount = new Account("12345", "CAD");
                Account britishAccount = new Account("54321", "GBP");
                britishAccount.Deposit(100);

                Expect.Once.On(m_MockCurrencyService).
                    Method("GetConversionRate").
                    With("GBP", "CAD").
                    Will(Return.Value(2.20));

                m_AccountService.TransferFunds(britishAccount, canadianAccount, 100);

                // This tests might fail because of float-problems
                Debug.Assert(0 == britishAccount.Balance);
                Debug.Assert(220 == canadianAccount.Balance);
                myMock.VerifyAllExpectationsHaveBeenMet();
            }

        }


    }
}</description>
		<content:encoded><![CDATA[<p>/* **************************************************<br />
 * Test program for NMock2<br />
 *<br />
 * The fragments form <a href="http://www.nmock.org/quickstart.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.nmock.org');" rel="nofollow">http://www.nmock.org/quickstart.html</a> were used as input<br />
 * and built together to a complete sample program that is ready to be used<br />
 *<br />
 * nUnit Code was eliminated<br />
 *<br />
 * Author: Roger Wissmann<br />
 * *********************************************** */</p>
<p>using System;<br />
using System.Diagnostics;           // Assert<br />
using NMock2;                       // Nmock stuff</p>
<p>namespace NMock<br />
{</p>
<p>    ///<br />
    /// Account-Definition&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
    ///<br />
    public class Account<br />
    {<br />
        private string m_ID;<br />
        private double m_Amount;<br />
        private string m_Currency;</p>
<p>        public Account(string id, string currency)<br />
        {<br />
            m_ID = id;<br />
            m_Amount = 0;<br />
            m_Currency = currency;<br />
        }</p>
<p>        public void Withdraw(double money)<br />
        {<br />
            m_Amount -= money;<br />
        }</p>
<p>        public void Deposit(double money)<br />
        {<br />
            m_Amount += money;<br />
        }</p>
<p>        public double Balance<br />
        {<br />
            get { return m_Amount; }<br />
        }</p>
<p>        public string Currency<br />
        {<br />
            get { return m_Currency; }<br />
        }</p>
<p>    }<br />
    /// End of Account Definition &#8212;&#8212;&#8212;&#8212;-</p>
<p>    public class Sample2<br />
    {</p>
<p>        ///<br />
        /// Interface Definition for the Currency Services<br />
        ///<br />
        public interface ICurrencyService<br />
        {<br />
            double GetConversionRate(string fromCurrency, string toCurrency);<br />
        }</p>
<p>        // The implementation for the interface ICurrencyService is missing by intention<br />
        // -&gt; data will be provided by the mock</p>
<p>        ///<br />
        /// Interface-Definition for the Account Services<br />
        ///<br />
        public interface IAccountService<br />
        {<br />
            void TransferFunds(Account from, Account to, double amount);<br />
        }</p>
<p>        public class AccountService : IAccountService<br />
        {<br />
            ICurrencyService m_CurrencyService;</p>
<p>            // Constructor<br />
            public AccountService(ICurrencyService currencyService)<br />
            {<br />
                m_CurrencyService = currencyService;<br />
            }</p>
<p>            public void TransferFundsStraight(Account from, Account to, double amount)<br />
            {<br />
                from.Withdraw(amount);<br />
                to.Deposit(amount);<br />
            }</p>
<p>            public void TransferFunds(Account from, Account to, double amount)<br />
            {<br />
                from.Withdraw(amount);<br />
                double conversionRate = m_CurrencyService.GetConversionRate(from.Currency, to.Currency);<br />
                double convertedAmount = amount * conversionRate;<br />
                to.Deposit(convertedAmount);<br />
            }<br />
        }</p>
<p>        ///<br />
        /// Test<br />
        ///<br />
        public class Tests<br />
        {</p>
<p>            public void Test_TransferFunds()<br />
            {<br />
                Mockery myMock = new Mockery();</p>
<p>                // initialisiere Mock für das ICurrencyService-Interface<br />
                ICurrencyService m_MockCurrencyService = myMock.NewMock();<br />
                AccountService m_AccountService = new AccountService(m_MockCurrencyService);</p>
<p>                Account canadianAccount = new Account(&#8221;12345&#8243;, &#8220;CAD&#8221;);<br />
                Account britishAccount = new Account(&#8221;54321&#8243;, &#8220;GBP&#8221;);<br />
                britishAccount.Deposit(100);</p>
<p>                Expect.Once.On(m_MockCurrencyService).<br />
                    Method(&#8221;GetConversionRate&#8221;).<br />
                    With(&#8221;GBP&#8221;, &#8220;CAD&#8221;).<br />
                    Will(Return.Value(2.20));</p>
<p>                m_AccountService.TransferFunds(britishAccount, canadianAccount, 100);</p>
<p>                // This tests might fail because of float-problems<br />
                Debug.Assert(0 == britishAccount.Balance);<br />
                Debug.Assert(220 == canadianAccount.Balance);<br />
                myMock.VerifyAllExpectationsHaveBeenMet();<br />
            }</p>
<p>        }</p>
<p>    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John L.</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comment-4608</link>
		<dc:creator>John L.</dc:creator>
		<pubDate>Thu, 17 Sep 2009 15:19:32 +0000</pubDate>
		<guid isPermaLink="false">http://codelog.blogial.com/?p=442#comment-4608</guid>
		<description>This is really a very good article. Thanks a lot.

John</description>
		<content:encoded><![CDATA[<p>This is really a very good article. Thanks a lot.</p>
<p>John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rowiss</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comment-4604</link>
		<dc:creator>rowiss</dc:creator>
		<pubDate>Thu, 17 Sep 2009 13:11:59 +0000</pubDate>
		<guid isPermaLink="false">http://codelog.blogial.com/?p=442#comment-4604</guid>
		<description>Hello John
You have to add a constructor in the class hello:

public Hello(IPerson person)
{
       this.person = person;
}

The mock interceptor that was created in step iv will create the GetName() output.

If you do not use nUnit, you can use instead of Assert.AreEqual for the verification in step vi:
 
Debug.Assert("Hello Pradeep"==h.Greet());</description>
		<content:encoded><![CDATA[<p>Hello John<br />
You have to add a constructor in the class hello:</p>
<p>public Hello(IPerson person)<br />
{<br />
       this.person = person;<br />
}</p>
<p>The mock interceptor that was created in step iv will create the GetName() output.</p>
<p>If you do not use nUnit, you can use instead of Assert.AreEqual for the verification in step vi:</p>
<p>Debug.Assert(&#8221;Hello Pradeep&#8221;==h.Greet());</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John L.</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comment-4588</link>
		<dc:creator>John L.</dc:creator>
		<pubDate>Wed, 16 Sep 2009 18:51:34 +0000</pubDate>
		<guid isPermaLink="false">http://codelog.blogial.com/?p=442#comment-4588</guid>
		<description>Hello, Praseo:

I am a little bit confused about your sample code:

    Hello h = new Hello(p);

Will the compiler complain Hello takes no argument? Could you provide a sample so we can download?

Thanks,

John L.</description>
		<content:encoded><![CDATA[<p>Hello, Praseo:</p>
<p>I am a little bit confused about your sample code:</p>
<p>    Hello h = new Hello(p);</p>
<p>Will the compiler complain Hello takes no argument? Could you provide a sample so we can download?</p>
<p>Thanks,</p>
<p>John L.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Urs Enzler - NMock2 dev team</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comment-4355</link>
		<dc:creator>Urs Enzler - NMock2 dev team</dc:creator>
		<pubDate>Sun, 06 Sep 2009 05:31:42 +0000</pubDate>
		<guid isPermaLink="false">http://codelog.blogial.com/?p=442#comment-4355</guid>
		<description>If you want to have a look at the latest and greatest NMock2 then please go to http://sourceforge.net/projects/nmock2. The one with the 2 in its name.

The version on the nmock site (which is not under our control, unfortunately) is not maintained anymore.

Happy mocking
Urs</description>
		<content:encoded><![CDATA[<p>If you want to have a look at the latest and greatest NMock2 then please go to <a href="http://sourceforge.net/projects/nmock2" onclick="javascript:pageTracker._trackPageview('/outbound/comment/sourceforge.net');" rel="nofollow">http://sourceforge.net/projects/nmock2</a>. The one with the 2 in its name.</p>
<p>The version on the nmock site (which is not under our control, unfortunately) is not maintained anymore.</p>
<p>Happy mocking<br />
Urs</p>
]]></content:encoded>
	</item>
</channel>
</rss>
