Skip to content

Instantly share code, notes, and snippets.

@dgwaldo
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgwaldo/5d6d5fcbee464f2e50a1 to your computer and use it in GitHub Desktop.
Save dgwaldo/5d6d5fcbee464f2e50a1 to your computer and use it in GitHub Desktop.
[TestMethod]
public void LoadData_SendsUpdateStatusEvents()
{
//Arrange
_mockEventAggregator.Setup(x => x.GetEvent<UpdateStatusEvent>().Publish(It.IsAny<string>()));
//Act
_materialMasterVm.LoadData().GetAwaiter();
//Assert
_mockEventAggregator.Verify(x => x.GetEvent<UpdateStatusEvent>().Publish(It.IsAny<string>()), Times.Exactly(2));
}
[TestMethod]
public void EventAggregator_ReceivesUpdatedUnitsEvent_CallsOnUnitsUpdated()
{
//Arrange
_updateUnitsEvent = new UpdatedUnitsEvent(); //Use the real event not a mock...
//Setup the Moq EventAggregator to return our event
_mockEventAggregator.Setup(x => x.GetEvent<UpdatedUnitsEvent>()).Returns(_updateUnitsEvent);
_mockUnits.Object.DensitySolid = DensitySolidSymbols.KgCm3;
_mockUnits.Object.Pressure = PressureSymbols.KPa;
//Act
_updateUnitsEvent.Publish(_mockUnits.Object); //Trigger the event by publishing our payload
//Assert
_mockEventAggregator.Verify(x => x.GetEvent<UpdatedUnitsEvent>(), Times.Once); //Verify using Moq
var currentItem = _materialMasterVm.MaterialModels.CurrentItem as MaterialDetailViewModel;//Check behavior
Assert.AreEqual(DensitySolidSymbols.KgCm3, currentItem.Density.UserUnitType);
Assert.AreEqual(PressureSymbols.KPa, currentItem.YieldStress.UserUnitType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment