public void LocationIdNotFoundReturnsNull() { // Arrange var locationId = "a"; var connectionSettings = new Mock <ILocationConnectionSettings>(); var query = new Mock <LocationRetrievalByIdQuery>(locationId); var dbAccess = new Mock <IDatabaseAccess>(); dbAccess .Setup(db => db.GetItemByIdAsync <MedicalExaminer.Models.Location>(connectionSettings.Object, It.IsAny <string>())) .Returns(Task.FromResult <MedicalExaminer.Models.Location>(null)) .Verifiable(); var sut = new LocationIdService(dbAccess.Object, connectionSettings.Object); var expected = default(MedicalExaminer.Models.Location); // Act var result = sut.Handle(query.Object); // Assert dbAccess.Verify( db => db.GetItemByIdAsync <MedicalExaminer.Models.Location>( connectionSettings.Object, It.IsAny <string>()), Times.Once); Assert.Equal(expected, result.Result); }
public void LocationIdIsNullThrowsException() { // Arrange var connectionSettings = new Mock <ILocationConnectionSettings>(); LocationRetrievalByIdQuery query = null; var dbAccess = new Mock <IDatabaseAccess>(); var sut = new LocationIdService(dbAccess.Object, connectionSettings.Object); // Act Action act = () => sut.Handle(query).GetAwaiter().GetResult(); act.Should().Throw <ArgumentNullException>(); }