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); } } }
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(); }); } }
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"); } }
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(); } }