public async void ConfirmSpotBooked_ExpectedTrue_Success()
        {
            using (var context = Fixture.CreateContext())
            {
                // arrange
                bool spotsCreated = await GenerateBookingData.CreateBookingWithOneSpot() != null;

                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);
                IPDFService <Booking> pDFService         = new BookingPDFService();
                IBookingService       bookingService     = new BookingService(context, service, null, pDFService, null);
                IMarinaOwnerService   marinaOwnerService = new MarinaOwnerService(context, service);

                // act
                var unconfirmedBookingLines = (List <BookingLine>) await marinaOwnerService.GetUnconfirmedBookingLines(1);

                bool actual = await bookingService.ConfirmSpotBooked(unconfirmedBookingLines.First().BookingLineId);

                // assert
                Assert.True(spotsCreated);
                Assert.Equal(expected, actual);
            }
        }
        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 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);
                }
            }
        }