public async Task RentByDayOk() { HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); using (HttpServer server = new HttpServer(config)) { HttpClient client = new HttpClient(server); string url = "http://localhost/api/rental/RentByDay"; using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url)) { RentByDayRequest rent = new RentByDayRequest(); rent.Days = 4; 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); } } } }
public BikeRentalInvoice RentByDay(RentByDayRequest rentByDayRequest) { BikeRentalInvoice invoice = new BikeRentalInvoice(); invoice.ReturnDate = CalculateReturnDate(rentByDayRequest.Days, BikeRentalType.Day); invoice.Total = CalculateTotal(rentByDayRequest.Days, BikeRentalType.Day, 0); invoice.InvoiceId = CreateInvoiceId(); return(invoice); }
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); }
public BikeRentalInvoice RentByHour(RentByHourRequest rentByHourRequest) { BikeRentalInvoice invoice = new BikeRentalInvoice(); invoice.ReturnDate = CalculateReturnDate(rentByHourRequest.Hours, BikeRentalType.Hour); invoice.Total = CalculateTotal(rentByHourRequest.Hours, BikeRentalType.Hour, 0); invoice.InvoiceId = CreateInvoiceId(); return(invoice); }
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); }