NSubstitute vs PRISM EventAggregator: Assert that calling a method triggers event with correct payload

前端 未结 3 1050
-上瘾入骨i
-上瘾入骨i 2020-12-21 09:39

Consider the below method that updates a person and publishes an event through the PRISM EventAggregator to indicate that the person has been updated.

I would like t

3条回答
  •  醉话见心
    2020-12-21 10:08

    I'm not an experienced unit tester so I'm not sure this is the correct unit test to write. But anyway, this is how I tested it so far and it seems to do what I want.

    [Test]
    public void TestPersonUpdateSendsEventWithCorrectPayload()
    {
        // ARRANGE
        PersonUpdatedEventArgs payload = null;
        _eventAggregator
            .GetEvent()
            .Subscribe(message => payload = message);
    
        // ACT
        _personService.UpdatePerson(5);
    
        // ASSERT
        payload.Should().NotBeNull();
        payload.Id.Should().Be(5);
    }
    

    Feedback welcome.

提交回复
热议问题