Exemplo n.º 1
0
 public void t02_should_be_two_notices_already()
 {
     List<FuneralNotice> results;
     using (NoticesContext ctx = new NoticesContext())
     {
         results = ctx.FuneralNotices.Where(x => x.Id > 0).ToList();
     }
     Assert.IsTrue(results.Count == 2);
 }
Exemplo n.º 2
0
        public void Setup()
        {
            LoggingHelper.PointLoggerToElmahDb();
            //excluded ELMAH
            ///LoggingHelper.ClearElmahLogs();
            LoggingHelper.EnableLoggingAll();

            ctx = new NoticesContext();
            logger = new NoticeLogger();
        }
Exemplo n.º 3
0
 public void t01_verify_if_can_create_db()
 {
     int result;
     using (NoticesContext ctx = new NoticesContext())
     {
         FuneralNotice notice = noticeBuilder.WithId(3);
         
         ctx.FuneralNotices.Add(notice);
         result = ctx.SaveChanges();
     }
     Assert.IsTrue(result == 1);
 }
        public override void Up()
        {
            var notice = new FuneralNotice(1, "test", "test")
            {
                MemorialId = 1,
                ParentBranchId = "1",
                CedarCode = "cedarCode",
                BranchId = "1",
                KnownAs = "knownAs",
                Obituary = "Obituary",
                Source = SourceType.PERMAVITA,
                DateOfDeath = DateTime.UtcNow,
                DateOfFuneral = DateTime.UtcNow,
            };

            using (var context = new NoticesContext())
            {
                context.FuneralNotices.Add(notice);
            }
        }
Exemplo n.º 5
0
        public void t05_notice_check_enums_trick()
        {
            List<FuneralNotice> result;
            using (NoticesContext ctx = new NoticesContext())
            {
                FuneralNotice notice = noticeBuilder
                    .WithId(5)
                    .WithSourceType(SourceType.RAINBOW);

                ctx.FuneralNotices.Add(notice);
                ctx.SaveChanges();

                result = ctx.FuneralNotices
                    .Where(x => x.Source == SourceType.RAINBOW)
                    .ToList();
            }
            
            Assert.That(result, Is.Not.Empty);
            Assert.That(result.First().SourceString, Is.EqualTo(SourceType.RAINBOW.ToString()) );
        }
Exemplo n.º 6
0
        public void t03_add_notice_and_auditlog()
        {
            AuditFuneralNotice audit;
            using (NoticesContext ctx = new NoticesContext())
            {
                FuneralNotice notice = noticeBuilder.WithId(4);
                ctx.FuneralNotices.Add(notice);

                audit = new AuditFuneralNotice(notice, AuditState.SavedToDb);
                ctx.AuditLogFuneralNotices.Add(audit);
                int result = ctx.SaveChanges();
                
                Assert.IsTrue(result == 2);
            }
            
            //read
            using (NoticesContext ctx = new NoticesContext())
            {
                audit = ctx.AuditLogFuneralNotices.FirstOrDefault(x => x.Id == 1);
            }
            Assert.IsTrue(audit.Id == 1);
        }
        protected virtual void Seed(NoticesContext context)
        {
            var notice = new FuneralNotice(1, "test", "test")
            {
                MemorialId = 1,
                ParentBranchId = "1",
                CedarCode = "cedarCode",
                BranchId = "1",
                KnownAs = "knownAs",
                Obituary = "Obituary",
                Source = SourceType.PERMAVITA,
                DateOfDeath = DateTime.UtcNow,
                DateOfFuneral = DateTime.UtcNow,
            };

            try
            {
                context.FuneralNotices.Add(notice);
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                StringBuilder builder = new StringBuilder();
                foreach (var eve in e.EntityValidationErrors)
                {
                    builder.AppendLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:".Frmt(
                        eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        builder.AppendLine("- Property: \"{0}\", Error: \"{1}\"".Frmt(ve.PropertyName, ve.ErrorMessage));
                    }
                }
                Console.Write(builder.ToString());
                throw;
            }

        }
        public void t07_SeedIndex()
        {
            indexer.ClearAllNoticesInIndex();
            LoggerConfiguration.Inst.NoticesTimeToLeave = new TimeSpan(0,1,0);

            int id = 2;
            using (var ctx = new NoticesContext())
            {
                for (int i = 0; i < 999; i++)
                {
                    FuneralNotice fn = noticeBuilder.WithId(2 + i);
                    fn.OnlineMemorialUrl = string.Empty;
                    ctx.FuneralNotices.Add(fn);
                }
                ctx.SaveChanges();
            }

            
            Assert.That(1, Is.EqualTo(1));

            indexer.ReIndexAll();
            var result = indexer.ReindexedCount;
            Assert.That(result, Is.GreaterThan(2));
        }
        public void t06_Reindex_all()
        {
            var date = DateTime.UtcNow.AddDays(-8); //too old
            FuneralNotice fn1 = noticeBuilder.WithId(5).WithDateOfFunerale(date); //funeral
            fn1.OnlineMemorialUrl = string.Empty;
            FuneralNotice fn2 = noticeBuilder.WithId(6).WithDateOfFunerale(date); //online

            using (var ctx = new NoticesContext())
            {
                ctx.FuneralNotices.Add(fn1);
                ctx.FuneralNotices.Add(fn2);
                ctx.SaveChanges();
            }
            
            indexer.Add(fn1);
            indexer.Add(fn2);
            indexer.ReIndexAll();

            var result = indexer.ReindexedCount;

            Assert.That(result, Is.EqualTo(2));
        }
