예제 #1
0
        public void InMemoryTest()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <LuxMeetContext>()
                          .UseSqlite(connection)
                          .Options;

            // Create the schema in the database
            using (var context = new LuxMeetContext(options))
            {
                context.Database.EnsureCreated();
            }

            using (var context = new LuxMeetContext(options))
            {
                context.Events.Add(new Event()
                {
                    name = "test event"
                });
                var count = context.SaveChanges();

                Debug.WriteLine("{0} records saved to database", count);

                Debug.WriteLine("");
                Debug.WriteLine("All blogs in database:");
                foreach (var item in context.Events)
                {
                    Debug.WriteLine(" - {0}", item.id);
                }
            }
        }
예제 #2
0
        public void CreateEventWithoutTitleThrowsError()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=testevents.db");

            connection.Open();

            var options = new DbContextOptionsBuilder <LuxMeetContext>()
                          .UseSqlite(connection)
                          .Options;

            // Create the schema in the database
            using (var context = new LuxMeetContext(options))
            {
                context.Database.EnsureCreated();
            }

            using (var context = new LuxMeetContext(options))
            {
                context.Events.Add(new Event()
                {
                    location = "doesn't matter, it should fail to save"
                });

                Assert.ThrowsException <DbUpdateException>(() =>
                {
                    var count = context.SaveChanges();
                });
            }
        }
예제 #3
0
        public async Task GetRemoteDoesNotError()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <LuxMeetContext>()
                          .UseSqlite(connection)
                          .Options;

            // Create the schema in the database
            using (var context = new LuxMeetContext(options))
            {
                context.Database.EnsureCreated();

                EventsRepository       rep    = new EventsRepository(connection);
                LuxMeet.DbModels.Event _event = await rep.GetRemote();

                var config = new MapperConfiguration(cfg => cfg.CreateMap <LuxMeet.DbModels.Event, LuxMeet.ViewModels.Event>());
                config.AssertConfigurationIsValid();

                // Perform mapping
                var   mapper = config.CreateMapper();
                Event dto    = mapper.Map <LuxMeet.DbModels.Event, LuxMeet.ViewModels.Event>(_event);

                dto.name.ShouldBe("new very future event");
                dto.location.ShouldBe("Route d'Esch");
            }
        }
예제 #4
0
        public async Task GetRemoteDoesNotError()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <LuxMeetContext>()
                          .UseSqlite(connection)
                          .Options;

            // Create the schema in the database
            using (var context = new LuxMeetContext(options))
            {
                context.Database.EnsureCreated();

                EventsRepository rep = new EventsRepository(connection);
                rep.accessToken = "xd8cfc758860187bc6e0cc76e33d6d10b65e505e2d1c9864a40d7c91f268131ec";
                await rep.GetRemote();
            }
        }