Inheritance: DbContext, IIsraelHikingDbContext
Ejemplo n.º 1
0
 public void NoDatabaseFile_CreateDatabase_DatabaseShouldBeCreated()
 {
     var context = new IsraelHikingDbContext();
     var siteUrl = new SiteUrl();
     siteUrl.CreationDate = DateTime.Now;
     var list = context.SiteUrls.ToList();
     Assert.AreEqual(0, list.Count);
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (_dbContext != null)
     {
         _dbContext.Dispose();
         _dbContext = null;
     }
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (_dbContext != null)
     {
         _dbContext.Dispose();
         _dbContext = null;
     }
 }
        public void UpdateDatabase()
        {
            using (var context = new IsraelHikingDbContext())
            {
                var list = context.SiteUrls.ToList();
                foreach (var siteUrl in list)
                {
                    var dataContainer = JsonConvert.DeserializeObject<DataContainer>(siteUrl.JsonData);
                    if (dataContainer.routes.Count == 0 && dataContainer.markers.Count == 0)
                    {
                        continue;
                    }
                    foreach (var routeData in dataContainer.routes)
                    {
                        for (int routeSegmentIndex = 0; routeSegmentIndex < routeData.segments.Count; routeSegmentIndex++)
                        {
                            var routeSegmentData = routeData.segments[routeSegmentIndex];
                            if (routeSegmentIndex <= 0)
                            {
                                continue;
                            }
                            var previousReouteSegment = routeData.segments[routeSegmentIndex - 1];
                            if (previousReouteSegment.routingType == "None" && 
                                !previousReouteSegment.latlngzs.Last().Equals(routeSegmentData.latlngzs.First()))
                            {
                                routeSegmentData.latlngzs.Insert(0, previousReouteSegment.latlngzs.Last());
                            }

                            if (routeSegmentData.routingType == "None" &&
                                !routeSegmentData.latlngzs.First().Equals(previousReouteSegment.latlngzs.Last()))
                            {
                                routeSegmentData.latlngzs[0] = previousReouteSegment.latlngzs.Last();
                            }
                        }
                    }

                    var jsonData = JsonConvert.SerializeObject(dataContainer, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
                    siteUrl.JsonData = jsonData;
                    context.MarkAsModified(siteUrl);
                }
                context.SaveChanges();
            }
        }
        public void NoDatabaseFile_CreateDatabase_DatabaseShouldBeCreated()
        {
            if (File.Exists(TEST_SQLITE_FILE_NAME))
            {
                File.Delete(TEST_SQLITE_FILE_NAME);
            }

            using (var context = new IsraelHikingDbContext())
            {
                var list = context.SiteUrls.ToList();
                Assert.AreEqual(0, list.Count);
                Assert.IsTrue(File.Exists(TEST_SQLITE_FILE_NAME));
            }

            var id = "42";
            using (var context = new IsraelHikingDbContext())
            {
                context.SiteUrls.Add(new SiteUrl {Id = id});
                context.SaveChanges();
            }

            using (var context = new IsraelHikingDbContext())
            {
                Assert.AreEqual(1, context.SiteUrls.Count());
            }
            using (var context = new IsraelHikingDbContext())
            {
                var siteUrlToUpdate = new SiteUrl {Id = id, Title = "title"};
                context.MarkAsModified(siteUrlToUpdate);
                context.SaveChanges();
            }

            using (var context = new IsraelHikingDbContext())
            {
                Assert.IsNotNull(context.SiteUrls.FirstOrDefault(x => x.Title == "title"));
            }
        }
Ejemplo n.º 6
0
 public IsraelHikingRepository()
 {
     _dbContext = new IsraelHikingDbContext();
 }
Ejemplo n.º 7
0
 public IsraelHikingRepository(IsraelHikingDbContext context)
 {
     _dbContext = context;
 }