public async Task TestThat_GetUserLocation_When_DataReaderReturnsItems_Returns_NotNullLocation() { // Arrange var dataReaderMock = new Mock <IUserLocationDataReader>(); dataReaderMock .Setup(x => x.ReadUserLocation()) .ReturnsAsync(MockObjects.UserLocation1); var userLocationRepository = new UserLocationRepository(dataReaderMock.Object); // Act var location = await userLocationRepository.GetUserLocation(); // Assert Assert.NotNull(location); }
public async Task TestThat_GetUserLocation_When_DataReaderThrowsDataProviderException_Throws_DataProviderExceptionWithExpectedMessage() { // Arrange var dataReaderMock = new Mock <IUserLocationDataReader>(); dataReaderMock .Setup(x => x.ReadUserLocation()) .Throws(new DataProviderException(MockValues.UserLocationDataProviderExceptionMessage)); var userLocationRepository = new UserLocationRepository(dataReaderMock.Object); // Act async Task Act() => await userLocationRepository.GetUserLocation(); // Assert var exception = await Assert.ThrowsAsync <DataProviderException>(Act); Assert.Equal(MockValues.UserLocationDataProviderExceptionMessage, exception.Message); }
public async Task TestThat_GetUserLocation_When_DataReaderReturnsItems_Returns_LocationWithExpectedValues() { // Arrange var mockLocation = MockObjects.UserLocation1; var dataReaderMock = new Mock <IUserLocationDataReader>(); dataReaderMock .Setup(x => x.ReadUserLocation()) .ReturnsAsync(mockLocation); var userLocationRepository = new UserLocationRepository(dataReaderMock.Object); // Act var location = await userLocationRepository.GetUserLocation(); // Assert Assert.Equal(mockLocation.X, location.X); Assert.Equal(mockLocation.Y, location.Y); Assert.Equal(mockLocation.Tag, location.Tag); }