コード例 #1
0
        public void ValidGetHotelByIdShouldGetSpecifiedHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetHotelByIdShouldGetSpecifiedHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var   hotelService = new ReviewService(context);
                Hotel hotel        = new Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                hotel.Id = 1;
                hotelService.Create(hotel);
                context.Entry(hotel).State = EntityState.Detached;

                Assert.AreEqual(hotelService.GetHotelById(1).HotelName, "Transilvania Hotel");
            }
        }
コード例 #2
0
        public void UpdateShouldUpdateExistingHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpdateShouldUpdateExistingHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var addedHotel   = hotelService.Create(new HotelBooking.Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10
                        }
                    }
                });


                context.Entry(addedHotel).State = EntityState.Detached;
                Assert.AreEqual("Transilvania Hotel", addedHotel.HotelName);
                addedHotel.HotelName = "updated hotel";
                var updatedHotel = hotelService.Update(addedHotel.Id, addedHotel);
                Assert.AreEqual("updated hotel", updatedHotel.HotelName);
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            using (var context = new BookingsDbContext())
            {
                var totalCheckins = context.Bookings
                                    .Count(b => b.From == DateTime.Today);

                var totalCheckouts = context.Bookings
                                     .Count(b => b.To == DateTime.Today);

                var summary = new RegistrationDaySummary
                {
                    Date      = DateTime.Today,
                    CheckIns  = totalCheckins,
                    CheckOuts = totalCheckouts
                };

                Checkins.InnerText  = summary.CheckIns.ToString();
                Checkouts.InnerText = summary.CheckOuts.ToString();

                Clock.Text = DateTime.Now.ToShortTimeString();
            }
        }
コード例 #4
0
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _commandHandler             = new AddCasesToHearingCommandHandler(context);
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(context);
        }
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _commandHandler             = new RemoveParticipantFromHearingCommandHandler(context);
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(context);
        }
コード例 #6
0
        public async Task SendBookingListInfo()
        {
            using (var db = new BookingsDbContext())
            {
                var registrationList = db.Bookings
                                       .Select(BookingToCheckin)
                                       .ToList();

                if (registrationList.Count > 0)
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri($"http://{_hostIp}:19081/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                        foreach (var reg in registrationList)
                        {
                            var partitionKey = Char.ToUpper(reg.Passport.First());
                            var postContent  = new StringContent(JsonConvert.SerializeObject(reg), Encoding.UTF8, "application/json");
                            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                            var response = await client.PostAsync($"{_appName}/SmartHotel.Registration.StoreKPIs/api/values?key={reg.Passport}&PartitionKey={partitionKey}&PartitionKind=Int64Range", postContent);

                            response.EnsureSuccessStatusCode();
                        }
                    }
                }
            }
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            var registrationProvided =
                int.TryParse(Request.QueryString["registration"], out int registrationId);

            //int.TryParse(Request.QueryString["registrationId"], out int registrationId);

            if (registrationId == 0)
            {
                throw new System.ArgumentException("Parameter cannot be null");
            }

            if (!registrationProvided)
            {
                Response.Redirect("Default.aspx");
            }

            using (var context = new BookingsDbContext())
            {
                Booking checkin = context.Bookings.Find(registrationId);

                CustomerName.Value = checkin.CustomerName;
                Passport.Value     = checkin.Passport;
                CustomerId.Value   = checkin.CustomerId;
                Address.Value      = checkin.Address;
                Amount.Value       = checkin.Amount.ToString();
            }
        }
コード例 #8
0
        public void ValidDeleteShouldDeleteHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidDeleteShouldDeleteHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var addedHotel   = hotelService.Create(new HotelBooking.Hotel
                {
                    Id        = 100,
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                });

                hotelService.Delete(100);

                Assert.IsNull(hotelService.GetHotelById(100));
            }
        }
コード例 #9
0
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _commandHandler             = new UpdatePersonCommandHandler(context);
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(context);
        }
