Beispiel #1
0
        public void ImageSetCanBeCreatedWithDuplicateFiles()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Imageset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Imageset-duplicate.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageset    = catalog.OpenImageSet("img1");

            var filePath = testFiles.CreateFile("data1.png", "img1");

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                filePath);

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                filePath);

            catalog.Write();

            string imagesetPath = Path.Combine(catalogPath, "img1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imagesetPath));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Imageset-duplicate.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1-1.png"), "img1");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Beispiel #2
0
        public void ImageSetCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Imageset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Imageset1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageset    = catalog.OpenImageSet("img1");

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                testFiles.CreateFile("data1.png", "img1"));

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                testFiles.CreateFile("data2.png", "img2"));

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X1),
                                testFiles.CreateFile("data3.png", "img3"));

            var alignment = new ImageAlignment();

            alignment.top    = 1;
            alignment.bottom = 2;
            alignment.left   = 3;
            alignment.right  = 4;

            var resizing = new ImageResizing();

            resizing.type             = ImageResizing.SlicingType.HorizontalAndVertical;
            resizing.top              = 1;
            resizing.bottom           = 2;
            resizing.left             = 3;
            resizing.right            = 4;
            resizing.centerResizeMode = ImageResizing.ResizeMode.Stretch;
            resizing.centerWidth      = 2;
            resizing.centerHeight     = 4;

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X3),
                                testFiles.CreateFile("data4.png", "img4"), alignment, resizing);
            catalog.Write();

            string imagesetPath = Path.Combine(catalogPath, "img1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imagesetPath));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Imageset1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data2.png"), "img2");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data3.png"), "img3");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data4.png"), "img4");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }