Exemplo n.º 1
0
        public void AddFormToContent_RemoveVersionDirectory_VersionOverflow()
        {
            var mockFileSystem = new Mock <IFileSystem>();

            DbConnector.FileSystem = mockFileSystem.Object;
            var actualPathes = new List <string>();

            mockFileSystem.Setup(x => x.RemoveDirectory(It.IsAny <string>())).Callback <string>(path => { actualPathes.Add(path); });

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

            var id = 0;

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

            var ids = new[] { id };

            Assert.DoesNotThrow(() => { id = DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, 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 article1, id); }, "Update");

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

            Assert.That(paths, Is.EqualTo(actualPathes), "RemoveDirectory calls");
        }
Exemplo n.º 2
0
        public void AddFormToContent_ThrowsException_ValidateAttributeValueMissedData()
        {
            var article1 = new Hashtable
            {
                [FieldName.ContentItemId] = "0"
            };

            Assert.That(() => { DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, BaseArticlesIds[0]); }, Throws.Exception.TypeOf <QpInvalidAttributeException>().And.Message.Contains("is required"), "Validate required fields");
        }
Exemplo n.º 3
0
        public void AddFormToContent_ThrowsException_ValidateAttributeValueStringSizeExceeded()
        {
            var titleName = DbConnector.FieldName(Global.SiteId, ContentName, "Title");
            var article1  = new Hashtable
            {
                [titleName] = new string('*', 1000)
            };

            Assert.That(() => { DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, BaseArticlesIds[0]); }, Throws.Exception.TypeOf <QpInvalidAttributeException>().And.Message.Contains("too long"), "Validate string size");
        }
Exemplo n.º 4
0
        public void AddFormToContent_ThrowsException_ValidateConstraintForDataConflict()
        {
            var titleName  = DbConnector.FieldName(Global.SiteId, ContentName, "Title");
            var numberName = DbConnector.FieldName(Global.SiteId, ContentName, "Number");
            var fn         = SqlQuerySyntaxHelper.FieldName(DbConnector.DatabaseType, "Title");
            var cmd        = DbConnector.CreateDbCommand($"select content_item_id from content_{ContentId}_united where {fn} <> 'Name2'");
            var id         = (int)(decimal)DbConnector.GetRealScalarData(cmd);
            var article1   = new Hashtable
            {
                [titleName]  = "Name2",
                [numberName] = "9,5"
            };

            Assert.That(() => { id = DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, id); }, Throws.Exception.TypeOf <QpInvalidAttributeException>().And.Message.Contains("Unique constraint violation"), "Duplicate of test data should violate rules");
        }
Exemplo n.º 5
0
        public void AddFormToContent_IsValid_ValidateConstraintSameData()
        {
            var first      = ContentItem.Read(BaseArticlesIds[0], DbConnector);
            var titleName  = DbConnector.FieldName(Global.SiteId, ContentName, "Title");
            var numberName = DbConnector.FieldName(Global.SiteId, ContentName, "Number");
            var article1   = new Hashtable
            {
                [titleName]  = first.FieldValues["Title"].Data,
                [numberName] = first.FieldValues["Number"].Data
            };

            var modified = Global.GetModified(DbConnector, ContentId);

            Assert.DoesNotThrow(() => { DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, BaseArticlesIds[0]); }, "Update existing data");

            var modified2 = Global.GetModified(DbConnector, ContentId);
            var first2    = ContentItem.Read(BaseArticlesIds[0], DbConnector);

            Assert.That(modified, Is.Not.EqualTo(modified2), "Modification dates should be changed");
            Assert.That(first2.FieldValues["Title"].Data, Is.EqualTo(first.FieldValues["Title"].Data), "Data should remain the same");
        }
Exemplo n.º 6
0
        public void AddFormToContent_DoesntCreateVersionDirectory_DisableVersionControlFields()
        {
            var mockFileSystem = new Mock <IFileSystem>();

            DbConnector.FileSystem = mockFileSystem.Object;
            mockFileSystem.Setup(x => x.CreateDirectory(It.IsAny <string>()));
            mockFileSystem.Setup(x => x.CopyFile(It.IsAny <string>(), It.IsAny <string>()));

            var article1 = new Hashtable
            {
                ["Video"] = "newtest.mp4"
            };

            var id = 0;

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

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

            mockFileSystem.Verify(x => x.CreateDirectory(It.IsAny <string>()), Times.Never(), "Shouldn't be called for disabled versions control fields");
            mockFileSystem.Verify(x => x.CopyFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never(), "Shouldn't be called for disabled versions control fields");
        }