コード例 #10
0
        public async Task AndTheJudiciaryPersonsShouldBeSaved()
        {
            await using var db = new BookingsDbContext(Context.BookingsDbContextOptions);
            var jps = await db.JudiciaryPersons.Where(x => TestDataManager.JudiciaryPersons.Contains(x.ExternalRefId)).ToListAsync();

            jps.ForEach(Assert.NotNull);
        }
コード例 #11
0
        public void DeleteById_IdNotFound()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteById_IdNotFound))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var controller = new ReviewsController(context);

                Review review = new Review
                {
                    HotelId = 1,
                    UserId  = 1,
                    Text    = "Cool",
                    Rating  = 8
                };

                controller.PostReview(review);
                context.Entry(review).State = EntityState.Detached;

                var actionResult = controller.DeleteReview(3).Result;
                Assert.IsNotEmpty(context.Reviews);
            }
        }
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _commandHandler = new AddJudiciaryPersonCommandHandler(context);
            _getJudiciaryPersonByExternalRefIdQueryHandler = new GetJudiciaryPersonByExternalRefIdQueryHandler(context);
        }
        public void InitialSetup()
        {
            var contextOptions = new DbContextOptionsBuilder <BookingsDbContext>().UseInMemoryDatabase(databaseName: "VhBookings").Options;

            _context       = new BookingsDbContext(contextOptions);
            _configOptions = new Mock <IOptions <FeatureFlagConfiguration> >();
        }
コード例 #14
0
        public void ValidDeleteShouldDeleteReview()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidDeleteShouldDeleteReview))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                // Arrange
                var controller = new ReviewsController(context);

                Review review = new Review
                {
                    HotelId = 1,
                    UserId  = 1,
                    Text    = "Cool",
                    Rating  = 8
                };

                controller.PostReview(review);

                // Act
                var result1 = controller.DeleteReview(1);
                var result2 = controller.DeleteReview(100);

                // Assert
                Assert.IsEmpty(context.Reviews);
                //    var okResult2 = result2.Should().BeOfType<>().Subject;
                //    Assert.Throws<InvalidOperationException>(() => controller.GetReview(100));
            }
        }
コード例 #15
0
        public async Task ClearUnattachedPersons(IEnumerable <string> removedPersons)
        {
            foreach (var personEmail in removedPersons)
            {
                await using var db = new BookingsDbContext(_dbContextOptions);
                var person = await db.Persons
                             .Include(x => x.Address)
                             .Include(x => x.Organisation)
                             .SingleOrDefaultAsync(x => x.ContactEmail == personEmail);

                if (person == null)
                {
                    return;
                }
                if (person.Address != null)
                {
                    db.Remove(person.Address);
                }
                if (person.Organisation != null)
                {
                    db.Remove(person.Organisation);
                }
                db.Remove(person);

                await db.SaveChangesAsync();
            }
        }
コード例 #16
0
        public void ValidPostShouldCreateANewHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidPostShouldCreateANewHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var controller   = new HotelsController(hotelService);

                Hotel hotel = new Hotel
                {
                    Id        = 1,
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                controller.PostHotel(hotel);

                Assert.IsNotEmpty(context.Hotels);
            }
        }
コード例 #17
0
        public async Task ThenTheHearingShouldBeRemoved()
        {
            await using var db = new BookingsDbContext(BookingsDbContextOptions);
            var hearingFromDb = db.VideoHearings.AsNoTracking().SingleOrDefault(x => x.Id == _hearingId);

            hearingFromDb.Should().BeNull();
        }
 private async Task <List <Person> > GetPersonsInDb()
 {
     await using var db = new BookingsDbContext(BookingsDbContextOptions);
     return(await db.Persons
            .Include(p => p.Organisation)
            .ToListAsync());
 }
コード例 #19
0
        public void ValidGetByIdShouldReturnSelectedHotel()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetByIdShouldReturnSelectedHotel))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var controller   = new HotelsController(hotelService);

                Hotel hotel2 = new Hotel
                {
                    Id        = 1,
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                Hotel hotel1 = new Hotel
                {
                    Id        = 2,
                    HotelName = "Belvedere Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                hotelService.Create(hotel1);
                hotelService.Create(hotel2);

                context.Entry(hotel1).State = EntityState.Detached;
                context.Entry(hotel2).State = EntityState.Detached;

                var response = controller.GetHotelById(1);

                var contentResult = response as Hotel;

                Assert.IsNotNull(contentResult);
                Assert.AreEqual("Transilvania Hotel", contentResult.HotelName);
            }
        }
