public void GetLastRunInfoForCheck_AllBooksChecked()
        {
            IScrBook book1 = AddBookToMockedScripture(1, "Genesis");
            IScrBook book2 = AddBookToMockedScripture(2, "Exodus");
            IScrBook book3 = AddBookToMockedScripture(3, "Leviticus");

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

            IFdoOwningSequence <IScrBookAnnotations> booksAnnotations =
                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.
            IScrCheckRunFactory checkRunFactory = Cache.ServiceLocator.GetInstance <IScrCheckRunFactory>();
            IScrCheckRun        checkRun        = checkRunFactory.Create();

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

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

            // Add a check history record for Leviticus.
            checkRun = checkRunFactory.Create();
            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
        /// ------------------------------------------------------------------------------------
        /// <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 <IScrScriptureNote> > > >();
            }

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

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

            pendingErrorsForBook[check.CheckId] = pendingErrorsForCheck;

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

            // Find previously created error annotions for the current book and check.
            foreach (IScrScriptureNote 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);
                    IStTxtPara quotePara      = (IStTxtPara)ann.QuoteOA.ParagraphsOS[0];
                    IStTxtPara discussionPara = (IStTxtPara)ann.DiscussionOA.ParagraphsOS[0];
                    string     key            = beginRef.AsString + endRef.AsString + quotePara.Contents.Text +
                                                discussionPara.Contents.Text;

                    List <IScrScriptureNote> errors;
                    if (!pendingErrorsForCheck.TryGetValue(key, out errors))
                    {
                        errors = new List <IScrScriptureNote>();
                        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.
            IScrCheckRun checkRun = null;

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

            if (checkRun == null)
            {
                checkRun = Cache.ServiceLocator.GetInstance <IScrCheckRunFactory>().Create();
                annotations.ChkHistRecsOC.Add(checkRun);
                checkRun.CheckId = check.CheckId;
            }

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

            foreach (List <IScrScriptureNote> obsoleteErrors in pendingErrorsForCheck.Values)
            {
                foreach (IScrScriptureNote obsoleteError in obsoleteErrors)
                {
                    annotations.NotesOS.Remove(obsoleteError);
                }
            }
        }