chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi

the following code works as expected
public class className
   {
      public static readonly className Instance=new className();
      private int i = 0;

      public className()
      {
      }

      public int I
      {
         get { return i; }
         set { i = value; }
      }
   }

   [TestFixture]
   public class ClassName
   {
      [TestFixtureSetUp]
      public void SetUp()
      {
         MockManager.Init();
      }

      [Test]
      public void MethodName()
      {
         
         Mock all = MockManager.MockAll(typeof(className),Constructor.NotMocked);
            all.ExpectGetAlways("I","2");
         Assert.AreEqual("2", className.Instance.I);

            all.Clear("get_I");

         Assert.AreEqual("", className.Instance.I);

      }
   }


but when i use MS enterprise library to initialize the classname class the test method fails at the 2nd assertion

classname inittialization
public static readonly className Instance=(className)ConfigurationManager.GetConfiguration("classname");

line failure
Assert.AreEqual("", className.Instance.I);
asked by (28.8k points)

5 Answers

0 votes
Hi,
If the code is correct className.Instance.I should return an int and not a string. It should also return 0, when not mocked, So I would expect the tests to be:
[Test]
public void MethodName()
{
   Mock all = MockManager.MockAll(typeof(className),Constructor.NotMocked);
   all.ExpectGetAlways("I",2);
   Assert.AreEqual(2, className.Instance.I);

   all.Clear("get_I");
   Assert.AreEqual(0, className.Instance.I);
}



:?: In any case, what does className.Instance.I return without setting any expectations?
answered by (32k points)
0 votes
oops sorry i paste wrong code

code that passes is
public class ActionMan 
   {
      public static readonly ActionMan Instance = new ActionMan();
      private string emailFromName="";
      public ActionMan()
      {
         
      }
      
      public string EmailFromName
      {
         get { return emailFromName; }
         set {emailFromName=value;}

      }
   }

   [TestFixture]
   public class ClassName
   {
      [SetUp]
      public void SetUp()
      {
         MockManager.Init();
      }
      

      [Test]
      public void MethodName()
      {
         Mock all = MockManager.MockAll(typeof(ActionMan),Constructor.NotMocked); 
         all.ExpectGetAlways("EmailFromName","2"); 
         Assert.AreEqual("2", ActionMan.Instance.EmailFromName); 

         all.Clear("get_EmailFromName"); 

         Assert.AreEqual("", ActionMan.Instance.EmailFromName); 

      }
   }


and when i use MS enterprize library to initialize ActionMan class i replace
public static readonly ActionMan Instance = new ActionMan();

public static readonly ActionMan Instance = (ActionMan) ConfigurationManager.GetConfiguration("actionMan");

then test method fails
answered by (28.8k points)
0 votes
Hi,
:?: What is the faliure message?
:?: What does this code print? (Without TypeMock.NET)
Console.WriteLine(ActionMan.Instance.EmailFromName);
answered by (32k points)
0 votes
Hi,
Just to touch base, is this problem still around?
answered by (32k points)
0 votes
Hi scott

can't tell if that is still around can't replicate at the moment.
I know that u r always here so am i using your best of all products!!!!!!!

i ll keep in touch
answered by (28.8k points)
...