This is a migrated thread and some comments may be shown as answers.

GUID list changes after mocked

1 Answer 68 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ari
Top achievements
Rank 1
ari asked on 03 May 2012, 01:06 PM
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


1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 08 May 2012, 07:06 PM
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 >>

Tags
General Discussions
Asked by
ari
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or