Example #1
0
        private void EnsureFieldImpl(Field fieldInfo)
        {
            if (ContainsFieldImpl(fieldInfo.Property))
            {
                return;
            }

            if (fieldInfo.Type == SPFieldType.Lookup)
            {
                if (string.IsNullOrEmpty(fieldInfo.LookupList))
                {
                    throw new SharepointCommonException(string.Format("LookupList must be set for lookup fields. ({0})", fieldInfo.Name));
                }

                var lookupList = ParentWeb.Web.TryGetListByNameOrUrlOrId(fieldInfo.LookupList);

                if (lookupList == null)
                {
                    throw new SharepointCommonException(string.Format("List {0} not found on {1}", fieldInfo.LookupList, ParentWeb.Web.Url));
                }

                List.Fields.AddLookup(fieldInfo.Name, lookupList.ID, false);
            }
            else if (fieldInfo.Type == SPFieldType.Invalid && fieldInfo.FieldAttribute.FieldProvider != null)
            {
                var customPropAttrs = (CustomPropertyAttribute[])Attribute.GetCustomAttributes(fieldInfo.Property, typeof(CustomPropertyAttribute));

                var sb = new StringBuilder();
                var xv = new XmlTextWriter(new StringWriter(sb));
                xv.WriteStartElement("Field");

                xv.WriteAttributeString("ID", Guid.NewGuid().ToString());
                xv.WriteAttributeString("Type", fieldInfo.FieldAttribute.FieldProvider.FieldTypeAsString);
                xv.WriteAttributeString("DisplayName", fieldInfo.Name);

                foreach (var customProp in customPropAttrs)
                {
                    xv.WriteAttributeString(customProp.Name, customProp.Value);
                }

                xv.WriteEndElement();

                Mockable.AddFieldAsXml(List.Fields, sb.ToString());

                //  List.Fields.AddFieldAsXml(sb.ToString());
            }
            else
            {
                List.Fields.Add(fieldInfo.Name, fieldInfo.Type, false);
            }

            //var field = List.Fields.GetFieldByInternalName(fieldInfo.Name);
            var field = Mockable.GetFieldByInternalName(List.Fields, fieldInfo.Name);

            Mockable.FieldMapper_SetFieldProperties(field, fieldInfo);
        }
Example #2
0
    void TestMethod()
    {
        //Arrange
        object factoryResult = new object();     //The expected result
        var    factory       = Substitute.For <IFactory>();

        factory.Create().Returns(x => factoryResult);     //mocked factory should return this
        IMockable mockable = new Mockable(factory);

        //Act
        object mockableResult = mockable.SomeMethod();     //Invoke subject under test

        //Assert
        factory.Received(1).Create();                //assert expected behavior
        Assert.Equal(mockableResult, factoryResult); //objects should match
    }