Example #1
0
        public void TestCalculate_WhenValidDimensions_ExpectCheapestEstimation(
            ParcelDimensions dimensions,
            CostEstimation expectedEstimation)
        {
            // Arrange
            var dimensionsCollection = new[] { dimensions };

            // Act
            var result = _service.Calculate(dimensionsCollection);

            // Assert
            Assert.Equal(expectedEstimation, result);
        }
Example #2
0
        public async Task <ActionResult <Rental> > EndRental(int id)
        {
            var rental = await _context.Rentals.FindAsync(id);

            if (rental is null)
            {
                return(NotFound());
            }

            if (rental.RentalEnd != default)
            {
                return(BadRequest());
            }

            using var transaction = _context.Database.BeginTransaction();

            rental.RentalEnd        = DateTime.Now;
            rental.TotalRentalCosts = _calculator.Calculate(
                rental.RentalBegin,
                rental.RentalEnd.GetValueOrDefault(),
                rental.RentedBike.RentalPriceFirstHour,
                rental.RentedBike.RentalPriceAdditionalHours
                );

            _context.Entry(rental).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            await transaction.CommitAsync();

            return(rental);
        }
            public async Task <HandlerResult <IEnumerable <ProductDto> > > Handle(Command request, CancellationToken cancellationToken)
            {
                var products = _productRepository.GetProducts()
                               .Select(product =>
                {
                    return(new ProductDto
                    {
                        Name = product.Name,
                        AnnualCosts = _costCalculator.Calculate(product, request.Consumption)
                    });
                })
                               .OrderBy(product => product.AnnualCosts)
                               .AsEnumerable();

                return(products == null
                    ? HandlerResult.EntityNotFound <IEnumerable <ProductDto> >()
                    : HandlerResult.Ok(products));
            }
Example #4
0
        private static void CalculateRentTest()
        {
            Write("Podaj imiÄ™: ");
            string firstName = ReadLine();

            Write("Podaj nazwisko: ");
            string lastName = ReadLine();

            var rentee = new Man();

            rentee.FirstName = firstName;
            rentee.LastName  = lastName;

            Product item = new CrossCountrySki
            {
                Id           = 1,
                PricePerHour = 50,
                Name         = "Fisher",
                Size         = 150,
            };

            var rent = new Rent(rentee, item)
            {
                Id = 1,
            };

            // zwrot

            Thread.Sleep(TimeSpan.FromSeconds(1));

            rent.Return();

            ICalculatorFactory calculatorFactory = new CalculatorFactory();

            ICostCalculator calculator = calculatorFactory.Create(rent);

            rent.Cost = calculator.Calculate(rent);
        }
Example #5
0
        public void CorrectCalculations(decimal consumption, ProductType productType, decimal result)
        {
            var product = new Product(string.Empty, productType);

            Assert.Equal(result, CostCalculator.Calculate(product, consumption));
        }