Пример #1
0
        public void GetLastRunInfoForCheck_AllBooksChecked()
        {
            IScrBook book1 = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
            IScrBook book2 = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus");
            IScrBook book3 = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");

            m_bookFilter.Add(new int[] { book1.Hvo, book2.Hvo, book3.Hvo });

            FdoOwningSequence <IScrBookAnnotations> booksAnnotations =
                m_inMemoryCache.Cache.LangProject.TranslatedScriptureOA.BookAnnotationsOS;

            Guid     checkId = Guid.NewGuid();
            DateTime date1   = new DateTime(2008, 3, 5, 14, 20, 30);
            DateTime date2   = new DateTime(2007, 3, 5, 14, 20, 30);
            DateTime date3   = new DateTime(2009, 3, 5, 14, 20, 30);

            // Add a check history record for Genesis.
            ScrCheckRun checkRun = new ScrCheckRun();

            booksAnnotations[0].ChkHistRecsOC.Add(checkRun);
            checkRun.CheckId = checkId;
            checkRun.RunDate = date1;

            // Add a check history record for Exodus.
            checkRun = new ScrCheckRun();
            booksAnnotations[1].ChkHistRecsOC.Add(checkRun);
            checkRun.CheckId = checkId;
            checkRun.RunDate = date2;

            // Add a check history record for Leviticus.
            checkRun = new ScrCheckRun();
            booksAnnotations[2].ChkHistRecsOC.Add(checkRun);
            checkRun.CheckId = checkId;
            checkRun.RunDate = date3;

            // Call the method we're testing. Send the arguments in an object
            // array because the second argument is an out parameter.
            object[] args    = new object[] { checkId, new string[] { } };
            DateTime lastRun = ReflectionHelper.GetDateTimeResult(m_editChecksControl,
                                                                  "GetLastRunInfoForCheck", args);

            string[] bookChkInfo = args[1] as string[];

            Assert.AreEqual(date2, lastRun);
            Assert.AreEqual(3, bookChkInfo.Length);
            Assert.IsTrue(bookChkInfo[0].Contains(date1.ToString()));
            Assert.IsTrue(bookChkInfo[1].Contains(date2.ToString()));
            Assert.IsTrue(bookChkInfo[2].Contains(date3.ToString()));
            Assert.IsTrue(bookChkInfo[0].Contains("Genesis"));
            Assert.IsTrue(bookChkInfo[1].Contains("Exodus"));
            Assert.IsTrue(bookChkInfo[2].Contains("Leviticus"));
        }
Пример #2
0
		public void RunCheck_ScrCheckRunRecordsWithOneBookTwoChecks()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check1 = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check1.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Verbification"));
			tok = new DummyParaCheckingToken(m_scr, m_inMemoryCache.Cache.DefaultVernWs, 0);
			check1.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 26, 2, "Verbification"));

			DummyEditorialCheck check2 = new DummyEditorialCheck(kCheckId2);
			check2.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Stupid Check"));
			tok = new DummyParaCheckingToken(m_scr, m_inMemoryCache.Cache.DefaultVernWs, 0);
			check2.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 26, 2, "Stupid Check"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "The Book of David");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check1);
			dataSource.RunCheck(check2);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];

			Assert.AreEqual(2, annotations.ChkHistRecsOC.Count);
			Assert.AreEqual(4, annotations.NotesOS.Count);

			ScrCheckRun scr1 =
				new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);
			ScrCheckRun scr2 =
				new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[1]);

			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr1.Result);
			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr2.Result);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[0].ResolutionStatus);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[1].ResolutionStatus);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[2].ResolutionStatus);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[3].ResolutionStatus);

			annotations.NotesOS[0].ResolutionStatus = NoteStatus.Closed;
			annotations.NotesOS[1].ResolutionStatus = NoteStatus.Closed;
			dataSource.RunCheck(check1);

			scr1 = new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);
			scr2 = new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[1]);
			Assert.AreEqual(ScrCheckRunResult.IgnoredInconsistencies, scr1.Result);
			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr2.Result);
		}
