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

byte enum as parameter not matching argument

1 Answer 21 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Software asked on 28 Nov 2012, 05:27 PM
I have an enum declared as

public enum SubdivisionTypeCode : byte
        None = 255,
        State = 0,
        County = 1,
        City = 2,
        Village = 3,
        Township = 4,
        CitySchoolDistrict = 5,
        SchoolDistrict = 6,
        JtVocSchoolDistrict = 7,
        Miscellaneous = 8,
        University = 9,
        PooledFinancing = 10

when I try to use that in a parameter in a Mocking Arrange, it doesn't match and the mock doesn't get called correctly.
public interface ISubdivisionTypeRepository
    ISubdivisionType Get(SubdivisionTypeCode subdivisionTypeCode);
var subdivisionTypeCode = SubdivisionTypeCode.City;
var subdivisionType = new SubdivisionType(subdivisionTypeCode: SubdivisionTypeCode.City);
var subdivisionTypeRepository = Mock.Create<ISubdivisionTypeRepository>();
Mock.Arrange(() => subdivisionTypeRepository.Get(subdivisionTypeCode)).Returns(subdivisionType);
var s = subdivisionTypeRepository.Get(subdivisionTypeCode);
In this case s returns null.  

If I remove the type from the enum (or change it to int) the above code returns the correct instance as expected.


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 30 Nov 2012, 08:50 PM
Hi Eric,

I sent you a reply at Ticket # 635484. Please check it out.  Hopefully it will be enough to resolve your issue.

Kind Regards
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question