예제 #1
0
        public void GetScooters_WhenCalled_ReturnsAllScooters()
        {
            var scooters = new List <Scooter>
            {
                new Scooter("id1", 1),
                new Scooter("id2", 2)
            };

            _scooterRepositoryMock.Setup(x => x.GetAll()).Returns(scooters);

            var result = _scooterService.GetScooters();

            _scooterRepositoryMock.Verify(x => x.GetAll());
            result.Should().BeSameAs(scooters);
        }
예제 #2
0
        public void GetAllScooters()
        {
            var scootersData = new GetAllScootersData();

            foreach (KeyValuePair <string, decimal> kvp in scootersData.Scooters)
            {
                _scooterService.AddScooter(kvp.Key, kvp.Value);
            }
            IList <Scooter> resultScooters = _scooterService.GetScooters();

            Assert.Equal(scootersData.Scooters.Count, resultScooters.Count);

            foreach (Scooter scooter in resultScooters)
            {
                Assert.True(scootersData.Scooters.ContainsKey(scooter.Id));
                Assert.Equal(scootersData.Scooters[scooter.Id], scooter.PricePerMinute);
            }
        }
        /// <inheritdoc />
        public decimal CalculateIncome(int?year, bool includeNotCompletedRentals)
        {
            var scooters = _scooterService.GetScooters();

            return(scooters.Sum(scooter =>
            {
                var rentals = _rentalService.GetRentalsByScooterId(scooter.Id).AsEnumerable();

                if (!includeNotCompletedRentals)
                {
                    rentals = rentals.Where(x => x.RentalEnd.HasValue);
                }

                if (year.HasValue)
                {
                    //this would raise a question for product owner - what should we count towards given year?
                    //I chose start because it's easiest
                    rentals = rentals.Where(x => x.RentalStart.Year.Equals(year));
                }

                return rentals.Sum(x =>
                                   _rentalCalculator.CalculateScooterRentalPrice(x.RentalStart, x.RentalEnd, scooter.PricePerMinute));
            }));
        }
예제 #4
0
 public void GetScooters_EmptyList_ThrowsExceptionEmptyList()
 {
     // Assert
     Assert.ThrowsException <EmptyHistoryException>(() => _scooterService.GetScooters());
 }
예제 #5
0
        public void GetScooters_ReturnsEmptyList()
        {
            var scooterList = service.GetScooters();

            scooterList.Should().BeEmpty();
        }