GUID list changes after mocked

2 posts, 0 answers
  1. ari
    ari avatar
    20 posts
    Member since:
    Jun 2010

    Posted 03 May 2012 Link to this post

    Hi..

    I have this kind of test situation I need Guid list to be send with ReturnsCollection 


            [TestMethod]       
            public void GetCodedObjectsClients_WithServiceArea()
            {               
                // Arrange
                KAPRole role = CreateDataRole();


                //Create test worker
                OHPClientWorker clientWorker = new OHPClientWorker(Entities);
                Guid MyGuidi = new Guid("ccae2079-2ebc-4200-879d-866fc82e6afa");
                Guid MyGuidi2 = new Guid("ccae2079-3ebc-4200-879d-866fc82e6afa");            
                IEnumerable<Guid> guids = new List<Guid> { MyGuidi, MyGuidi2 };


                // Create mock data
                Mock.Arrange(() => clientWorker.ServiceAreaWorker.GetServiceAreaUserGuids(Arg.IsAny<long>())).ReturnsCollection(guids);



    But in code to test the Guid list contains only guids 00000 0000 00000 00000 .... So guid was changed from ccae2079-2ebc-4200-879d-866fc82e6afa"  to 00000 0000 00000 0000  Why

     public ICollection<OHPClientWithCodedObject> GetCodedObjectsClients(ICollection<long> objectIDs, ICollection<KAPRole> roles, long serviceAreaID)
            {          
                //Users with rights granted through servicearea
                ICollection<Guid> userGuids = ServiceAreaWorker.GetServiceAreaUserGuids(serviceAreaID);
    ............
    userGuids  does not contain anymore real Guids


    Any Idea why ReturnsCollection  chages Guids


  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 08 May 2012 Link to this post

    Hi Ari,
    Thanks again for reporting the issue. However, I wrote the following test and it worked as per expectation.
    [TestMethod]
    public void ShouldAssertReturnsCollectonOnGuid()
    {
        var client = Mock.Create<OHPClientWorker>();
     
        Guid MyGuidi = new Guid("ccae2079-2ebc-4200-879d-866fc82e6afa");
        Guid MyGuidi2 = new Guid("ccae2079-3ebc-4200-879d-866fc82e6afa");
        IEnumerable<Guid> guids = new List<Guid> { MyGuidi, MyGuidi2 };
     
        // Create mock data
        Mock.Arrange(() => client.ServiceAreaWorker.GetServiceAreaUserGuids(Arg.IsAny<long>())).ReturnsCollection(guids);
     
        ICollection<Guid> userGuids = client.ServiceAreaWorker.GetServiceAreaUserGuids(10);
     
        Assert.AreEqual(MyGuidi, userGuids.First());
        Assert.AreEqual(MyGuidi2, userGuids.Last());
    }

    Here I used the latest version of the product and I am attaching the sample project to let you have a look. Generally, it should not override any values unless specified. One issue could be that it is creating a default valued object for ServiceAreaWorker class which is not initialized by ReturnsCollection properly. In that regard, I would request you to try the latest SP1 build released yesterday.

    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
Back to Top