bitblack / moq

Automatically exported from code.google.com/p/moq
Other
0 stars 0 forks source link

mocking interfaces with same property name (silverlight) #359

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying to resolve an issue I have with some generic / non-generic patterns

What steps will reproduce the problem?

1) Create set of interface like those

    public interface IWhatever
    {
        object Property { get; }
    }

    public interface IWhatever<out T> : IWhatever
    {
        new T Property { get; }
    }

    public interface IReallyWhatever
    {
        object Property { get; }
    }

    public interface IImplementWhatever : IWhatever<string>, IReallyWhatever
    {

    }
2) Create a test like this one

  [TestMethod]
        public void Test_Generic_Calls()
        {
            #region Mock setup

            const string returnedValue = "Tadadam!";

            var implementWhateverMock = new Mock<IImplementWhatever>(MockBehavior.Strict);

            var whateverMock = implementWhateverMock.As<IWhatever>();
            whateverMock.Setup(w => w.Property).Returns(returnedValue);

            var reallyWhateverMock = implementWhateverMock.As<IReallyWhatever>();
            reallyWhateverMock.Setup(w => w.Property).Returns(returnedValue);

            var whateverGenericMock = implementWhateverMock.As<IWhatever<string>>();
            whateverGenericMock.Setup(w => w.Property).Returns(returnedValue);

            #endregion

            #region Pre-interaction assertions

            CallIWhatever(implementWhateverMock.Object);
            CallIReallyWhatever(implementWhateverMock.Object);
            CallGenericIWhatever(implementWhateverMock.Object);

            #endregion

            #region Post-interaction assertions

            implementWhateverMock.VerifyAll();

            #endregion
        }

        private void CallIWhatever(IWhatever entity)
        {
            var property = entity.Property;
        }

        private void CallIReallyWhatever(IReallyWhatever entity)
        {
            var property = entity.Property;
        }

        private void CallGenericIWhatever<T>(IWhatever<T> entity)
        {
            var property = entity.Property;
        }

What is the expected output? What do you see instead?

I expect the test to pass

What version of the product are you using? On what operating system?

Moq.Silverlight version 3.1.416.3

Please provide any additional information below.

Original issue reported on code.google.com by rocketro...@gmail.com on 15 Feb 2013 at 3:39