For example you are testing getSomeString.
public class Class1
{
public Class1() {}
public string getSomeString(string input)
{
//dosomething
OtherClass class = new OtherClass();
return class.getData();
}
}
public class OtherClass
{
public Otherclass() {/*some data*/}
public string getData()
{
//do something
string aString = getAString(Input);
//do something
}
public virtual string getAString(string input);
{
//do something to be mocked
return somethingToBeMocked;
}
}
So you need the unit test to mock out getAString. How do you do this?
I have tried just mocking getAString and hoping the test uses the mocked value, but that doesn't work.
I have tried mocking Class1 and setting the unit test class1 to be the mocked object, but i could not figure out how to make the mocked getAString passed into the mocked class1.
I cannot figure out what to do.
________
You are trying to test getAString method and you are trying to mock getAString method? getAString method is the method you are trying to test. You shouldn't mock it. Mocking should be applied on dependencies. For instance, had getAString method in class
OtherClass calls a method or property on another class such as Class1, that is where you need to apply
mocking; to have full control of what the object the method depends/calls return.
If i missed your question, please explain it with example and specify which method you want to test.
Thanks and have a great day!
--
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Moq Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moqdisc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You are trying to test getAString method and you are trying to mock getAString method? getAString method is the method you are trying to test. You shouldn't mock it. Mocking should be applied on dependencies. For instance, had getAString method in class
OtherClass calls a method or property on another class such as Class1, that is where you need to apply
mocking; to have full control of what the object the method depends/calls return.
If i missed your question, please explain it with example and specify which method you want to test.
Thanks and have a great day!
--