MockingContainer-generated mocks not compatible with Raise

2 posts, 0 answers
  1. Isaac Abraham
    Isaac Abraham avatar
    21 posts
    Member since:
    Sep 2009

    Posted 20 Nov 2013 Link to this post

    If I have a MockingContainer and use Get<T> on it, and then try to Mock.Raise on an event of T, I receive an error: Unable to specify which event was deduced in the parameter. If I replace that with the same type generated by Mock.Create<T>, it works.
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 22 Nov 2013 Link to this post

    Hello Isaac,

    I tried the following test:
    public interface IAccount
    {
        event EventHandler<EventArgs> DepositMade;
    }
     
    public class BankTransation
    {
        readonly IAccount _fromAccount;
         
        public BankTransation(IAccount acc)
        {
            this._fromAccount = acc;
        }
    }
     
        [TestMethod]
        public void ShouldArrangeRaisesBehavior()
        {
            var container = new MockingContainer<BankTransation>();
             
            bool eventRaised = false;
            container.Get<IAccount>().DepositMade += delegate(object sender, EventArgs args)
            {
                eventRaised = true;
            };
     
            Mock.Raise(() => container.Get<IAccount>().DepositMade += null, new EventArgs());
             
            Assert.IsTrue(eventRaised);
        }
     and it passed.

    Could you please provide a code sample of the issue?

    Thank you for the understanding in advance.

    Regards,
    Kaloyan
    Telerik
    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top