public void UpdateContentsAndSave_OnValidCall_ConfirmResult()
        {
            // Arrange
            var fileSaved = false;
            var file      = new ShimSPFile
            {
                ParentFolderGet = () => new ShimSPFolder
                {
                    FilesGet = () => new ShimSPFileCollection
                    {
                        AddStringByteArrayBoolean = (_, __, ___) =>
                        {
                            fileSaved = true;
                            return(new ShimSPFile());
                        }
                    }
                },
                UrlGet = () => DummyString
            }.Instance;

            // Act
            ExtensionMethods.UpdateContentsAndSave(file, DummyString);

            // Assert
            fileSaved.ShouldBeTrue();
        }
        public void GetModel_WhenCalled_ReturnsString()
        {
            // Arrange
            const string fileName  = "fileName";
            const string extension = ".xml";

            var data      = string.Format(@"
                <model Name=""{0}""/>
                ", fileName);
            var byteArray = new byte[] { 1, 2, 3 };
            var file      = new ShimSPFile()
            {
                NameGet    = () => $"{fileName}{extension}",
                ItemGet    = () => spListItem,
                OpenBinary = () => byteArray
            }.Instance;

            spListCollection.ItemGetString           = _ => new ShimSPDocumentLibrary();
            spListItem.FileGet                       = () => file;
            ShimSPList.AllInstances.GetItemByIdInt32 = (_, __) => spListItem;
            ShimSPList.AllInstances.RootFolderGet    = _ => new ShimSPFolder()
            {
                FilesGet = () => new ShimSPFileCollection()
            };
            ShimSPBaseCollection.AllInstances.GetEnumerator = _ => new List <SPFile>()
            {
                file
            }.GetEnumerator();

            // Act
            var actual = Encoding.Default.GetBytes((string)privateObject.Invoke(
                                                       GetModelMethodName,
                                                       BindingFlags.Instance | BindingFlags.Public,
                                                       new object[] { data }));

            // Assert
            actual.ShouldSatisfyAllConditions(
                () => actual.Count().ShouldBe(3),
                () => actual[0].ShouldBe <byte>(1),
                () => actual[1].ShouldBe <byte>(2),
                () => actual[2].ShouldBe <byte>(3));
        }
        public void GetContents_OnValidCall_ConfirmResult()
        {
            // Arrange
            var file = new ShimSPFile
            {
                OpenBinaryStream = () => new ShimFileStream()
            }.Instance;

            ShimFileStream.AllInstances.DisposeBoolean = (_, __) => { };

            ShimStreamReader.ConstructorStream           = (_, __) => { };
            ShimStreamReader.AllInstances.DisposeBoolean = (_, __) => { };
            ShimStreamReader.AllInstances.ReadToEnd      = _ => DummyString;

            // Act
            var result = ExtensionMethods.GetContents(file);

            // Assert
            result.ShouldBe(DummyString);
        }
        public void LoadModels_WhenCalled_ReturnsString()
        {
            // Arrange
            const string fileName  = "fileName";
            const string extension = ".xml";

            var file = new ShimSPFile()
            {
                NameGet = () => $"C:\\{fileName}{extension}",
                ItemGet = () => spListItem,
                UrlGet  = () => DummyString
            }.Instance;

            spListCollection.ItemGetString           = _ => new ShimSPDocumentLibrary();
            ShimSPList.AllInstances.GetItemByIdInt32 = (_, __) => spListItem;
            ShimSPList.AllInstances.RootFolderGet    = _ => new ShimSPFolder()
            {
                FilesGet = () => new ShimSPFileCollection()
            };
            ShimSPBaseCollection.AllInstances.GetEnumerator = _ => new List <SPFile>()
            {
                file
            }.GetEnumerator();

            // Act
            var actual = XElement.Parse((string)privateObject.Invoke(
                                            LoadModelsMethodName,
                                            BindingFlags.Instance | BindingFlags.Public,
                                            new object[] { string.Empty }));

            // Assert
            actual.ShouldSatisfyAllConditions(
                () => actual.Name.LocalName.ShouldBe("AssignmentPlannerModels"),
                () => actual.Element("Models").Element("Model").Attribute("Name").Value.ShouldBe(fileName),
                () => actual.Element("Models").Element("Model").Attribute("Url").Value.ShouldBe($"{DummyString}/{DummyString}"));
        }
Beispiel #5
0
 private void SetupVariables()
 {
     validations       = 0;
     publicStatic      = BindingFlags.Static | BindingFlags.Public;
     nonPublicStatic   = BindingFlags.Static | BindingFlags.NonPublic;
     publicInstance    = BindingFlags.Instance | BindingFlags.Public;
     nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic;
     guid    = Guid.Parse(SampleGuidString1);
     request = new Dictionary <string, string>()
     {
         ["period"]     = DummyString,
         ["action"]     = DummyString,
         ["duser"]      = DummyString,
         ["ts_uids"]    = DummyString,
         ["tsitemuids"] = DummyString
     };
     currentDate = DateTime.Now;
     spWeb       = new ShimSPWeb()
     {
         IDGet                = () => guid,
         SiteGet              = () => spSite,
         ListsGet             = () => spListCollection,
         GetFolderString      = _ => spFolder,
         GetFileString        = _ => spFile,
         FoldersGet           = () => spFolderCollection,
         CurrentUserGet       = () => spUser,
         ServerRelativeUrlGet = () => SampleUrl,
         AllUsersGet          = () => new ShimSPUserCollection(),
         SiteUsersGet         = () => new ShimSPUserCollection(),
         TitleGet             = () => DummyString
     };
     spSite = new ShimSPSite()
     {
         IDGet             = () => guid,
         WebApplicationGet = () => new ShimSPWebApplication(),
         RootWebGet        = () => spWeb,
         FeaturesGet       = () => new ShimSPFeatureCollection()
         {
             ItemGetGuid = _ => new ShimSPFeature()
         },
         ContentDatabaseGet = () => new ShimSPContentDatabase()
     };
     spListCollection = new ShimSPListCollection()
     {
         TryGetListString = _ => spList,
         ItemGetString    = _ => spList,
         ItemGetGuid      = _ => spList
     };
     spList = new ShimSPList()
     {
         IDGet             = () => guid,
         FieldsGet         = () => spFieldCollection,
         GetItemByIdInt32  = _ => spListItem,
         ItemsGet          = () => spListItemCollection,
         GetItemsSPQuery   = _ => spListItemCollection,
         RootFolderGet     = () => spFolder,
         ParentWebGet      = () => spWeb,
         DefaultViewGet    = () => spView,
         ViewsGet          = () => spViewCollection,
         ContentTypesGet   = () => spContentTypeCollection,
         TitleGet          = () => DummyString,
         EventReceiversGet = () => new ShimSPEventReceiverDefinitionCollection(),
         DefaultViewUrlGet = () => SampleUrl
     };
     spListItemCollection = new ShimSPListItemCollection()
     {
         CountGet     = () => DummyInt,
         ItemGetInt32 = _ => spListItem
     };
     spListItem = new ShimSPListItem()
     {
         IDGet             = () => DummyInt,
         TitleGet          = () => DummyString,
         ItemGetString     = _ => DummyString,
         ItemGetGuid       = _ => DummyString,
         ItemSetGuidObject = (_, __) => { },
         Update            = () => { },
         FileGet           = () => spFile,
         ParentListGet     = () => spList,
         NameGet           = () => DummyString
     };
     spFieldCollection = new ShimSPFieldCollection()
     {
         GetFieldByInternalNameString = _ => spField,
         ContainsFieldString          = _ => false,
         GetFieldString = _ => spField,
         ItemGetString  = _ => spField
     };
     spField = new ShimSPField()
     {
         IdGet            = () => guid,
         TitleGet         = () => DummyString,
         InternalNameGet  = () => DummyString,
         ReadOnlyFieldGet = () => false,
         HiddenGet        = () => false,
         ReorderableGet   = () => true,
         TypeAsStringGet  = () => DummyString
     };
     spUser = new ShimSPUser()
     {
         IDGet          = () => DummyInt,
         IsSiteAdminGet = () => true,
         UserTokenGet   = () => new ShimSPUserToken(),
         EmailGet       = () => DummyString
     };
     spFolderCollection = new ShimSPFolderCollection()
     {
         ItemGetString = _ => spFolder,
         AddString     = _ => spFolder
     };
     spFolder = new ShimSPFolder()
     {
         ExistsGet     = () => false,
         SubFoldersGet = () => spFolderCollection,
         FilesGet      = () => spFileCollection,
         UrlGet        = () => SampleUrl,
         UniqueIdGet   = () => guid,
         ParentWebGet  = () => spWeb
     };
     spFileCollection = new ShimSPFileCollection()
     {
         CountGet = () => DummyInt,
         AddStringByteArrayBoolean = (_1, _2, _3) => spFile,
         AddStringStream           = (_1, _2) => spFile,
         ItemGetString             = _ => spFile
     };
     spFile = new ShimSPFile()
     {
         Delete                 = () => { },
         OpenBinaryStream       = () => null,
         NameGet                = () => DummyString,
         GetListItemStringArray = _ => spListItem
     };
     spViewCollection = new ShimSPViewCollection()
     {
         ItemGetString = _ => spView
     };
     spView = new ShimSPView()
     {
         ViewFieldsGet        = () => spViewFieldCollection,
         ServerRelativeUrlGet = () => SampleUrl
     };
     spViewFieldCollection   = new ShimSPViewFieldCollection();
     spContentTypeCollection = new ShimSPContentTypeCollection()
     {
         ItemGetString = _ => spContentType
     };
     spContentType = new ShimSPContentType()
     {
         IdGet         = () => default(SPContentTypeId),
         FieldLinksGet = () => spFieldLinkCollection
     };
     spFieldLinkCollection = new ShimSPFieldLinkCollection()
     {
         ItemGetGuid = _ => new ShimSPFieldLink()
     };
     transaction = new ShimSqlTransaction()
     {
         Commit   = () => { },
         Rollback = () => { }
     };
     dataReader = new ShimSqlDataReader()
     {
         Read             = () => false,
         GetInt32Int32    = _ => One,
         GetDateTimeInt32 = _ => currentDate,
         GetStringInt32   = _ => DummyString,
         GetGuidInt32     = _ => guid,
         Close            = () => { }
     };
 }