Exemplo n.º 1
0
        public void DateTimeField_GetValue_ReturnsDateMinWhenEmpty()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.DATETIME, string.Empty);

                var field = new DateTimeField(new Lazy <Field>(() => item[TestFields.DATETIME]), null);

                Assert.AreEqual(field.Value, DateTime.MinValue);
            }
        }
Exemplo n.º 2
0
        public void DateTimeField_HasValue_WhenFalse()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.DATETIME, string.Empty);

                var field = new DateTimeField(new Lazy <Field>(() => item[TestFields.DATETIME]), null);

                Assert.IsFalse(field.HasValue);
            }
        }
Exemplo n.º 3
0
        public void BooleanField_GetValue_ReturnsFalseWhenZero()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "0");

                var field = new BooleanField(new LazyField(() => item[TestFields.BOOLEAN], "TEST", TestFields.BOOLEAN), null);

                Assert.False(field.Value);
            }
        }
Exemplo n.º 4
0
        public void DateTimeField_HasValue_WhenTrue()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.DATETIME, DateUtil.IsoNow);

                var field = new DateTimeField(new Lazy <Field>(() => item[TestFields.DATETIME]), null);

                Assert.IsTrue(field.HasValue);
            }
        }
Exemplo n.º 5
0
        public void BooleanField_GetValue_ReturnsFalseWhenBlank()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "");

                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                Assert.IsFalse(field.Value);
            }
        }
Exemplo n.º 6
0
        public void BooleanField_GetValue_WhenTrue()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "1");

                var field = new BooleanField(new LazyField(() => item[TestFields.BOOLEAN], "TEST", TestFields.BOOLEAN), null);

                Assert.True(field.Value);
            }
        }
Exemplo n.º 7
0
        public void DateTimeField_GetValue_ReturnsValidValue()
        {
            using (var item = new TestItemContext())
            {
                var dateSet = DateUtil.IsoDateToDateTime(DateUtil.ToIsoDate(DateTime.Now));                 // convert now to sitecore format and back to make sure the rounding is correct - sitecore doesn't have quite the same precision (no msec) as DateTime.Now
                item.SetField(TestFields.DATETIME, DateUtil.ToIsoDate(dateSet));

                var field = new DateTimeField(new Lazy <Field>(() => item[TestFields.DATETIME]), null);

                Assert.AreEqual(field.Value, dateSet);
            }
        }
Exemplo n.º 8
0
        public void BooleanField_CanImplicitCastToCheckboxField()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "1");

                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                CheckboxField sitecoreField = field;

                Assert.IsTrue(sitecoreField.Checked);
            }
        }
Exemplo n.º 9
0
        public void BooleanField_CanImplicitCastToBool()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "1");

                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                bool boolean = field;

                Assert.IsTrue(boolean);
            }
        }
Exemplo n.º 10
0
        public void NumericField_CanImplicitCastToDecimal()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.NUMERIC, "3.14159");

                var field = new NumericField(new Lazy <Field>(() => item[TestFields.NUMERIC]), null);

                decimal value = field;

                Assert.AreEqual(value, 3.14159m);
            }
        }
Exemplo n.º 11
0
        public void IntegerField_CanImplicitCastToInt()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.INTEGER, "16");

                var field = new IntegerField(new Lazy <Field>(() => item[TestFields.INTEGER]), null);

                int value = field;

                Assert.AreEqual(value, 16);
            }
        }
Exemplo n.º 12
0
        public void TextField_CanImplicitCastToString()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.STRING, "the Monstrous Blue Whale #1");

                var field = new TextField(new Lazy <Field>(() => item[TestFields.STRING]), null);

                string value = field;

                Assert.AreEqual(value, "the Monstrous Blue Whale #1");
            }
        }
Exemplo n.º 13
0
        public void DateTimeField_CanImplicitCastToDateField()
        {
            using (var item = new TestItemContext())
            {
                var setTime = DateUtil.IsoNow;
                item.SetField(TestFields.DATETIME, setTime);

                var field = new DateTimeField(new Lazy <Field>(() => item[TestFields.DATETIME]), null);

                DateField sitecoreField = field;

                Assert.AreEqual(DateUtil.IsoDateToDateTime(setTime), sitecoreField.DateTime);
            }
        }