示例#1
0
        protected SimSPList(SPList instance)
            : base(instance)
        {
            this.contentTypes      = new SimSPContentTypeCollection();
            this.fields            = new SimSPFieldCollection();
            this.fieldIndexes      = new SimSPFieldIndexCollection();
            this.items             = new SimSPListItemCollection();
            this.views             = new SimSPViewCollection();
            this.contentTypes.List = this.Instance;
            this.fields.List       = this.Instance;
            this.fieldIndexes.List = this.Instance;
            this.items.List        = this.Instance;
            this.views.List        = this.Instance;
            this.GetOrCreateDefaultView();

            var shimSPList = new ShimSPList(instance);

            shimSPList.IDGet            = () => this.ID;
            shimSPList.HiddenGet        = () => this.Hidden;
            shimSPList.HiddenSetBoolean = (bool value) =>
            {
                this.Hidden = value;
            };
            shimSPList.EnableAttachmentsGet        = () => this.EnableAttachments;
            shimSPList.EnableAttachmentsSetBoolean = (bool value) =>
            {
                this.EnableAttachments = value;
            };
            shimSPList.TitleGet       = () => this.Title;
            shimSPList.TitleSetString = (string newTitle) =>
            {
                this.Title = newTitle;
            };
            shimSPList.RootFolderGet     = () => this.RootFolder;
            shimSPList.RootFolderUrlGet  = () => this.RootFolderUrl;
            shimSPList.DefaultViewGet    = () => this.GetOrCreateDefaultView().Instance;
            shimSPList.DefaultViewUrlGet = () =>
            {
                SimSPView orCreateDefaultView = this.GetOrCreateDefaultView();
                return(orCreateDefaultView.ServerRelativeUrl);
            };
            shimSPList.ParentWebGet     = () => this.ParentWeb;
            shimSPList.Delete           = new FakesDelegates.Action(this.Delete);
            shimSPList.ListsGet         = () => this.Lists;
            shimSPList.ItemsGet         = () => this.items.Instance;
            shimSPList.FieldsGet        = () => this.fields.Instance;
            shimSPList.FieldIndexesGet  = () => this.fieldIndexes.Instance;
            shimSPList.ContentTypesGet  = () => this.contentTypes.Instance;
            shimSPList.ViewsGet         = () => this.views.Instance;
            shimSPList.GetItemByIdInt32 = (int id) =>
            {
                foreach (SPListItem current in this.items)
                {
                    if (current.ID == id)
                    {
                        return(current);
                    }
                }
                throw new ArgumentException();
            };
            shimSPList.GetItemsSPView = (SPView view) => this.GetItems().Instance;
            shimSPList.ItemCountGet   = () => this.Items.Count;
            shimSPList.Update         = () =>
            {
                this.Updated = new bool?(false);
            };
            shimSPList.UpdateBoolean = (bool fromMigration) =>
            {
                this.Updated = new bool?(fromMigration);
            };
            shimSPList.AddItem = () => this.AddItem();
            shimSPList.ContentTypesEnabledGet        = () => this.ContentTypesEnabled;
            shimSPList.ContentTypesEnabledSetBoolean = (bool value) =>
            {
                this.ContentTypesEnabled = value;
            };
            this.Fake = shimSPList;
        }