Пример #3
0
		public void RunCheck_ScrCheckRunRecordsWithFixedInconsistency()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			DummyEditorialCheck check = new DummyEditorialCheck(kCheckId1);
			ScrCheckingToken tok = new DummyParaCheckingToken(m_scr, Cache.DefaultVernWs, 0);
			check.m_ErrorsToReport.Add(new DummyEditorialCheck.DummyError(tok, 5, 2, "Verbification"));

			m_scrInMemoryCache.AddBookToMockedScripture(tok.StartRef.Book, "The Book of David");

			dataSource.GetText(tok.StartRef.Book, 0);
			dataSource.RunCheck(check);
			IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[tok.StartRef.Book - 1];

			Assert.AreEqual(1, annotations.ChkHistRecsOC.Count);
			Assert.AreEqual(1, annotations.NotesOS.Count);

			ScrCheckRun scr =
				new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);

			Assert.AreEqual(ScrCheckRunResult.Inconsistencies, scr.Result);
			Assert.AreEqual(NoteStatus.Open, annotations.NotesOS[0].ResolutionStatus);

			check.m_ErrorsToReport.Clear();
			dataSource.RunCheck(check);

			Assert.AreEqual(1, annotations.ChkHistRecsOC.Count);
			Assert.AreEqual(0, annotations.NotesOS.Count);

			scr = new ScrCheckRun(Cache, annotations.ChkHistRecsOC.HvoArray[0]);
			Assert.AreEqual(ScrCheckRunResult.NoInconsistencies, scr.Result);
		}
Пример #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Runs the check.
        /// </summary>
        /// <param name="check">The check.</param>
        /// ------------------------------------------------------------------------------------
        public void RunCheck(IScriptureCheck check)
        {
            if (m_bookChecksFailed == null)
            {
                m_bookChecksFailed = new Dictionary <int, Dictionary <Guid, ScrCheckRunResult> >();
            }

            if (m_pendingCheckErrors == null)
            {
                m_pendingCheckErrors = new Dictionary <int, Dictionary <Guid, Dictionary <string, List <ScrScriptureNote> > > >();
            }

            Dictionary <Guid, Dictionary <string, List <ScrScriptureNote> > > pendingErrorsForBook;
            int bookNum = m_bookBeingChecked.CanonicalNum;

            if (!m_pendingCheckErrors.TryGetValue(bookNum, out pendingErrorsForBook))
            {
                pendingErrorsForBook          = new Dictionary <Guid, Dictionary <string, List <ScrScriptureNote> > >();
                m_pendingCheckErrors[bookNum] = pendingErrorsForBook;
            }
            Dictionary <string, List <ScrScriptureNote> > pendingErrorsForCheck =
                new Dictionary <string, List <ScrScriptureNote> >();

            pendingErrorsForBook[check.CheckId] = pendingErrorsForCheck;

            ScrBookAnnotations annotations =
                (ScrBookAnnotations)m_scr.BookAnnotationsOS[bookNum - 1];

            // Find previously created error annotions for the current book and check.
            foreach (ScrScriptureNote ann in annotations.NotesOS)
            {
                BCVRef beginRef = new BCVRef(ann.BeginRef);
                // ENHANCE, use a smarter algorithm to search for the start of the annotations for this book
                if (beginRef.Book == bookNum && ann.AnnotationTypeRA.Guid == check.CheckId)
                {
                    BCVRef    endRef         = new BCVRef(ann.EndRef);
                    StTxtPara quotePara      = (StTxtPara)ann.QuoteOA.ParagraphsOS[0];
                    StTxtPara discussionPara = (StTxtPara)ann.DiscussionOA.ParagraphsOS[0];
                    string    key            = beginRef.AsString + endRef.AsString + quotePara.Contents.Text +
                                               discussionPara.Contents.Text;

                    List <ScrScriptureNote> errors;
                    if (!pendingErrorsForCheck.TryGetValue(key, out errors))
                    {
                        errors = new List <ScrScriptureNote>();
                        pendingErrorsForCheck[key] = errors;
                    }
                    errors.Add(ann);
                }
            }

            if (!m_bookChecksFailed.ContainsKey(bookNum))
            {
                m_bookChecksFailed[bookNum] = new Dictionary <Guid, ScrCheckRunResult>();
            }

            // Before running the check, reset the check result for this book and check.
            // This is like initializing our check result to green bar in an NUnit test.
            // As the check is running, that status may get changed to "Inconsistencies"
            // (red bar) or "IgnoredInconsistencies" (yellow bar).
            m_bookChecksFailed[bookNum][check.CheckId] = ScrCheckRunResult.NoInconsistencies;

            // Create a hash table for this check to tally how many times each unique error is generated.
            if (m_errorCounts != null)
            {
                m_errorCounts.Clear();
                m_errorCounts = null;
            }
            m_errorCounts = new ErrorInventory();

            // Run the Scripture check.
            check.Check(TextTokens(), RecordError);

            // Find a check history record for the check just run.
            // If one cannot be found, then create a new one.
            ScrCheckRun checkRun = null;

            foreach (ScrCheckRun scrChkRun in annotations.ChkHistRecsOC)
            {
                if (scrChkRun.CheckId == check.CheckId)
                {
                    checkRun = scrChkRun;
                    break;
                }
            }

            if (checkRun == null)
            {
                checkRun = new ScrCheckRun();
                annotations.ChkHistRecsOC.Add(checkRun);
                checkRun.CheckId = check.CheckId;
            }

            checkRun.RunDate = DateTime.Now;
            checkRun.Result  = m_bookChecksFailed[bookNum][check.CheckId];

            // Should this be initialized to certain capacity?
            Set <int> obsoleteErrorIds = new Set <int>();

            foreach (List <ScrScriptureNote> obsoleteErrors in pendingErrorsForCheck.Values)
            {
                foreach (ScrScriptureNote obsoleteError in obsoleteErrors)
                {
                    //annotations.NotesOS.Remove(obsoleteError);
                    obsoleteErrorIds.Add(obsoleteError.Hvo);
                }
            }

            CmObject.DeleteObjects(obsoleteErrorIds, m_cache);
        }
