Пример #1
0
        public async Task RentByWeekOk()
        {
            HttpConfiguration config = new HttpConfiguration();

            WebApiConfig.Register(config);
            using (HttpServer server = new HttpServer(config))
            {
                HttpClient client = new HttpClient(server);

                string url = "http://localhost/api/rental/RentByWeek";

                using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url))
                {
                    RentByWeekRequest rent = new RentByWeekRequest();
                    rent.Weeks      = 30;
                    request.Content = new StringContent(JsonConvert.SerializeObject(rent), Encoding.UTF8, "application/json");
                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        BikeRentalInvoice invoice = response.Content.ReadAsAsync <BikeRentalInvoice>().Result;

                        Assert.IsTrue(invoice.InvoiceId != null && invoice.ReturnDate != DateTime.MinValue && invoice.Total > 0);
                    }
                }
            }
        }
Пример #2
0
        public IHttpActionResult RentByWeek(RentByWeekRequest rentByWeekRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(Dao.RentByWeek(rentByWeekRequest)));
        }
Пример #3
0
        public BikeRentalInvoice RentByWeek(RentByWeekRequest rentByWeekRequest)
        {
            BikeRentalInvoice invoice = new BikeRentalInvoice();

            invoice.ReturnDate = CalculateReturnDate(rentByWeekRequest.Weeks, BikeRentalType.Week);
            invoice.Total      = CalculateTotal(rentByWeekRequest.Weeks, BikeRentalType.Week, 0);
            invoice.InvoiceId  = CreateInvoiceId();

            return(invoice);
        }
Пример #4
0
        public async Task RentByWeekBadRequest()
        {
            HttpConfiguration config = new HttpConfiguration();

            WebApiConfig.Register(config);
            using (HttpServer server = new HttpServer(config))
            {
                HttpClient client = new HttpClient(server);

                string url = "http://localhost/api/rental/RentByWeek";

                using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url))
                {
                    RentByWeekRequest rent = new RentByWeekRequest();
                    request.Content = new StringContent(JsonConvert.SerializeObject(rent), Encoding.UTF8, "application/json");
                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
                    }
                }
            }
        }
Пример #5
0
        public BikeRentalInvoice RentByFamily(RentByFamilyRequest rentByFamilyRequest)
        {
            BikeRentalInvoice invoice = new BikeRentalInvoice();

            BikeRentalType bikeRentalType;
            int            number;

            if (rentByFamilyRequest.RentByHourRequest != null)
            {
                RentByHourRequest rentByHourRequest = rentByFamilyRequest.RentByHourRequest;

                bikeRentalType = BikeRentalType.Hour;
                number         = rentByHourRequest.Hours;
            }
            else if (rentByFamilyRequest.RentByDayRequest != null)
            {
                RentByDayRequest rentByDayRequest = rentByFamilyRequest.RentByDayRequest;

                bikeRentalType = BikeRentalType.Day;
                number         = rentByDayRequest.Days;
            }
            else if (rentByFamilyRequest.RentByWeekRequest != null)
            {
                RentByWeekRequest rentByDayRequest = rentByFamilyRequest.RentByWeekRequest;

                bikeRentalType = BikeRentalType.Week;
                number         = rentByDayRequest.Weeks;
            }
            else
            {
                throw new NotImplementedException();
            }

            invoice.ReturnDate = CalculateReturnDate(number, bikeRentalType);
            invoice.Total      = CalculateTotal(number, bikeRentalType, FamilyDiscountPercent);
            invoice.InvoiceId  = CreateInvoiceId();
            return(invoice);
        }