public void SetField_CollectionHas2Values_FieldContainsQueryString()
        {
            //Assign
            var expected = "Name1=Value1&Name2=Value2";
            var item     = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldNameValueCollectionMapper/SetField");
            var field    = item.Fields[FieldName];
            var value    = new NameValueCollection();

            value.Add("Name1", "Value1");
            value.Add("Name2", "Value2");
            var mapper = new SitecoreFieldNameValueCollectionMapper();

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

            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, value, null, null);
            }
            //Assert
            Assert.AreEqual(expected, field.Value);
        }
Ejemplo n.º 2
0
        public void SetField_CollectionHas0Values_FieldIsEmpty()
        {
            //Assign
            var expected = "";
            var fieldId  = Guid.NewGuid();

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

            var value  = new NameValueCollection();
            var mapper = new SitecoreFieldNameValueCollectionMapper();

            item.Editing.BeginEdit();

            //Act

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

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
Ejemplo n.º 3
0
        public void SetField_CollectionHas2Values_FieldContainsQueryString()
        {
            //Assign
            var expected = "Name1=Value1&Name2=Value2";
            var fieldId  = Guid.NewGuid();

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

            var value = new NameValueCollection();

            value.Add("Name1", "Value1");
            value.Add("Name2", "Value2");
            var mapper = new SitecoreFieldNameValueCollectionMapper();

            item.Editing.BeginEdit();

            //Act

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

            //Assert
            Assert.AreEqual(expected, field.Value);
        }