Exemplo n.º 7
0
        public void AddFormToContent_CreateDynamicImages_ContentHasDynamicImages()
        {
            var mockDynamicImage = new Mock <IDynamicImageCreator>();

            DbConnector.DynamicImageCreator = mockDynamicImage.Object;

            var actualImages = new List <DynamicImageInfo>();

            mockDynamicImage
            .Setup(x => x.CreateDynamicImage(It.IsAny <DynamicImageInfo>()))
            .Callback <DynamicImageInfo>(info => { actualImages.Add(info); });

            const string name1   = "test789";
            const string name2   = "test321";
            const string ext1    = "jpg";
            const string ext2    = "png";
            const string folder2 = "cnt";

            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 };
            const string imagePng = "PngImage";
            const string imageJpg = "JpgImage";
            const string imageGif = "GifImage";

            var pngs1 = Global.GetFieldValues <string>(DbConnector, ContentId, imagePng, ids);
            var jpgs1 = Global.GetFieldValues <string>(DbConnector, ContentId, imageJpg, ids);
            var gifs1 = Global.GetFieldValues <string>(DbConnector, ContentId, imageGif, ids);

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

            var pngs2 = Global.GetFieldValues <string>(DbConnector, ContentId, imagePng, ids);
            var jpgs2 = Global.GetFieldValues <string>(DbConnector, ContentId, imageJpg, ids);
            var gifs2 = Global.GetFieldValues <string>(DbConnector, ContentId, imageGif, ids);

            var pngId = DbConnector.FieldID(Global.SiteId, ContentName, imagePng);
            var jpgId = DbConnector.FieldID(Global.SiteId, ContentName, imageJpg);
            var gifId = DbConnector.FieldID(Global.SiteId, ContentName, imageGif);

            var dbPng1 = $"field_{pngId}/{name1}.PNG";
            var dbPng2 = $"field_{pngId}/{folder2}/{name2}.PNG";
            var dbJpg1 = $"field_{jpgId}/{name1}.JPG";
            var dbJpg2 = $"field_{jpgId}/{folder2}/{name2}.JPG";
            var dbGif1 = $"field_{gifId}/{name1}.GIF";
            var dbGif2 = $"field_{gifId}/{folder2}/{name2}.GIF";

            Assert.That(actualImages.Any(n => n.ImageName == article1[imageName].ToString() && n.AttrId == pngId), Is.True, "Create png for article 1");
            Assert.That(actualImages.Any(n => n.ImageName == article2[imageName].ToString() && n.AttrId == pngId), Is.True, "Create png for article 2");
            Assert.That(actualImages.Any(n => n.ImageName == article1[imageName].ToString() && n.AttrId == jpgId), Is.True, "Create jpg for article 1");
            Assert.That(actualImages.Any(n => n.ImageName == article2[imageName].ToString() && n.AttrId == jpgId), Is.True, "Create jpg for article 2");
            Assert.That(actualImages.Any(n => n.ImageName == article1[imageName].ToString() && n.AttrId == gifId), Is.True, "Create gif for article 1");
            Assert.That(actualImages.Any(n => n.ImageName == article2[imageName].ToString() && n.AttrId == gifId), Is.True, "Create gif for article 2");

            Assert.That(pngs1[0], Is.EqualTo(dbPng1), "Dynamic image value for png in article 1");
            Assert.That(pngs2[0], Is.EqualTo(dbPng2), "Dynamic image value for png in article 2");
            Assert.That(jpgs1[0], Is.EqualTo(dbJpg1), "Dynamic image value for jpg in article 1");
            Assert.That(jpgs2[0], Is.EqualTo(dbJpg2), "Dynamic image value for jpg in article 2");
            Assert.That(gifs1[0], Is.EqualTo(dbGif1), "Dynamic image value for gif in article 1");
            Assert.That(gifs2[0], Is.EqualTo(dbGif2), "Dynamic image value for gif in article 2");
        }
Exemplo n.º 8
0
        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");
        }