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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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"); } }
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); } }