public async Task <IActionResult> Edit(int?id) { try { var marinaTask = _marinaService.GetSingle(id); var marina = await marinaTask; var isAuthorized = await _authorizationService.AuthorizeAsync(User, marina, Operation.Update); if (!isAuthorized.Succeeded) { return(Forbid()); } var marinaCopy = new Marina { Name = marina.Name, Description = marina.Description, Facilities = marina.Facilities, Location = marina.Location, LocationId = marina.LocationId, MarinaOwnerId = marina.MarinaOwnerId }; marinaTask.Dispose(); return(View(marinaCopy)); } catch (BusinessException exception) { Console.WriteLine(exception); throw; } }
/// <summary> /// Calculate a marina's location based on the locations that its spots have, if it has any. /// </summary> /// <remarks> /// Uses a algorithm in order to determine the smallest enclosing circle of a number of points. /// </remarks> /// <param name="marina"></param> public static void CalculateMarinaLocation(Marina marina) { if (marina is not null) { if (MarinaSpotsHaveLocations(marina)) { var locations = new List <Point>(); // Verify for spots with locations once again // (When the method gets called it is made sure that the spots inside have a valid location, but let's verify again) marina.Spots .FindAll(spot => spot.LocationId.IsValidId()) .ForEach(spot => locations.Add(new Point(spot.Location.Latitude, spot.Location.Longitude))); Circle circle = SmallestEnclosingCircle.MakeCircle(locations); if (circle.r * 8000 < 10000) { circle.r = 10; } Location marinaLocation = new Location { Latitude = circle.c.x, Longitude = circle.c.y, Radius = circle.r, }; marina.Location = marinaLocation; } } }
public async Task <Marina> GetMarinaById(int?marinaId) { var result = string.Empty; var marinaResult = new Marina(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(this.marinaServiceBase); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var urlAddress = marinaServiceBase + marinaId; HttpResponseMessage response = await client.GetAsync(urlAddress).ConfigureAwait(continueOnCapturedContext: false); if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsStringAsync(); } try { marinaResult = JsonConvert.DeserializeObject <Marina>(result); } catch (Exception e) { throw new Exception($"Error: {e.StackTrace}"); } } return(marinaResult); }
public async Task <int> Create(Marina marina) { marina.ThrowIfNull(); await _context.AddAsync(marina); return(marina.MarinaId); }
public Marina Update(Marina marina) { marina.ThrowIfNull(); _context.Update(marina); return(marina); }
public Marina UpdateMarinaLocation(Marina marina, Location location) { marina.ThrowIfNull(); location.ThrowIfNull(); _locationService.Update(location); return(marina); }
public IActionResult Create(string marinaName, string phone, string email, double depth, string cityName, string country, string zipCodeNumber, int totalBerths, int isShower, int isToilet, int isInternet, int isPharmacy, int isElectricity, int isRepairing, int isStore, int isTelephone, int isHotel, int isCafeteria, string description, decimal latitude, decimal longtitude) { Marina marina = new Marina() { MarinaName = marinaName, Phone = phone, Email = email, Depth = depth, CityName = cityName, Country = country, ZipCodeNumber = zipCodeNumber, TotalBerths = totalBerths, IsShower = isShower, IsToilet = isToilet, IsInternet = isInternet, IsPharmacy = isPharmacy, IsElectricity = isElectricity, IsRepairing = isRepairing, IsStore = isStore, IsTelephone = isTelephone, IsHotel = isHotel, IsCafeteria = isCafeteria, Description = description, Latitude = latitude, Longtitude = longtitude }; bookMarinaClient.CreateMarina(marina); return(RedirectToAction("Index", "Marina")); }
public async Task <Marina> DeleteMarinaLocation(Marina marina) { marina = await GetSingle(marina.MarinaId); marina.ThrowIfNull(); marina.LocationId.ThrowIfInvalidId(); await _locationService.Delete(marina.LocationId); return(marina); }
public void testGetMarinaCapacity() { //arrange int expected = 51; //act' MarinaMaintenanceObj MarinaMaintenance_Obj = new MarinaMaintenanceObj(); Marina Marina = new Marina(); Marina._LoadDataFromFile(); Assert.AreEqual(expected, Marina.getCurrentCapacityMarinaLength()); }
public async Task <int> CreateLocationForMarina(Marina marina, Location location) { marina.ThrowIfNull(); location.ThrowIfNull(); // Create location for marina and take the Id await _locationService.Create(location); // Assign location to marina marina.Location = location; return(marina.MarinaId); }
public static bool MarinaSpotsHaveLocations(Marina marina) { marina.ThrowIfNull(); foreach (Spot spot in marina.Spots) { if (spot.LocationId.IsValidId()) { return(true); } } return(false); }
public async Task <ActionResult <Marina> > PostSpot(Marina marina) { if (marina.MarinaId != 0 || marina.Location?.LocationId != 0) { BadRequest("Do not set the ID"); } await _marinaService.Create(marina); await _marinaService.Save(); return(CreatedAtAction("GetSpot", new { id = marina.MarinaId }, marina)); }
public async void CreateMarina(Marina marina) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(this.marinaServiceBase); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var json = JsonConvert.SerializeObject(marina); HttpResponseMessage response = await client.PostAsync(marinaServiceBase, new StringContent(json, Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); } }
public async Task <int> CreateWithLocation(Marina marina, Location location) { marina.ThrowIfNull(); location.ThrowIfNull(); // Create location for marina await _locationService.Create(location); // Create marina await Create(marina); // Assign location to marina marina.Location = location; return(marina.MarinaId); }
public async void GetBookingsByMarinOwner_Expected2_Pass() { using (var context = Fixture.CreateContext()) { bool expected = true; IBookingService bookingService = new BookingService(context, null, null, null, null); Marina marina = context.Marinas.Find(1); MarinaOwner marinaOwner = context.MarinaOwners.Where(mo => mo.MarinaOwnerId == marina.MarinaOwnerId).FirstOrDefault(); bool spotsCreated = await GenerateBookingData.CreateBookingWithTwoSpotsInSameMarina() != null; var marinaOwnerBookings = (List <BookingLine>) await bookingService.GetBookingLines(marinaOwner.MarinaOwnerId); bool actual = marinaOwnerBookings == null ? false : marinaOwnerBookings.Count > 0 ? true : false; Assert.True(spotsCreated); Assert.Equal(expected, actual); } }
public async Task <IActionResult> Edit(int id, [Bind("MarinaOwnerId, Name, Description, Facilities, LocationId")] Marina marina) { marina.MarinaId = id; try { var isAuthorized = await _authorizationService.AuthorizeAsync(User, marina, Operation.Update); if (!isAuthorized.Succeeded) { Forbid(); } if (!ModelState.IsValid) { return(View(marina)); } if (MarinaLocationIsSelected()) { var marinaLocation = GetLocationFormData(); _marinaService.UpdateMarinaLocation(marina, marinaLocation); await _marinaService.CreateLocationForMarina(marina, marinaLocation); } else { marina = await _marinaService.DeleteMarinaLocation(marina); } _marinaService.Update(marina); await _marinaService.Save(); return(RedirectToAction(nameof(Index))); } catch (BusinessException exception) { Console.WriteLine(exception); throw; } }
public void deleteBooking() { //arrange int indexOfBoat = 1; int expectedRowCount = 2; //act MarinaMaintenanceObj MarinaMaintenance_Obj = new MarinaMaintenanceObj(); Marina Marina = new Marina(); FileOperations FP = new FileOperations(); Marina._LoadDataFromFile(); Marina.DeleteBoat(indexOfBoat); int actual = FP.readDataFromFile().Count; //assert Assert.AreEqual(expectedRowCount, actual); }
public Marina GetMarinaById(int id) { var marinaById = new Marina(); using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand(Queries.GetMarinaById, conn); cmd.Parameters.Add("@id", MySqlDbType.Int16).Value = id; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { marinaById.MarinaId = Convert.ToInt32(reader["MarinaId"]); marinaById.MarinaName = reader["MarinaName"].ToString(); marinaById.Phone = reader["Phone"].ToString(); marinaById.Email = reader["Email"].ToString(); marinaById.Depth = Convert.ToDouble(reader["Depth"]); marinaById.CityName = reader["CityName"].ToString(); marinaById.Country = reader["Country"].ToString(); marinaById.ZipCodeNumber = reader["ZipCodeNumber"].ToString(); marinaById.TotalBerths = Convert.ToInt32(reader["TotalBerths"]); marinaById.IsToilet = Convert.ToInt32(reader["IsToilet"]); marinaById.IsShower = Convert.ToInt32(reader["IsShower"]); marinaById.IsInternet = Convert.ToInt32(reader["IsInternet"]); marinaById.IsPharmacy = Convert.ToInt32(reader["IsPharmacy"]); marinaById.IsElectricity = Convert.ToInt32(reader["IsElectricity"]); marinaById.IsRepairing = Convert.ToInt32(reader["IsRepairing"]); marinaById.IsStore = Convert.ToInt32(reader["IsStore"]); marinaById.IsTelephone = Convert.ToInt32(reader["IsTelephone"]); marinaById.IsHotel = Convert.ToInt32(reader["IsHotel"]); marinaById.IsCafeteria = Convert.ToInt32(reader["IsCafeteria"]); marinaById.Description = reader["Description"].ToString(); marinaById.Latitude = Convert.ToDecimal(reader["Latitude"]); marinaById.Longtitude = Convert.ToDecimal(reader["Longtitude"]); } } } return(marinaById); }
static void Main(string[] args) { Garage parking = new Garage(100); Car Audi = new Car { Make = CarModel.Audi, Model = "A4", Fuel = FuelType.Diesel }; Car BMW = new Car { Make = CarModel.BMW, Model = "X1", Fuel = FuelType.Petrol }; Car Skoda = new Car { Make = CarModel.Skoda, Model = "Fabia", Fuel = FuelType.LPG }; Airport airport = new Airport(20); Airplane Boeing = new Airplane { AirplaneModel = "Boeing", AirplaneType = AirplaneType.Combat }; Airplane WizzPlane = new Airplane { AirplaneModel = "WizzAirPlane", AirplaneType = AirplaneType.Civil }; Marina marina = new Marina(10); Boat sailboat = new Boat { BoatName = "Whistle", BoatType = BoatType.Sailboat }; parking.ParkTheVehicle(Audi); parking.ParkTheVehicle(BMW); parking.ParkTheVehicle(Skoda); airport.ParkTheAirplane(Boeing); airport.ParkTheAirplane(WizzPlane); marina.ParkTheVehicle(sailboat); parking.LeaveParking(Audi); airport.LeaveAirport(WizzPlane); }
public async void GetUnconfirmedBookingLines_Pass() { using (var context = Fixture.CreateContext()) { bool expected = true; ILocationService locationService = new LocationService(context); IMarinaService marinaService = new MarinaService(context, locationService); IBookingFormService bookingFormService = new BookingFormService(context, marinaService); IBookingLineService service = new BookingLineService(context, bookingFormService); IMarinaOwnerService marinaOwnerService = new MarinaOwnerService(context, service); Marina marina = context.Marinas.Find(1); MarinaOwner marinaOwner = context.MarinaOwners.Where(mo => mo.MarinaOwnerId == marina.MarinaOwnerId).FirstOrDefault(); bool spotsCreated = await GenerateBookingData.CreateBookingWithTwoSpotsInSameMarina() != null; var spotsToConfirm = (List <BookingLine>) await marinaOwnerService.GetUnconfirmedBookingLines(marinaOwner.MarinaOwnerId); bool actual = spotsToConfirm == null ? false : spotsToConfirm.Count > 0 ? true : false; Assert.True(spotsCreated); Assert.Equal(expected, actual); } }
public async Task <IActionResult> Create([Bind("Name, Description, Facilities")] Marina marina) { try { // Reload the page if the model is invalid if (!ModelState.IsValid) { return(View(marina)); } // Set the marina's marinaOwner id to logged user var person = await _userManager.GetUserAsync(User); var marinaOwnerId = _userService.GetMarinaOwnerFromPerson(person).MarinaOwnerId; marina.MarinaOwnerId = marinaOwnerId; if (MarinaLocationIsSelected()) { var marinaLocation = GetLocationFormData(); await _marinaService.CreateWithLocation(marina, marinaLocation); } else { await _marinaService.Create(marina); } await _marinaService.Save(); // Return to index if successful return(RedirectToAction(nameof(Index))); } catch (BusinessException exception) { Console.WriteLine(exception); throw; } }
public void createBoatTest() { NarrowBoat NB = new NarrowBoat(); NB.BoatDraft = 3; NB.BoatLength = 15; NB.NameOfBoat = "Phantom Menance"; NB.NameOfOwner = "Anakin Skywalker"; MarinaMaintenanceObj MarinaMaintenance_Obj = new MarinaMaintenanceObj(); Marina Marina = new Marina(); Marina.ClearAllMarinaItems(); //add new boat to marina Marina.addBoatToMarina(NB); List <string> listData = new List <string>(); listData = Marina.convertMarinaToList(); //write to file FileOperations FP = new FileOperations(); FP.writeToFile(listData); int index = Marina.getCurrentCapacityMarinaLength(); List <string> list = new List <string>(); list = FP.readDataFromFile(); string nameOflastBoatInList = list.Last(); //split array at commas and put result into an array string[] arrSplitRow = nameOflastBoatInList.Split(",".ToCharArray()); string actual = arrSplitRow[1]; Assert.AreEqual(actual.ToUpper(), NB.NameOfOwner.ToUpper()); }
public void CreateMarina(Marina marina) { try { using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand(Queries.CreateMarina, conn); cmd.Parameters.Add("@marinaName", MySqlDbType.VarChar).Value = marina.MarinaName; cmd.Parameters.Add("@phone", MySqlDbType.VarChar).Value = marina.Phone; cmd.Parameters.Add("@email", MySqlDbType.VarChar).Value = marina.Email; cmd.Parameters.Add("@depth", MySqlDbType.Double).Value = marina.Depth; cmd.Parameters.Add("@cityName", MySqlDbType.VarChar).Value = marina.CityName; cmd.Parameters.Add("@country", MySqlDbType.VarChar).Value = marina.Country; cmd.Parameters.Add("@zipCodeNumber", MySqlDbType.VarChar).Value = marina.ZipCodeNumber; cmd.Parameters.Add("@totalBerths", MySqlDbType.Int32).Value = marina.TotalBerths; cmd.Parameters.Add("@isToilet", MySqlDbType.Int32).Value = marina.IsToilet; cmd.Parameters.Add("@isShower", MySqlDbType.Int32).Value = marina.IsShower; cmd.Parameters.Add("@isInternet", MySqlDbType.Int32).Value = marina.IsInternet; cmd.Parameters.Add("@isElectricity", MySqlDbType.Int32).Value = marina.IsElectricity; cmd.Parameters.Add("@isRepairing", MySqlDbType.Int32).Value = marina.IsRepairing; cmd.Parameters.Add("@isStore", MySqlDbType.Int32).Value = marina.IsStore; cmd.Parameters.Add("@isTelephone", MySqlDbType.Int32).Value = marina.IsTelephone; cmd.Parameters.Add("@isHotel", MySqlDbType.Int32).Value = marina.IsHotel; cmd.Parameters.Add("@isCafeteria", MySqlDbType.Int32).Value = marina.IsCafeteria; cmd.Parameters.Add("@description", MySqlDbType.Text).Value = marina.Description; cmd.Parameters.Add("@latitude", MySqlDbType.Decimal).Value = marina.Latitude; cmd.Parameters.Add("@longtitude", MySqlDbType.Decimal).Value = marina.Longtitude; cmd.ExecuteReader(); } } catch (Exception e) { } }
public async Task <IActionResult> PutMarina(int id, Marina marina) { if (id != marina.MarinaId) { return(BadRequest()); } var isAuthorized = await _authorizationService.AuthorizeAsync(User, marina, Operation.Update); if (isAuthorized.Succeeded) { _marinaService.Update(marina); try { await _marinaService.Save(); } catch (BusinessException ex) { BadRequest(ex); } } return(NoContent()); }
public static void SeedDb(SportsContext context) { //TODO: Remove in Release :) context.Database.EnsureDeleted(); context.Database.EnsureCreated(); //TODO: Add seed data or use NMockaroo //Insert data into the database if there aren't any in the specific table if (!context.Addresses.Any()) { var addresses = new Address[] { new Address { Street = "Amazing Drive", City = "Aalborg", Country = "DK", State = "DK" }, new Address { Street = "Not so Amazing Drive", City = "Copenhagen", Country = "DK", State = "DK" }, new Address { City = "Aalborg", Street = "Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, new Address { City = "Aarhus", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, new Address { City = "Copenhagen", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, new Address { City = "Esbjerg", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, }; context.Addresses.AddRange(addresses); context.SaveChanges(); } if (!context.Locations.Any()) { var locations = new Location[] { new Location { Latitude = 55.724478044067006, Longitude = 12.60262191295624 }, new Location { Latitude = 57.058790791383466, Longitude = 9.895803630352022 }, new Location { Latitude = 57.05889288811736, Longitude = 9.895127713680269 }, }; context.Locations.AddRange(locations); context.SaveChanges(); } if (!context.Persons.Any()) { var persons = new Person[] { new Person { FirstName = "Bartosz", LastName = "Urban", Email = "*****@*****.**", AddressId = 1 }, new Person { FirstName = "Dragos", LastName = "Ionescu", Email = "*****@*****.**", AddressId = 1 }, new Person { FirstName = "Peter", LastName = "Boelt", Email = "*****@*****.**", AddressId = 2 }, new Person { FirstName = "Zach", LastName = "Horatau", Email = "*****@*****.**", AddressId = 2 } }; context.Persons.AddRange(persons); context.SaveChanges(); } if (!context.MarinaOwners.Any()) { var marinaOwners = new MarinaOwner[] { new MarinaOwner { PersonId = 1 }, new MarinaOwner { PersonId = 2 }, new MarinaOwner { PersonId = 3 }, new MarinaOwner { PersonId = 4 }, }; context.MarinaOwners.AddRange(marinaOwners); context.SaveChanges(); } if (!context.Marinas.Any()) { var marinas = new Marina[] { new Marina { Name = "Aalborg Marina", MarinaOwnerId = 1, Description = "Coolest marina", Facilities = "none", AddressId = 1 }, new Marina { Name = "Aarhus Marina", MarinaOwnerId = 2, Description = "Some marina", Facilities = "none", AddressId = 2 }, new Marina { Name = "Copenhagen Marina", MarinaOwnerId = 3, Description = "Some marina", Facilities = "none", AddressId = 3 }, new Marina { Name = "Esbjerg Marina", MarinaOwnerId = 1, Description = "Some marina", Facilities = "none", AddressId = 4 }, }; context.Marinas.AddRange(marinas); context.SaveChanges(); } if (!context.BoatOwners.Any()) { var boatOwners = new BoatOwner[] { new BoatOwner { PersonId = 3 }, new BoatOwner { PersonId = 4 } }; context.BoatOwners.AddRange(boatOwners); context.SaveChanges(); } if (!context.Boats.Any()) { var boats = new Boat[] { new Boat { Name = "Titanic", BoatOwnerId = 1, Depth = 2, Length = 5, Width = 3 }, new Boat { Name = "Mama Destroyer", BoatOwnerId = 2, Depth = 5, Length = 20, Width = 9 }, }; context.Boats.AddRange(boats); context.SaveChanges(); } if (!context.Spots.Any()) { var spots = new Spot[] { new Spot { SpotNumber = 1, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 10, MaxLength = 30 }, new Spot { SpotNumber = 2, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 }, new Spot { SpotNumber = 3, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 }, new Spot { SpotNumber = 4, MarinaId = 2, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 3 }, new Spot { SpotNumber = 5, MarinaId = 3, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 }, new Spot { SpotNumber = 1, MarinaId = 4, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 1 }, new Spot { SpotNumber = 2, MarinaId = 4, Available = true, Price = 40.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 2 }, new Spot { SpotNumber = 3, MarinaId = 4, Available = true, Price = 30.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 } }; context.Spots.AddRange(spots); context.SaveChanges(); } if (!context.Bookings.Any()) { var bookings = new Booking[] { new Booking { BookingReferenceNo = 1, BoatId = 1, TotalPrice = 2, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 2, BoatId = 1, TotalPrice = 10, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 3, BoatId = 1, TotalPrice = 100, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 4, BoatId = 2, TotalPrice = 83, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 5, BoatId = 2, TotalPrice = 97, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 6, BoatId = 2, TotalPrice = 23, PaymentStatus = "not paid", CreationDate = DateTime.Now } }; context.Bookings.AddRange(bookings); context.SaveChanges(); } if (!context.BookingLines.Any()) { var bookingLines = new BookingLine[] { // Ongoing: True new BookingLine { Ongoing = true, BookingId = 1, SpotId = 1, DiscountedTotalPrice = 1, Confirmed = true, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1) }, new BookingLine { Ongoing = false, BookingId = 1, SpotId = 2, DiscountedTotalPrice = 2, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1) }, new BookingLine { Ongoing = false, BookingId = 1, SpotId = 3, DiscountedTotalPrice = 3, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4) }, // Ongoing: False new BookingLine { Ongoing = false, BookingId = 2, SpotId = 1, DiscountedTotalPrice = 4, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4) }, new BookingLine { Ongoing = false, BookingId = 2, SpotId = 2, DiscountedTotalPrice = 5, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4) }, new BookingLine { Ongoing = false, BookingId = 2, SpotId = 3, DiscountedTotalPrice = 6, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, // Ongoing: False new BookingLine { Ongoing = false, BookingId = 3, SpotId = 1, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, new BookingLine { Ongoing = false, BookingId = 3, SpotId = 2, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, new BookingLine { Ongoing = false, BookingId = 3, SpotId = 3, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, // Ongoing: False new BookingLine { Ongoing = false, BookingId = 4, SpotId = 1, DiscountedTotalPrice = 19, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15) }, new BookingLine { Ongoing = false, BookingId = 4, SpotId = 2, DiscountedTotalPrice = 11, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15) }, new BookingLine { Ongoing = false, BookingId = 4, SpotId = 3, DiscountedTotalPrice = 17, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15) }, // Ongoing: True new BookingLine { Ongoing = true, BookingId = 5, SpotId = 1, DiscountedTotalPrice = 15, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25) }, new BookingLine { Ongoing = true, BookingId = 5, SpotId = 3, DiscountedTotalPrice = 16, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25) }, new BookingLine { Ongoing = true, BookingId = 5, SpotId = 2, DiscountedTotalPrice = 14, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25) }, // Ongoing: True new BookingLine { Ongoing = false, BookingId = 6, SpotId = 1, DiscountedTotalPrice = 12 }, new BookingLine { Ongoing = true, BookingId = 6, SpotId = 2, DiscountedTotalPrice = 13 }, new BookingLine { Ongoing = true, BookingId = 6, SpotId = 5, DiscountedTotalPrice = 14 } }; context.BookingLines.AddRange(bookingLines); context.SaveChanges(); } }
public async void GetAllAvailableSpotsCount() { using (var transaction = Fixture.Connection.BeginTransaction()) { using (var context = Fixture.CreateContext(transaction)) { // Arrange var locationService = new LocationService(context); var marinaService = new MarinaService(context, locationService); var service = new BookingFormService(context, marinaService); List <BookingLine> bookingLines1 = new List <BookingLine> { new BookingLine { StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(5), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(6), EndDate = DateTime.Now.AddDays(9), BookingId = 1 }, }; List <BookingLine> bookingLines2 = new List <BookingLine> { new BookingLine { StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(5), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(6), EndDate = DateTime.Now.AddDays(9), BookingId = 1 }, }; List <BookingLine> bookingLines3 = new List <BookingLine> { new BookingLine { StartDate = DateTime.Now.AddDays(8), EndDate = DateTime.Now.AddDays(12), BookingId = 1 }, }; List <Spot> spots = new List <Spot> { new Spot { SpotNumber = 1, MarinaId = 1, MaxDepth = 10, MaxLength = 20, MaxWidth = 30, BookingLines = bookingLines1, Available = true }, new Spot { SpotNumber = 2, MarinaId = 1, MaxDepth = 30, MaxLength = 40, MaxWidth = 30, BookingLines = bookingLines2, Available = true }, new Spot { SpotNumber = 3, MarinaId = 1, MaxDepth = 30, MaxLength = 30, MaxWidth = 30, BookingLines = bookingLines3, Available = true } }; List <Spot> spots2 = new List <Spot> { new Spot { SpotNumber = 1, MarinaId = 1, MaxDepth = 10, MaxLength = 20, MaxWidth = 30, BookingLines = bookingLines1, Available = true }, new Spot { SpotNumber = 2, MarinaId = 1, MaxDepth = 30, MaxLength = 40, MaxWidth = 30, BookingLines = bookingLines2, Available = true }, new Spot { SpotNumber = 3, MarinaId = 1, MaxDepth = 30, MaxLength = 30, MaxWidth = 30, BookingLines = bookingLines3, Available = true } }; Marina marina = new Marina { Name = "Hello", Spots = spots, MarinaOwnerId = 1 }; Marina marina2 = new Marina { Name = "Better Marina", Spots = spots2, MarinaOwnerId = 1 }; Boat boat = new Boat { Depth = 30, Length = 30, Width = 30, BoatOwnerId = 1 }; DateTime startDate = DateTime.Now; DateTime endDate = DateTime.Now.AddDays(1); context.AddRange(spots); context.AddRange(spots2); context.Add(marina); context.Add(marina2); context.Add(boat); context.SaveChanges(); // Act var result = await service.GetAllAvailableSpotsCount( new List <int> { marina.MarinaId, marina2.MarinaId }, boat.BoatId, startDate, endDate); // Assert Assert.NotNull(result); output.WriteLine(HelperMethods.Serialize(result)); } } }
public async void GetAvailableSpots_FoundOne() { using (var transaction = Fixture.Connection.BeginTransaction()) { using (var context = Fixture.CreateContext(transaction)) { // Arrange var locationService = new LocationService(context); var marinaService = new MarinaService(context, locationService); var service = new BookingFormService(context, marinaService); List <BookingLine> bookingLines1 = new List <BookingLine> { new BookingLine { StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(5), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(6), EndDate = DateTime.Now.AddDays(9), BookingId = 1 }, }; List <BookingLine> bookingLines2 = new List <BookingLine> { new BookingLine { StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(5), BookingId = 1 }, new BookingLine { StartDate = DateTime.Now.AddDays(6), EndDate = DateTime.Now.AddDays(9), BookingId = 1 }, }; List <BookingLine> bookingLines3 = new List <BookingLine> { new BookingLine { StartDate = DateTime.Now.AddDays(8), EndDate = DateTime.Now.AddDays(12), BookingId = 1 }, }; List <Spot> spots = new List <Spot> { new Spot { SpotNumber = 1, MarinaId = 1, MaxDepth = 10, MaxLength = 20, MaxWidth = 30, BookingLines = bookingLines1, Available = true }, new Spot { SpotNumber = 2, MarinaId = 1, MaxDepth = 30, MaxLength = 40, MaxWidth = 30, BookingLines = bookingLines2, Available = true }, new Spot { SpotNumber = 3, MarinaId = 1, MaxDepth = 30, MaxLength = 30, MaxWidth = 30, BookingLines = bookingLines3, Available = true } }; Marina marina = new Marina { Name = "Hello", Spots = spots, MarinaOwnerId = 1 }; Boat boat = new Boat { Depth = 1, Length = 2, Width = 3, BoatOwnerId = 1 }; DateTime startDate = DateTime.Now.AddDays(3); DateTime endDate = DateTime.Now.AddDays(4); context.AddRange(spots); context.Add(marina); context.Add(boat); context.SaveChanges(); // Act var result = await service.GetAvailableSpots( marina.MarinaId, boat.BoatId, startDate, endDate); // Assert Assert.NotNull(result); //Assert.Single(result); Assert.Equal(1, result.First().SpotNumber); } } }
public void Post([FromBody] Marina marina) { IMarinaRepository repository = HttpContext.RequestServices.GetService(typeof(MarinaRepository)) as MarinaRepository; repository.CreateMarina(marina); }