示例#1
0
        public void JoinTest()
        {
            // Get file link for link memo id = 1
            int      linkMemoId = 1;
            FileLink fl         = LinkManager.GetLink(linkMemoId);

            // Get the files for file link
            List <TrackedFile> linkedFiles = fl.GetFiles();

            // Verify at least one file is returned
            Assert.IsNotNull(linkedFiles);

            // Get all files
            List <TrackedFile> allFiles = FileManagerDAL.GetFiles();

            // Find a file not in the MemoId = 1 list
            TrackedFile joinFile = null;

            // Get a list of the file IDs of the linked files
            List <int> linkedFileIDs = new List <int>();

            foreach (var file in linkedFiles)
            {
                linkedFileIDs.Add(file.FileID);
            }

            //
            foreach (var file in allFiles)
            {
                if (!linkedFileIDs.Contains(file.FileID))
                {
                    joinFile = file;
                    break;
                }
            }

            // Join file if we have found one
            if (joinFile != null)
            {
                // Join file
                fl.Join(joinFile.FileID);

                // Reteieve file list
                linkedFiles = fl.GetFiles();

                // Fill linedFileIDs with new file ID list
                linkedFileIDs.Clear();
                foreach (var file in linkedFiles)
                {
                    linkedFileIDs.Add(file.FileID);
                }

                // Verify joined file exists in the list
                Assert.IsTrue(linkedFileIDs.Contains(joinFile.FileID));

                // Remove joined file
                fl.RemoveFiles(new List <int> {
                    joinFile.FileID
                });
            }
        }