Exemplo n.º 1
0
        public void Check_If_Responds_To_Query()
        {
            var options = new DbContextOptionsBuilder <TRDBContext>().UseInMemoryDatabase(databaseName: "database_super_cazzuto").Options;


            using (var context = new TRDBContext(options))
            {
                context.TReservations.Add(new TennisReservation()
                {
                    CourtId = 1, ReservationTime = DateTime.Now, MatchType = "Singolo"
                });
                context.TReservations.Add(new TennisReservation()
                {
                    CourtId = 2, ReservationTime = DateTime.Now, MatchType = "Doppio"
                });
                context.TReservations.Add(new TennisReservation()
                {
                    CourtId = 2, ReservationTime = DateTime.Now, MatchType = "Singolo"
                });
                context.TReservations.Add(new TennisReservation()
                {
                    CourtId = 1, ReservationTime = DateTime.Now, MatchType = "Doppio"
                });

                context.SaveChanges();
            }


            using (var context = new TRDBContext(options))
            {
                var repo   = new Repository(context);
                var result = repo.FindByMatchType("Doppio");
                Assert.Equal(2, result.Count());
            }
        }
Exemplo n.º 2
0
        public void Check_If_Add_To_Database_Works()
        {
            //Arrange
            var testReservation = new TennisReservation();

            testReservation.CourtId         = 1;
            testReservation.ReservationTime = DateTime.Now;
            testReservation.MatchType       = "Doppio";
            //{ CourtId = 1, ReservationTime = DateTime.Now, MatchType = "Doppio" };
            var options = new DbContextOptionsBuilder <TRDBContext>().UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Initial Catalog=TennisReservations;Integrated Security=True; MultipleActiveResultSets=true").Options;

            using (var context = new TRDBContext(options))
            {
                Repository repo  = new Repository(context);
                var        count = repo.Reservations.Count();
                //Act
                repo.AddReservation(testReservation);
                //Assert
                Assert.Equal(count + 1, repo.Reservations.Count());
                Assert.Equal(testReservation, repo.Reservations.Last());
            }

            using (var context = new TRDBContext(options))
            {
                var count = context.TReservations.Count();
                //Act
                context.TReservations.Remove(testReservation);
                context.SaveChanges();
                //Assert
                Assert.Equal(count - 1, context.TReservations.Count());
                Assert.NotEqual(testReservation, context.TReservations.Last());
            }
        }