I need a help as I am very new to moles, I have the following code:
namespace A.BusinessLayer
{
sealed class AManager
{
void Method1(object obj){
// do something
}
}
public class B
{
void Method1(object obj){
if some thing{
AManager a=new AManager();
a.Method1();
}
}
}
}
Now I am creating Unit Tests for the above classes as below (wondering whether this could even be possible): Explanation: When B.Method1 is called I simply wan't to check whether A.Method1 was called from the implemetation, this is what I am simply expecting this code to test.
namespace A.Tests
{
class BTest
{
void Method1Test(){
//I need something like
A.BusinessLayer.Moles.MAManager t=new A.BusinessLayer.Moles.MAManager();
t.Method1=(obj)=>{
Assert.IsTrue(true);
};
B=new B();
B.Method1();
//Assert.IsTrue(true);
}
}
}
I have added following attributes to AssemblyInfo class of A.BusinessLayer project as :
[assembly: InternalsVisibleTo("A.BusinessLayer.Moles")]
[assembly: InternalsVisibleTo("A.BusinessLayer.Tests")]
Problem is I cannot see any Moles for AManger class?
Any help even to improve my approach will be appriciated.
Update: I see class AManager in *moles.xml file, but cannot see it in the A.BusinessLayer.Moles dll through object browser
After banging my head with monitor for some time, it finally started to work. Here is what I did:
You need to clean the test project and then build it again
Hope this helps to some one suffering from the same problem.
As for the approach is considered I am using the below code:
namespace A.Tests
{
class BTest
{
void Method1Test(){
bool isMethodInvoked=false;
A.BusinessLayer.Moles.MAManager.AllInstances=()=>{
isMethodInvoked=true;
};
B=new B();
B.Method1();
Assert.IsTrue(isMethodInvoked, "Method is not invoked");
}
}
}