Пример #5
0
		public void GetLastRunInfoForCheck_AllBooksChecked()
		{
			IScrBook book1 = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			IScrBook book2 = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus");
			IScrBook book3 = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
			m_bookFilter.Add(new int[] { book1.Hvo, book2.Hvo, book3.Hvo });

			FdoOwningSequence<IScrBookAnnotations> booksAnnotations =
				m_inMemoryCache.Cache.LangProject.TranslatedScriptureOA.BookAnnotationsOS;

			Guid checkId = Guid.NewGuid();
			DateTime date1 = new DateTime(2008, 3, 5, 14, 20, 30);
			DateTime date2 = new DateTime(2007, 3, 5, 14, 20, 30);
			DateTime date3 = new DateTime(2009, 3, 5, 14, 20, 30);

			// Add a check history record for Genesis.
			ScrCheckRun checkRun = new ScrCheckRun();
			booksAnnotations[0].ChkHistRecsOC.Add(checkRun);
			checkRun.CheckId = checkId;
			checkRun.RunDate = date1;

			// Add a check history record for Exodus.
			checkRun = new ScrCheckRun();
			booksAnnotations[1].ChkHistRecsOC.Add(checkRun);
			checkRun.CheckId = checkId;
			checkRun.RunDate = date2;

			// Add a check history record for Leviticus.
			checkRun = new ScrCheckRun();
			booksAnnotations[2].ChkHistRecsOC.Add(checkRun);
			checkRun.CheckId = checkId;
			checkRun.RunDate = date3;

			// Call the method we're testing. Send the arguments in an object
			// array because the second argument is an out parameter.
			object[] args = new object[] { checkId, new string[] { } };
			DateTime lastRun = ReflectionHelper.GetDateTimeResult(m_editChecksControl,
				"GetLastRunInfoForCheck", args);

			string[] bookChkInfo = args[1] as string[];

			Assert.AreEqual(date2, lastRun);
			Assert.AreEqual(3, bookChkInfo.Length);
			Assert.IsTrue(bookChkInfo[0].Contains(date1.ToString()));
			Assert.IsTrue(bookChkInfo[1].Contains(date2.ToString()));
			Assert.IsTrue(bookChkInfo[2].Contains(date3.ToString()));
			Assert.IsTrue(bookChkInfo[0].Contains("Genesis"));
			Assert.IsTrue(bookChkInfo[1].Contains("Exodus"));
			Assert.IsTrue(bookChkInfo[2].Contains("Leviticus"));
		}