public void TestReadOnly()
        {
            DateTimeFormatInfo info   = DateTimeFormatInfo.InvariantInfo;
            DateTimeFormatInfo actual = DateTimeFormatInfo.ReadOnly(info);

            Assert.True(actual.IsReadOnly);
        }
 public void TestNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         DateTimeFormatInfo.ReadOnly(null);
     });
 }
Пример #3
0
    public bool NegTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest1: ArgumentNullException should be thrown when dtfi is a null reference");

        try
        {
            DateTimeFormatInfo.ReadOnly(null);

            TestLibrary.TestFramework.LogError("101.1", "ArgumentNullException is not thrown when dtfi is a null reference");
            retVal = false;
        }
        catch (ArgumentNullException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("101.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
        public void TestWritable()
        {
            DateTimeFormatInfo info   = new DateTimeFormatInfo();
            DateTimeFormatInfo actual = DateTimeFormatInfo.ReadOnly(info);

            Assert.True(actual.IsReadOnly);
        }
Пример #5
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call ReadOnly on a read only DateTimeFormatInfo instance");

        try
        {
            DateTimeFormatInfo info   = DateTimeFormatInfo.InvariantInfo;
            DateTimeFormatInfo actual = DateTimeFormatInfo.ReadOnly(info);

            if (!actual.IsReadOnly)
            {
                TestLibrary.TestFramework.LogError("002.1", "Calling ReadOnly on a read only DateTimeFormatInfo instance does not make the instance read only");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Пример #6
0
        public void ReadOnly(DateTimeFormatInfo format, bool expected)
        {
            Assert.Equal(expected, format.IsReadOnly);

            DateTimeFormatInfo readOnlyFormat = DateTimeFormatInfo.ReadOnly(format);

            Assert.True(readOnlyFormat.IsReadOnly);
        }
        public static IEnumerable <object[]> ReadOnly_TestData()
        {
            yield return(new object[] { DateTimeFormatInfo.InvariantInfo, true });

            yield return(new object[] { DateTimeFormatInfo.ReadOnly(new DateTimeFormatInfo()), true });

            yield return(new object[] { new DateTimeFormatInfo(), false });

            yield return(new object[] { new CultureInfo("en-US").DateTimeFormat, false });
        }
Пример #8
0
 public override object GetFormat(Type formatType)
 {
     if (formatType == typeof(DateTimeFormatInfo))
     {
         DateTimeFormatInfo info = (DateTimeFormatInfo)((DateTimeFormatInfo)base.GetFormat(formatType)).Clone();
         info.ShortDatePattern = "MM?dd?yyyy";
         info.ShortTimePattern = "hh!mm";
         return(DateTimeFormatInfo.ReadOnly(info));
     }
     else
     {
         return(base.GetFormat(formatType));
     }
 }
Пример #9
0
        /// <summary>
        ///     Initializes the <see cref="DateTimeUtility" /> class.
        /// </summary>
        static DateTimeUtility()
        {
            var info = (DateTimeFormatInfo)CultureInfo.GetCultureInfo("fa-IR").DateTimeFormat.Clone();

            info.AbbreviatedDayNames   = new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
            info.DayNames              = new[] { "یکشنبه", "دوشنبه", "سه‌شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
            info.AbbreviatedMonthNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
            info.MonthNames            = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
            info.AMDesignator          = "ق.ظ";
            info.PMDesignator          = "ب.ظ";
            info.ShortDatePattern      = "yyyy/MM/dd";
            info.FirstDayOfWeek        = DayOfWeek.Saturday;
            _PersianDateTimeFormatInfo = DateTimeFormatInfo.ReadOnly(info);
        }
        public void ReadOnly(DateTimeFormatInfo format, bool originalFormatIsReadOnly)
        {
            Assert.Equal(originalFormatIsReadOnly, format.IsReadOnly);

            DateTimeFormatInfo readOnlyFormat = DateTimeFormatInfo.ReadOnly(format);

            if (originalFormatIsReadOnly)
            {
                Assert.Same(format, readOnlyFormat);
            }
            else
            {
                Assert.NotSame(format, readOnlyFormat);
            }
            Assert.True(readOnlyFormat.IsReadOnly);
        }
Пример #11
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: IsReadOnly should return true for DateTimeFormatInfo created by ReadOnly method");

        try
        {
            DateTimeFormatInfo info = DateTimeFormatInfo.ReadOnly(new CultureInfo("en-us").DateTimeFormat);
            if (!info.IsReadOnly)
            {
                TestLibrary.TestFramework.LogError("003.1", "IsReadOnly returns false for DateTimeFormatInfo created by ReadOnly method");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
Пример #12
0
        public void TestReadOnlyMethod()
        {
            DateTimeFormatInfo info = DateTimeFormatInfo.ReadOnly(new CultureInfo("en-us").DateTimeFormat);

            Assert.True(info.IsReadOnly);
        }
 public void ReadOnly_Null_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("dtfi", () => DateTimeFormatInfo.ReadOnly(null)); // Dtfi is null
 }
Пример #14
0
 public void ReadOnly_Invalid()
 {
     Assert.Throws <ArgumentNullException>(() => DateTimeFormatInfo.ReadOnly(null)); // Dtfi is null
 }