public void AddFormToContent_CopyFiles_ContentHasFileFields()
        {
            var mockFileSystem = new Mock <IFileSystem>();

            DbConnector.FileSystem = mockFileSystem.Object;

            var list = new List <DynamicImageCopyFile>();

            mockFileSystem.Setup(x => x.CopyFile(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((from, to) => { list.Add(new DynamicImageCopyFile(from, to)); });

            const string name1   = "test123";
            const string ext1    = "jpg";
            const string name2   = "test456";
            const string ext2    = "png";
            const string folder2 = "center";

            var imageName = DbConnector.FieldName(Global.SiteId, ContentName, "BaseImage");
            var article1  = new Hashtable
            {
                [imageName] = $"{name1}.{ext1}"
            };

            var article2 = new Hashtable
            {
                [imageName] = $"{folder2}/{name2}.{ext2}"
            };

            var id = 0;

            Assert.DoesNotThrow(() => { id = DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, 0); }, "Create");

            var ids                  = new[] { id };
            var attrFolder           = DbConnector.GetDirectoryForFileAttribute(DbConnector.FieldID(Global.SiteId, ContentName, ImageName));
            var currentVersionFolder = DbConnector.GetCurrentVersionFolderForContent(ContentId);

            Assert.DoesNotThrow(() => { id = DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article2, id); }, "Update");

            var paths = Global.GetMaxVersions(DbConnector, ids).Select(n => DbConnector.GetVersionFolderForContent(ContentId, n)).ToArray();

            Assert.DoesNotThrow(() => { id = DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article2, id); }, "Update");

            var paths2 = Global.GetMaxVersions(DbConnector, ids).Select(n => DbConnector.GetVersionFolderForContent(ContentId, n)).ToArray();
            var file1  = new DynamicImageCopyFile(
                Path.Combine(attrFolder, article1[imageName].ToString()),
                Path.Combine(currentVersionFolder, article1[imageName].ToString())
                );

            var file2 = new DynamicImageCopyFile(
                Path.Combine(currentVersionFolder, article1[imageName].ToString()),
                Path.Combine(paths[0], article1[imageName].ToString())
                );

            var file3 = new DynamicImageCopyFile(
                Path.Combine(attrFolder, article2[imageName].ToString().Replace(@"/", @"\")),
                Path.Combine(currentVersionFolder, $"{name2}.{ext2}")
                );

            var file4 = new DynamicImageCopyFile(
                Path.Combine(currentVersionFolder, $"{name2}.{ext2}"),
                Path.Combine(paths2[0], $"{name2}.{ext2}")
                );

            Assert.That(list, Has.Member(file1), "Copy old file to current dir");
            Assert.That(list, Has.Member(file2), "Copy old file to version dir");
            Assert.That(list, Has.Member(file3), "Copy new file to current dir without subfolders");
            Assert.That(list, Has.Member(file4), "Copy new file to version dir without subfolders");
        }
        public void MassUpdate_CopyFiles_ContentHasFileFields()
        {
            var mockFileSystem = new Mock <IFileSystem>();

            DbConnector.FileSystem = mockFileSystem.Object;

            var list = new List <DynamicImageCopyFile>();

            mockFileSystem.Setup(x => x.CopyFile(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((from, to) => { list.Add(new DynamicImageCopyFile(from, to)); });

            var          values  = new List <Dictionary <string, string> >();
            const string name1   = "test234";
            const string name2   = "test456";
            const string ext1    = "jpg";
            const string ext2    = "png";
            const string folder2 = "center";

            var ids      = new[] { BaseArticlesIds[0], BaseArticlesIds[1] };
            var article1 = new Dictionary <string, string>
            {
                [FieldName.ContentItemId] = BaseArticlesIds[0].ToString(),
                [ImageName] = $"{name1}.{ext1}"
            };

            values.Add(article1);
            var article2 = new Dictionary <string, string>
            {
                [FieldName.ContentItemId] = BaseArticlesIds[1].ToString(),
                [ImageName] = $"{folder2}/{name2}.{ext2}"
            };

            values.Add(article2);
            var attrFolder           = DbConnector.GetDirectoryForFileAttribute(DbConnector.FieldID(Global.SiteId, ContentName, ImageName));
            var currentVersionFolder = DbConnector.GetCurrentVersionFolderForContent(ContentId);
            var fileValuesBefore     = Global.GetFieldValues <string>(DbConnector, ContentId, ImageName, ids);

            Assert.DoesNotThrow(() => DbConnector.MassUpdate(ContentId, values, 1), "Update");
            var paths = Global.GetMaxVersions(DbConnector, ids).Select(n => DbConnector.GetVersionFolderForContent(ContentId, n)).ToArray();
            var file1 = new DynamicImageCopyFile(
                Path.Combine(currentVersionFolder, fileValuesBefore[0]),
                Path.Combine(paths[0], fileValuesBefore[0])
                );

            var file2 = new DynamicImageCopyFile(
                Path.Combine(currentVersionFolder, fileValuesBefore[1]),
                Path.Combine(paths[1], fileValuesBefore[1])
                );

            var file3 = new DynamicImageCopyFile(
                Path.Combine(attrFolder, article1[ImageName]),
                Path.Combine(currentVersionFolder, article1[ImageName])
                );

            var file4 = new DynamicImageCopyFile(
                Path.Combine(attrFolder, article2[ImageName].Replace(@"/", @"\")),
                Path.Combine(currentVersionFolder, $"{name2}.{ext2}")
                );

            Assert.That(list, Has.Member(file1), "Copy old file 1 to version dir");
            Assert.That(list, Has.Member(file2), "Copy old file 2 to version dir");
            Assert.That(list, Has.Member(file3), "Copy new file 1 to current dir");
            Assert.That(list, Has.Member(file4), "Copy new file 2 to current dir without subfolders");

            Assert.DoesNotThrow(() => DbConnector.MassUpdate(ContentId, values, 1), "Update");
            var paths2 = Global.GetMaxVersions(DbConnector, ids).Select(n => DbConnector.GetVersionFolderForContent(ContentId, n)).ToArray();
            var file5  = new DynamicImageCopyFile(
                Path.Combine(currentVersionFolder, $"{name2}.{ext2}"),
                Path.Combine(paths2[1], $"{name2}.{ext2}")
                );

            Assert.That(list, Has.Member(file5), "Copy new file 2 to version dir without subfolders");
        }