Beispiel #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

#if DEBUG 
            // Drop, recreate and reseed the database
            Database.SetInitializer(new DbInitializer());
            using (var db = new ListAssistContext())
            {
                db.Database.Initialize(true);
            }

            // Recreate a edmx diagram from the latest model
            using (var ctx = new ListAssistContext())
            {
                using (var writer = new XmlTextWriter(HttpRuntime.AppDomainAppPath.TrimEnd('\\') + @".Data\EntityModelDiagram.edmx", Encoding.Default))
                {
                    EdmxWriter.WriteEdmx(ctx, writer);
                }
            }
#endif 
        }
            public void TestInitialize()
            {
                Database.SetInitializer(new DbInitializer());
                this.db = new ListAssistContext(new DbConStringBuilder("WebAPITests").getConnectionString());
                db.Database.Initialize(true);                
                Assert.IsNotNull(this.db, "List assist context is null.");

                AutoMapperConfiguration.Configure();

                listQueries = new ListQueries(new DbConStringBuilder("WebAPITests").getConnectionString());

                LAList testList1 = new LAList() { Name = "Test List 1" };
                LAList testList2 = new LAList() { Name = "Test List 2" };

                LAListItem testInsertItem1 = new LAListItem() { Description = "Test Insert 1", Done = false };
                LAListItem testInsertItem2 = new LAListItem() { Description = "Test Insert 2", Done = false };
                LAListItem testInsertItem3 = new LAListItem() { Description = "Test Insert 3", Done = false };

                Assert.IsNotNull(testList1, "Test list 1 is null.");
                Assert.IsNotNull(testList2, "Test list 2 is null.");

                Assert.IsNotNull(testInsertItem1, "Test insert item 1 is null.");
                testList1.LAListItems.Add(testInsertItem1);

                Assert.IsNotNull(testInsertItem2, "Test insert item 2 is null.");
                testList1.LAListItems.Add(testInsertItem2);

                Assert.IsNotNull(testInsertItem3, "Test insert item 3 is null,");
                testList2.LAListItems.Add(testInsertItem3);

                var lists = new List<LAList>
            {
                testList1,
                testList2,
            };


                foreach (LAList newList in lists)
                {
                    this.db.LALists.Add(newList);

                    foreach (LAListItem newListItem in newList.LAListItems)
                    {
                        this.db.LAListItems.Add(newListItem);
                    }
                }

                this.db.SaveChanges();

                Assert.IsNotNull(this.db.LALists.Where(e => e.Name.Equals("Test List 1")).FirstOrDefault(), "Test List 1 not found.");
                Assert.IsNotNull(this.db.LALists.Where(e => e.Name.Equals("Test List 2")).FirstOrDefault(), "Test List 2 not found.");
                Assert.IsNull(this.db.LALists.Where(e => e.Name.Equals("Test List 3")).FirstOrDefault(), "Test List 3 found.");
            }
Beispiel #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Drop, recreate and reseed the database
            Database.SetInitializer(new DbInitializer());
            using (var db = new ListAssistContext())
            {
                db.Database.Initialize(false);
            }
        }
 public void Initialize()
 {
     Database.SetInitializer(new DbInitializer());
     var db = new ListAssistContext();
     db.Database.Initialize(false);
 }
Beispiel #5
0
 public ListQueries(string connection)
 {
     this.db = new ListAssistContext(connection);
 }
Beispiel #6
0
 public ListQueries()
 {
      this.db = new ListAssistContext();
 }