public void AsCardListLineTest_After()
        {
            string aCFormat   = null;
            bool   aDualDated = false;
            string aNewYear   = null;

            CommonEnums.DateQuality aQuality = CommonEnums.DateQuality.unknown;
            string aVal = "1939";

            CommonEnums.DateValType aValType = CommonEnums.DateValType.after;

            testVal = new DateObjectModelVal(aVal, aCFormat, aDualDated, aNewYear, aQuality, aValType);

            CardListLineCollection AsCardListLineTest_After = testVal.AsCardListLine("Test Title");

            if (AsCardListLineTest_After.Title != "Test Title")
            {
                Assert.Fail();
                return;
            }

            CardListLineUtils.CheckCardListLine(AsCardListLineTest_After[0], "Date:", "after 1939");
            CardListLineUtils.CheckCardListLine(AsCardListLineTest_After[1], "Val:", "1939");
            CardListLineUtils.CheckCardListLine(AsCardListLineTest_After[2], "Type:", "after");

            Assert.True(AsCardListLineTest_After.Count == 3);
        }
        public void AsCardListLineTest_DualDated()
        {
            string aCFormat   = null;
            bool   aDualDated = true;
            string aNewYear   = null;

            CommonEnums.DateQuality aQuality = CommonEnums.DateQuality.unknown;
            string aVal = "1939";

            CommonEnums.DateValType aValType = CommonEnums.DateValType.unknown;

            testVal = new DateObjectModelVal(aVal, aCFormat, aDualDated, aNewYear, aQuality, aValType);

            CardListLineCollection AsCardListLineTest_Basic = testVal.AsCardListLine("Test Title");

            if (AsCardListLineTest_Basic.Title != "Test Title")
            {
                Assert.Fail(); return;
            }

            CardListLineUtils.CheckCardListLine(AsCardListLineTest_Basic[0], "Date:", "1939 (Dual dated)");
            CardListLineUtils.CheckCardListLine(AsCardListLineTest_Basic[1], "Val:", "1939");
            CardListLineUtils.CheckCardListLine(AsCardListLineTest_Basic[2], "Dual Dated:", "True");

            Assert.True(AsCardListLineTest_Basic.Count == 3);
        }
Beispiel #3
0
        public void InitYearOnly()
        {
            string aCFormat   = null;
            bool   aDualDated = false;
            string aNewYear   = null;

            CommonEnums.DateQuality aQuality = CommonEnums.DateQuality.unknown;
            string aVal = "1939";

            CommonEnums.DateValType aValType = CommonEnums.DateValType.unknown;

            testVal = new DateObjectModelVal(aVal, aCFormat, aDualDated, aNewYear, aQuality, aValType);
        }
        /// <summary>
        /// Sets the date value.
        /// </summary>
        /// <param name="argCurrentElement">
        /// The current element.
        /// </param>
        /// <returns>
        /// </returns>
        public static DateObjectModel SetDateVal(XElement argCurrentElement)
        {
            Contract.Requires(argCurrentElement != null);

            string aCFormat   = string.Empty;
            bool   aDualDated = false;
            string aNewYear   = string.Empty;

            CommonEnums.DateQuality aQuality = CommonEnums.DateQuality.unknown;
            string aVal = string.Empty;

            CommonEnums.DateValType aValType = CommonEnums.DateValType.unknown;

            // check for date range
            try
            {
                bool boolFound = false;

                // cformat CDATA #REQUIRED
                string stringFound = GetAttribute(argCurrentElement, "cformat");
                if (!string.IsNullOrEmpty(stringFound))
                {
                    aCFormat = stringFound;
                }

                // dualdated value #REQUIRED
                boolFound = GetBool(argCurrentElement, "dualdated");
                if (!string.IsNullOrEmpty(stringFound))
                {
                    aDualDated = boolFound;
                }

                // newyear CDATA #IMPLIED
                stringFound = GetAttribute(argCurrentElement, "newyear");
                if (!string.IsNullOrEmpty(stringFound))
                {
                    aNewYear = stringFound;
                }

                // type CDATA #REQUIRED
                stringFound = GetAttribute(argCurrentElement, "quality");
                if (!string.IsNullOrEmpty(stringFound))
                {
                    if (!Enum.TryParse(stringFound, out aQuality))
                    {
                        ErrorInfo t = new ErrorInfo("Bad Date Quality")
                        {
                            { "Current Element", argCurrentElement.ToString() }
                        };

                        App.Current.Services.GetService <IErrorNotifications>().NotifyError(t);
                    }
                }

                // type CDATA #REQUIRED
                stringFound = GetAttribute(argCurrentElement, "type");
                if (!string.IsNullOrEmpty(stringFound))
                {
                    if (!Enum.TryParse(stringFound, out aValType))
                    {
                        ErrorInfo t = new ErrorInfo("Bad Date Value")
                        {
                            { "Current Element", argCurrentElement.ToString() }
                        };

                        App.Current.Services.GetService <IErrorNotifications>().NotifyError(t);
                    }
                }

                // val CDATA #REQUIRED
                stringFound = GetAttribute(argCurrentElement, "val");
                if (!string.IsNullOrEmpty(stringFound))
                {
                    aVal = stringFound;
                }
            }
            catch (Exception e)
            {
                // TODO
                App.Current.Services.GetService <IErrorNotifications>().NotifyException(e.Message, e);
                throw;
            }

            return(new DateObjectModelVal(aVal, aCFormat, aDualDated, aNewYear, aQuality, aValType));
        }