Arrange sometimes returning incorrect value during execution

6 posts, 0 answers
  1. Carlos
    Carlos avatar
    3 posts
    Member since:
    Aug 2012

    Posted 11 Jun 2012 Link to this post

    Hello,

    I am currently running into an issue where the arrange method returns the wrong value for the mock.  This does not occur all the time, but randomly, which seems to suggest a threading issue.  The "arrange" code that I have is as follow:

          IRTObjectModel model = Mock.Create<IRTObjectModel>();
     
          Mock.Arrange<TimeSpan>(() => model.ShiftDateStartTime)
            .Returns(shiftDateStartTime);
          Mock.Arrange<IDictionary<stringFuelBay>>(() => model.FuelBays)
            .Returns(initialTestData.ActiveFuelBays);
          Mock.Arrange<IDictionary<stringFuelTruck>>(() => model.FuelTrucks)
            .Returns(initialTestData.ActiveFuelTrucks);

    However, sometimes I get the following error message:
    System.InvalidCastException: Unable to cast object of type 'System.TimeSpan' to type 'FMFuelDispatch.Util.ObservableDictionary`2[System.String,FMFuelDispatch.Model.FuelBay]'.

    According to the stack trace, it looks like there is something wrong with the proxy:
    IRTObjectModel_Proxy_26c2fd2954ac4f68ba71390f3a22fa84._get_FuelBays(MethodInvocation , Int32 , Boolean )
    IRTObjectModel_Proxy_26c2fd2954ac4f68ba71390f3a22fa84.get_FuelBays()
    FMFuelDispatch.ViewModel.FuelScheduleViewModel.DataBindFuelSources(IRTObjectModel objModel, IDictionary`2 keyedResources, ResourceCollection resourceCollection) 

    Based on the above, it looks like that calling the FuelBays property of my mock, returns the first arrange.  I am currently using the free edition of JustMock (v2011.3.1116.2).  Is there anything I can do to work around this problem?

    Thanks.


    -Carlos.
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 14 Jun 2012 Link to this post

    Hi Carlos,

    Thanks again for reporting the issue to us.

    At this point, I would recommend you to use the latest version of JustMock that is released a week ago. We have fixed a similar issue in the last release. Please try it out and let me know if you still getting the exception.

    In case of exception I would also request you to send me the sample project that you are working with.



    Kind Regards,
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
  4. Carlos
    Carlos avatar
    3 posts
    Member since:
    Aug 2012

    Posted 14 Jun 2012 Link to this post

    Hello,

    Is there a way to have both installed on the same machine?  There are currently a few projects using the older version, and I noticed that upgrading to the newest version will not only uninstall the old version but install the new version in a different folder path.  This would break the build for the other projects.

    Thank you.


    -Carlos.
  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 19 Jun 2012 Link to this post

    Hi Carlos,

    Unfortunately, you can't have two separate versions of JustMock in the same machine. However, JustMock releases are backward compatible therefore even you upgrade to the newer one, it still should work with existing projects.

    Kind regards,
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Carlos
    Carlos avatar
    3 posts
    Member since:
    Aug 2012

    Posted 15 Aug 2012 Link to this post

    Hello Telerik,

    I am still getting this error with version 2012.2.813.9.  I have attached a specific example of the error.  The relevant parts of the setup for my test is as follow:

          IRTObjectModel model = Mock.Create<IRTObjectModel>();
          Mock.Arrange<IDictionary<stringFuelTruck>>(() => model.FuelTrucks)
            .Returns(testData.ActiveFuelTrucks)
            .OccursAtLeast(2);     // 2 due to databinding + event
          using (FuelScheduleViewModel target = new FuelScheduleViewModel(model))
          {
            target.Init();
                }

    The relevant parts of the class for the testData variable above is as follow:

      public class FuelScheduleTestData
      {
        public ObservableDictionary<stringFuelTruck> ActiveFuelTrucks { getprivate set; }
        }

    The IRTObjectModel being mocked implements an interface that includes the following property:
        ObservableDictionary<stringFuelTruck> FuelTrucks { get; }

    If you review the attached screenshot, it will show you the stack trace of the failed test and point at the proxy class code.  As well, the screenshot will also verify that I am using the expected version (2012.2.813.9).
  7. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 22 Aug 2012 Link to this post

    Hi Carlos,
    Thanks again for contacting us. I am sending a test project where I wrote the test in the following way and working as expected:

    IRTObjectModel model = Mock.Create<IRTObjectModel>();
    Mock.Arrange(() => model.FuelTrucks)
      .Returns(_Trucks).OccursOnce();
     
    Assert.IsTrue(model.FuelTrucks.Count() == 1);
     
    Mock.Assert(model);

    However, if it does not solve your issue then please update the project to a point where it fails and send it over so that I can investigate further.

     

    Kind Regards
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft R3 2016 release webinar banner