Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
QuestionHow to launch another application Pin
KennyODell5-Jun-08 4:24
KennyODell5-Jun-08 4:24 
AnswerRe: How to launch another application Pin
Gareth H5-Jun-08 4:28
Gareth H5-Jun-08 4:28 
AnswerRe: How to launch another application Pin
DaveyM695-Jun-08 8:13
professionalDaveyM695-Jun-08 8:13 
QuestionPrint Pin
Kr_Chandan5-Jun-08 4:10
Kr_Chandan5-Jun-08 4:10 
AnswerRe: Print Pin
leppie5-Jun-08 4:50
leppie5-Jun-08 4:50 
AnswerRe: Print Pin
Brady Kelly5-Jun-08 5:38
Brady Kelly5-Jun-08 5:38 
GeneralRe: Print Pin
Kr_Chandan5-Jun-08 19:09
Kr_Chandan5-Jun-08 19:09 
QuestionNMock expectations producing weird results Pin
N a v a n e e t h5-Jun-08 4:09
N a v a n e e t h5-Jun-08 4:09 
I am using NMock for creating mock objects. I have found a weird behavior of the expectations set on the object. Here is my code. (This code is just to explain the problem, and not used in production)

public class AccountServices
{
    ICurrencyServices currencyService = null;
    public AccountServices(ICurrencyServices services)
    {
        currencyService = services;
    }

    public string Total()
    {
        return "10" + currencyService.GetTotal();
    }
}

public class CurrencyServices : ICurrencyServices
{
    public string GetTotal()
    {
        return "10";
    }
}

public interface ICurrencyServices
{
    string GetTotal();
}
I am testing Total() method by mocking ICurrencyServices and injecting via constructor to AccountServices. Here goes my test method

[Test]
public void TestTotal()
{
    Mockery mock = new Mockery();
    ICurrencyServices currency = mock.NewMock<icurrencyservices>();
    Expect.Once.On(currency).Method("GetTotal").Will(Return.Value("100"));
    AccountServices services = new AccountServices(currency);
    Assert.AreEqual("10100", services.Total());
}</icurrencyservices>
This works well. But when I add one more assert just down to the last assert
AccountServices services = new AccountServices(currency);
Assert.AreEqual("10100", services.Total());
Assert.AreEqual("10100", services.Total());// This will throw exception
I am getting the following error.
"unexpected invocation of currencyservices.GetTotal()"
. This problem will be solved if I add one more expectation before the last assert. It looks like each time I need to add the expectation before doing anything that calls "GetTotal". Any idea why it works like this ? Why don't the expected value persist until the scope ends ?

All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia

How to use google | Ask smart questions

AnswerRe: NMock expectations producing weird results Pin
Judah Gabriel Himango5-Jun-08 5:06
sponsorJudah Gabriel Himango5-Jun-08 5:06 
GeneralRe: NMock expectations producing weird results Pin
N a v a n e e t h5-Jun-08 7:04
N a v a n e e t h5-Jun-08 7:04 
GeneralRe: NMock expectations producing weird results Pin
Judah Gabriel Himango5-Jun-08 7:13
sponsorJudah Gabriel Himango5-Jun-08 7:13 
GeneralRe: NMock expectations producing weird results Pin
N a v a n e e t h5-Jun-08 7:21
N a v a n e e t h5-Jun-08 7:21 
GeneralRe: NMock expectations producing weird results Pin
Judah Gabriel Himango6-Jun-08 6:45
sponsorJudah Gabriel Himango6-Jun-08 6:45 
GeneralRe: NMock expectations producing weird results Pin
N a v a n e e t h6-Jun-08 7:37
N a v a n e e t h6-Jun-08 7:37 
QuestionSuspending a process programmatically, How is that? Pin
LordCover5-Jun-08 3:21
LordCover5-Jun-08 3:21 
QuestionRe: Suspending a process programmatically, How is that? Pin
LordCover5-Jun-08 3:25
LordCover5-Jun-08 3:25 
AnswerRe: Suspending a process programmatically, How is that? Pin
CPallini5-Jun-08 3:29
mveCPallini5-Jun-08 3:29 
GeneralRe: Suspending a process programmatically, How is that? Pin
LordCover5-Jun-08 3:47
LordCover5-Jun-08 3:47 
AnswerRe: Suspending a process programmatically, How is that? Pin
Anthony Mushrow5-Jun-08 3:33
professionalAnthony Mushrow5-Jun-08 3:33 
GeneralRe: Suspending a process programmatically, How is that? Pin
LordCover5-Jun-08 4:50
LordCover5-Jun-08 4:50 
QuestionApplicationSettingBAse Issue Pin
AmithaRaghu5-Jun-08 2:46
AmithaRaghu5-Jun-08 2:46 
QuestionWCF plugin for VS 2005 Pin
priy@5-Jun-08 1:18
priy@5-Jun-08 1:18 
AnswerRe: WCF plugin for VS 2005 Pin
#realJSOP5-Jun-08 2:45
mve#realJSOP5-Jun-08 2:45 
AnswerRe: WCF plugin for VS 2005 Pin
teejayem5-Jun-08 3:22
teejayem5-Jun-08 3:22 
Questiona question about kernel32.dll and user32.dll Pin
Sajjad Izadi5-Jun-08 1:16
Sajjad Izadi5-Jun-08 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.