Ejemplo n.º 1
0
        private void SetUpClient()
        {
            ContactsAPI.Globals globals = new ContactsAPI.Globals();
            globals.ConnectionString = "DataSource=D:\\tfs\\web\\Contacts API\\ContactsAPI\\Contacts.db";

            var builder = new WebHostBuilder()
                          .UseStartup <ContactsAPI.Startup>()
                          .ConfigureServices(services =>
            {
                var context = new contactsContext(new DbContextOptionsBuilder <contactsContext>()
                                                  //.UseSqlite("DataSource=:memory:")
                                                  .UseSqlite("DataSource=D:\\tfs\\web\\Contacts API\\ContactsAPI\\Contacts.db")
                                                  .EnableSensitiveDataLogging()
                                                  .Options, globals);

                services.RemoveAll(typeof(contactsContext));
                services.AddSingleton(context);

                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                context.SaveChanges();

                // Clear local context cache
                foreach (var entity in context.ChangeTracker.Entries().ToList())
                {
                    entity.State = EntityState.Detached;
                }
                repository = new Repository(context);
            });

            _server = new TestServer(builder);

            Client = _server.CreateClient();
        }
Ejemplo n.º 2
0
 public Repository(contactsContext context)
 {
     _context = context;
 }
Ejemplo n.º 3
0
 public contactsItemsController(contactsContext context)
 {
     _context = context;
 }