Class SitecoreFieldDateTimeMapper
Inheritance: AbstractSitecoreFieldMapper
        public void SetField_DateTimePassed_SetsFieldValue()
        {
            //Assign
            string expected = "20120101T010101";
            DateTime objectValue = new DateTime(2012, 01, 01, 01, 01, 01);
            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldDateTimeMapper/GetField");
            var field = item.Fields[FieldName];

            var mapper = new SitecoreFieldDateTimeMapper();

            using (new ItemEditing(item, true))
            {
                field.Value = string.Empty;
            }
             
            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, objectValue, null, null);
            }
        

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
        public void GetField_FieldContainsValidIsoDate_ReturnsDateTime()
        {
            //Assign 
            string fieldValue = "20121101T230000";
            DateTime expected = new DateTime(2012, 11, 01, 23, 00, 00);
            var fieldId = Guid.NewGuid();

            var item = Helpers.CreateFakeItem(fieldId, fieldValue);
            var field = item.Fields[new ID(fieldId)];

            var mapper = new SitecoreFieldDateTimeMapper();


            //Act
            var result = (DateTime)mapper.GetField(field, null, null);

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void GetField_FieldContainsValidDate_ReturnsDateTime()
        {
            //Assign
            string fieldValue = "20120101T010101";
            DateTime expected = new DateTime(2012,01,01,01,01,01);
            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldDateTimeMapper/GetField");
            var field = item.Fields[FieldName];

            var mapper = new SitecoreFieldDateTimeMapper();

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            //Act
            var result = (DateTime) mapper.GetField(field, null, null);

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void SetField_DateTimePassed_SetsFieldValue()
        {
            //Assign
            string expected = "20120101T010101";
            DateTime objectValue = new DateTime(2012, 01, 01, 01, 01, 01);
            var fieldId = Guid.NewGuid();

            var item = Helpers.CreateFakeItem(fieldId, string.Empty);
            var field = item.Fields[new ID(fieldId)];

            var mapper = new SitecoreFieldDateTimeMapper();

            item.Editing.BeginEdit();
            //Act
          
                mapper.SetField(field, objectValue, null, null);
           
        

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
        public void SetField_NonDateTimePassed_ExceptionThrown()
        {
            //Assign
            string expected = "20120101T010101Z";
            int objectValue = 4;
            var fieldId = Guid.NewGuid();

            var item = Helpers.CreateFakeItem(fieldId, string.Empty);
            var field = item.Fields[new ID(fieldId)];

            var mapper = new SitecoreFieldDateTimeMapper();

            item.Editing.BeginEdit();

            //Act

            mapper.SetField(field, objectValue, null, null);



            //Assert
        }
        public void SetField_NonDateTimePassed_ExceptionThrown()
        {
            //Assign
            string expected = "20120101T010101";
            int objectValue = 4; 
            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldDateTimeMapper/GetField");
            var field = item.Fields[FieldName];

            var mapper = new SitecoreFieldDateTimeMapper();

            using (new ItemEditing(item, true))
            {
                field.Value = string.Empty;
            }

            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, objectValue, null, null);
            }


            //Assert
        }