Example #1
0
        public async Task TestThat_GetShortestCoffeeShopDistances_When_NoExceptionThrown_Returns_ExpectedElementsCount()
        {
            // Arrange
            _userLocationRepositoryMock
            .Setup(x => x.GetUserLocation())
            .ReturnsAsync(MockObjects.UserLocation1);

            _coffeeShopLocationRepositoryMock
            .Setup(x => x.GetCoffeeShopLocations())
            .ReturnsAsync(MockObjects.ValidCoffeeShopLocations);

            _distanceCalculatorMock
            .Setup(x => x.CalculateDistanceToDestination(It.IsAny <Location>(), It.IsAny <Location>()))
            .ReturnsAsync(MockObjects.ShopDistance1);

            _distanceSelectorMock
            .Setup(x => x.SelectDistances(It.IsAny <IEnumerable <Distance> >()))
            .ReturnsAsync(MockObjects.SelectedShopDistances);

            var coffeeShopsQueryService = new CoffeeShopsQueryService(_queryFacadeMock.Object);

            // Act
            var distances = await coffeeShopsQueryService.GetShortestCoffeeShopDistances();

            // Assert
            Assert.Equal(MockValues.DefaultOutputDistancesCount, distances.Count());
        }
Example #2
0
        public async Task TestThat_GetShortestCoffeeShopDistances_When_DistanceSelectorThrowsArgumentOutOfRangeException_Throws_ArgumentOutOfRangeException()
        {
            // Arrange
            _distanceSelectorMock
            .Setup(x => x.SelectDistances(It.IsAny <IEnumerable <Distance> >()))
            .Throws <ArgumentOutOfRangeException>();

            var coffeeShopsQueryService = new CoffeeShopsQueryService(_queryFacadeMock.Object);

            // Act
            async Task Act() => await coffeeShopsQueryService.GetShortestCoffeeShopDistances();

            // Assert
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(Act);
        }
Example #3
0
        public async Task TestThat_GetShortestCoffeeShopDistances_When_CoffeeShopLocationRepositoryThrowsDataValidationException_Throws_DataValidationExceptionWithExpectedMessage()
        {
            // Arrange
            _coffeeShopLocationRepositoryMock
            .Setup(x => x.GetCoffeeShopLocations())
            .Throws(new DataValidationException(MockValues.CsvDataValidationExceptionMessage));

            var coffeeShopsQueryService = new CoffeeShopsQueryService(_queryFacadeMock.Object);

            // Act
            async Task Act() => await coffeeShopsQueryService.GetShortestCoffeeShopDistances();

            // Assert
            var exception = await Assert.ThrowsAsync <DataValidationException>(Act);

            Assert.Equal(MockValues.CsvDataValidationExceptionMessage, exception.Message);
        }
Example #4
0
        public async Task TestThat_GetShortestCoffeeShopDistances_When_DistanceCalculatorThrowsArgumentNullException_Throws_ArgumentNullException()
        {
            // Arrange
            _userLocationRepositoryMock
            .Setup(x => x.GetUserLocation())
            .ReturnsAsync(MockObjects.UserLocation1);

            _coffeeShopLocationRepositoryMock
            .Setup(x => x.GetCoffeeShopLocations())
            .ReturnsAsync(MockObjects.ValidCoffeeShopLocations);

            _distanceCalculatorMock
            .Setup(x => x.CalculateDistanceToDestination(It.IsAny <Location>(), It.IsAny <Location>()))
            .Throws <ArgumentNullException>();

            var coffeeShopsQueryService = new CoffeeShopsQueryService(_queryFacadeMock.Object);

            // Act
            async Task Act() => await coffeeShopsQueryService.GetShortestCoffeeShopDistances();

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(Act);
        }