コード例 #20
0
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _commandHandler             = new AnonymisePersonCommandHandler(context);
            _newHearingId               = Guid.Empty;
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(context);
        }
コード例 #21
0
 public void PostRegister(Booking booking)
 {
     using (var db = new BookingsDbContext())
     {
         var checkin = db.Bookings.Add(booking);
         db.SaveChanges();
     }
 }
コード例 #22
0
        public void Setup()
        {
            var context        = new BookingsDbContext(BookingsDbContextOptions);
            var hearingService = new HearingService(context);

            _commandHandler = new UpdateParticipantCommandHandler(context, hearingService);
            _newHearingId   = Guid.Empty;
        }
コード例 #23
0
        private async Task AddQuestionnaire()
        {
            await using var db = new BookingsDbContext(_dbContextOptions);
            AddIndividualQuestionnaire(db);
            AddRepresentativeQuestionnaire(db);

            await db.SaveChangesAsync();
        }
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _commandHandler             = new AddEndPointToHearingCommandHandler(context);
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(context);
            _newHearingId = Guid.Empty;
        }
コード例 #25
0
        public async Task RemoveJudiciaryPersonAsync(JudiciaryPerson judiciaryPerson)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);

            db.JudiciaryPersons.Remove(judiciaryPerson);

            await db.SaveChangesAsync();
        }
コード例 #26
0
        public void ValidGetHotelsShouldListAll()
        {
            var options = new DbContextOptionsBuilder <BookingsDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidGetHotelsShouldListAll))
                          .Options;

            using (var context = new BookingsDbContext(options))
            {
                var hotelService = new ReviewService(context);
                var controller   = new HotelsController(hotelService);

                Hotel hotel2 = new Hotel
                {
                    HotelName = "Transilvania Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                Hotel hotel1 = new Hotel
                {
                    HotelName = "Belvedere Hotel",
                    City      = "Sibiu",
                    Capacity  = 120,
                    Rating    = 8,
                    Reviews   = new List <Review>()
                    {
                        new Review
                        {
                            Text   = "fain",
                            Rating = 10,
                        }
                    }
                };

                controller.PostHotel(hotel1);
                controller.PostHotel(hotel2);

                context.Entry(hotel1).State = EntityState.Detached;
                context.Entry(hotel2).State = EntityState.Detached;

                Assert.AreEqual(hotelService.GetHotels().Count(), 2);

                IActionResult actionResult  = controller.GetHotels();
                var           createdResult = actionResult as OkObjectResult;

                Assert.IsNotNull(createdResult);
                Assert.AreEqual(200, createdResult.StatusCode);
            }
        }
        public void Setup()
        {
            var context        = new BookingsDbContext(BookingsDbContextOptions);
            var hearingService = new HearingService(context);

            _commandHandler             = new AddParticipantsToVideoHearingCommandHandler(context, hearingService);
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(context);
            _newHearingId = Guid.Empty;
        }
コード例 #28
0
        public ReviewValidator(BookingsDbContext context)
        {
            RuleFor(x => x.Text).NotEmpty()
            .MinimumLength(2);

            RuleFor(x => x.Rating).NotEmpty()
            .GreaterThan(0)
            .LessThan(11);
        }
コード例 #29
0
        public void Setup()
        {
            var context = new BookingsDbContext(BookingsDbContextOptions);

            _getHearingByIdQueryHandler   = new GetHearingByIdQueryHandler(context);
            _getHearingVenuesQueryHandler = new GetHearingVenuesQueryHandler(context);
            _commandHandler = new UpdateHearingCommandHandler(context);
            _newHearingId   = Guid.Empty;
        }
コード例 #30
0
        public async Task SeedVideoHearing(VideoHearing videoHearing)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);
            await db.VideoHearings.AddAsync(videoHearing);

            await db.SaveChangesAsync();

            _seededHearings.Add(videoHearing.Id);
        }