mardi 5 mai 2015

JustMock unit test passing when it should fail

I was writing some unit tests using JustMock and was pretty happy with myself that they were all passing until I tried to get one to fail. This unit test passes:

    [Test]
    public void BaseEventIsPublishedToBaseEventSubcriberButNotDerivedEventSubscriber()
    {
        MockingContainer<EventAggregationService> mockingContainer = new MockingContainer<EventAggregationService>(new AutoMockSettings { MockBehavior = Behavior.Loose });

        // Arrange
        Action<object, BaseEventArgs> baseEventHandler = Mock.Create<Action<object, BaseEventArgs>>();
        Mock.Arrange(() => baseEventHandler(Arg.AnyObject, Arg.IsAny<BaseEventArgs>())).MustBeCalled();
        Action<object, DerivedEventArgs> derivedEventHandler = Mock.Create<Action<object, DerivedEventArgs>>();
        Mock.Arrange(() => derivedEventHandler(Arg.AnyObject, Arg.IsAny<DerivedEventArgs>())).MustBeCalled();

        // Act
        EventAggregationService eventAggregationService = mockingContainer.Instance;
        using (eventAggregationService.Subscribe(new EventHandler<BaseEventArgs>((s, e) => baseEventHandler(s, e))))
        using (eventAggregationService.Subscribe(new EventHandler<DerivedEventArgs>((s, e) => derivedEventHandler(s, e))))
        {
            eventAggregationService.Publish(this, new BaseEventArgs());
        }

        // Assert
        Mock.Assert(baseEventHandler);
        Mock.Assert(derivedEventHandler);
    }

It should fail, I put a break point in each of the lambdas and the base is called but not the derived. I have tried shifting and twisting things but I can't for the life of me figure out why this test passes since the derived handler is confirmed to not be called.

Aucun commentaire:

Enregistrer un commentaire