示例#2
0
        public SimSPWeb(SPWeb instance)
            : base(instance)
        {
            this.fields                = new SimSPFieldCollection();
            this.availableFields       = new SimSPFieldCollection();
            this.lists                 = new SimSPListCollection();
            this.users                 = new SimSPUserCollection();
            this.features              = new SimSPFeatureCollection();
            this.contentTypes          = new SimSPContentTypeCollection();
            this.availableContentTypes = new SimSPContentTypeCollection();
            this.folders               = new SimSPFolderCollection();
            this.properties            = new SimSPPropertyBag();
            this.webs                 = new SimSPWebCollection(this);
            this.allProperties        = new Hashtable();
            this.Exists               = true;
            this.lists.Web            = this.Instance;
            this.features.ScopeParent = this.Instance;
            this.contentTypes.Web     = this.Instance;
            this.fields.Web           = this.Instance;

            var shimSPWeb = new ShimSPWeb(instance);

            shimSPWeb.IDGet                      = (() => this.ID);
            shimSPWeb.UrlGet                     = (() => this.Url);
            shimSPWeb.TitleGet                   = (() => this.Title);
            shimSPWeb.NameGet                    = (() => this.Name);
            shimSPWeb.ParentWebGet               = (() => this.ParentWeb);
            shimSPWeb.ParentWebIdGet             = (() => this.ParentWebId);
            shimSPWeb.RootFolderGet              = (() => this.RootFolder.Instance);
            shimSPWeb.ServerRelativeUrlGet       = (() => this.ServerRelativeUrl);
            shimSPWeb.ServerRelativeUrlSetString = (delegate(string value)
            {
                this.ServerRelativeUrl = value;
            });
            shimSPWeb.SiteGet                      = (() => this.Site);
            shimSPWeb.CurrentUserGet               = (() => this.CurrentUser);
            shimSPWeb.AllowUnsafeUpdatesGet        = (() => this.AllowUnsafeUpdates);
            shimSPWeb.AllowUnsafeUpdatesSetBoolean = (delegate(bool value)
            {
                this.AllowUnsafeUpdates = value;
            });
            shimSPWeb.ExistsGet                = (() => this.Exists);
            shimSPWeb.LocaleGet                = (() => this.Locale);
            shimSPWeb.ListsGet                 = (() => this.lists.Instance);
            shimSPWeb.UsersGet                 = (() => this.users.Instance);
            shimSPWeb.FeaturesGet              = (() => this.features.Instance);
            shimSPWeb.ContentTypesGet          = (() => this.contentTypes.Instance);
            shimSPWeb.AvailableContentTypesGet = (() => this.availableContentTypes.Instance);
            shimSPWeb.FieldsGet                = (() => this.fields.Instance);
            shimSPWeb.AvailableFieldsGet       = (() => this.availableFields.Instance);
            shimSPWeb.PropertiesGet            = (() => this.properties.Instance);
            shimSPWeb.WebsGet          = (() => this.webs.Instance);
            shimSPWeb.AllPropertiesGet = (() => this.allProperties);
            shimSPWeb.FoldersGet       = (() => this.folders.Instance);
            shimSPWeb.GetFolderString  = (delegate(string url)
            {
                using (IEnumerator <SPFolder> enumerator = (
                           from folder in this.folders
                           where folder.Url == url
                           select folder).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        return(enumerator.Current);
                    }
                }
                throw new ArgumentException(url);
            });
            shimSPWeb.GetFolderGuid = (delegate(Guid id)
            {
                using (IEnumerator <SPFolder> enumerator = (
                           from folder in this.folders
                           where folder.UniqueId == id
                           select folder).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        return(enumerator.Current);
                    }
                }
                throw new ArgumentException(id.ToString());
            });
            shimSPWeb.Dispose = (delegate
            {
                this.DisposeCount++;
            });
            shimSPWeb.Update = (delegate
            {
                this.Updated = true;
            });
            shimSPWeb.SetPropertyObjectObject = (delegate(object name, object value)
            {
                this.AllProperties[name] = value;
            });
            shimSPWeb.GetPropertyObject = ((object name) => this.AllProperties[name]);
            shimSPWeb.GetListString     = ((string url) => (
                                               from list in this.Lists
                                               let blist = SimSPList.FromInstance(list)
                                                           where blist != null && blist.Url == url
                                                           select list).FirstOrDefault <SPList>());
            shimSPWeb.Delete = (new FakesDelegates.Action(this.Delete));

            this.Fake = shimSPWeb;
        }