Exemplo n.º 10
0
 public NoticeLogger(NoticesContext ctx) : this()
 {
     _ctx = ctx;
 }
Exemplo n.º 11
0
 public NoticeLogger()
 {
     _ctx = _ctx ?? new NoticesContext();
 }
Exemplo n.º 12
0
        public string ReIndexAll()
        {
            ReindexedCount = 0;
            var builder = new StringBuilder();
            var watch = new Stopwatch();
            watch.Start();

            DateTime prevWeek = DateTime.UtcNow.AddDays(-7);
            using (var ctx = new NoticesContext())
            {
                IEnumerable<FuneralNotice> results = ctx.FuneralNotices.Where(x =>
                                            (x.DateOfFuneral > prevWeek) //funeral
                                            || !String.IsNullOrEmpty(x.OnlineMemorialUrl) //online
                    ).Select(x => x).ToList();

                foreach (FuneralNotice fn in results)
                {
                    Add(fn);
                    ReindexedCount++;

                    if (ReIndexShouldStop)
                        break;
                }
            }
            watch.Stop();

            string completed = (!ReIndexShouldStop) ? "ReIndexAll compleated. <br/>" : "ReIndexAll was stopped. <br/>";
            builder.AppendLine(completed);
            builder.AppendLine("Execution time: {0}minutes {1}seconds <br/>".Frmt(watch.Elapsed.Minutes, watch.Elapsed.Seconds));
            builder.AppendLine("Number of items indexed: {0} <br/>".Frmt(ReindexedCount));
            return builder.ToString();
        } 
Exemplo n.º 13
0
        public void t06_audits_verify_getLast()
        {
            AuditFuneralNotice result;
            using (NoticesContext ctx = new NoticesContext())
            {
                FuneralNotice notice = noticeBuilder
                    .WithId(6);

                var audit1 = new AuditFuneralNotice(notice, AuditState.Creating);
                var audit2 = new AuditFuneralNotice(notice, AuditState.IndexingFailed);

                ctx.FuneralNotices.Add(notice);
                ctx.AuditLogFuneralNotices.AddRange(new[] { audit1, audit2 });
                ctx.SaveChanges();
            }
            using (NoticesContext ctx = new NoticesContext())
            {
                result = ctx.AuditLogFuneralNotices.GetLast(6);
            }

            Assert.That(result.AuditState, Is.EqualTo(AuditState.IndexingFailed) );
        }