public void SketchFileWithoutCompatibilityVersionDoesNotFail()
        {
            // The first sketch-files in the open format doesn't seem to have compatibilityVersion field
            var archive    = Substitute.For <ISketchArchive>();
            var appVersion = 3.14;
            var version    = 91;

            var json =
                @"{
				'appVersion': '"                 + appVersion + @"',
				'build': 45422,
				'variant': 'NONAPPSTORE',
				'version': '"                 + version + @"'
			}"            ;

            using (var jsonStream = new MemoryStream(Encoding.ASCII.GetBytes(json))) {
                archive.OpenFile("meta.json")
                .Returns(jsonStream);

                var log = new MessageListLogger();

                CompatibilityChecker.Check("dummy.sketch", archive, log);

                Assert.AreEqual(1, log.ErrorsAndWarnings().Count);
                Assert.AreEqual(3, log.Messages.Count);
                Assert.That(log.ErrorsAndWarnings().First(),
                            Does.StartWith("WARNING:" + "\t" + "The sketch file was created with an older version"));
            }
        }
Exemple #2
0
        public void NestedSketchSymbolCreatesUxInstance()
        {
            var childSymbol = DocumentBuilder.SketchSymbolMaster("Inner").WithLayer(DocumentBuilder.Rectangle("R1"));

            var document = DocumentBuilder.SketchDocument()
                           .WithSymbol(childSymbol)
                           .WithSymbol(DocumentBuilder.SketchSymbolMaster("Outer").WithLayer(DocumentBuilder.SymbolInstanceOf(childSymbol)));

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);

            var files = Directory.EnumerateFiles(_outputDirectory);

            Assert.AreEqual(2, files.Count());
            Assert.IsTrue(files.First().EndsWith("Inner.ux"));
            Assert.IsTrue(files.Last().EndsWith("Outer.ux"));
            Assert.AreEqual(0, logger.ErrorsAndWarnings().Count);

            var ux = File.ReadAllText(files.Last());

            Assert.IsTrue(ux.Contains("<Sketch.Inner"));
            Assert.IsTrue(ux.Contains("</Sketch.Inner>"));
        }
        public void WhenOneFileFailsParsing_ReportsErrorAndKeepsConverting()
        {
            var parser         = Substitute.For <ISketchParser>();
            var guid           = Guid.NewGuid();
            var sketchDocument = new SketchDocument(guid, new List <SketchPage>());

            parser.Parse(Arg.Any <SketchArchive>()).Returns(
                _ => { throw new SketchParserException("Whenever I adjust my sail, I fail."); },
                _ => sketchDocument);

            var builder   = Substitute.For <IUxBuilder>();
            var log       = new MessageListLogger();
            var converter = new Converter(parser, builder, log);

            //Just some arbitrary valid sketch files to make sure `Load` works
            var arrowSketch = Path.Combine(FilesDirectory, "Arrow.sketch");
            var lineSketch  = Path.Combine(FilesDirectory, "Line.sketch");

            converter.Convert(new [] { arrowSketch, lineSketch }, TempDirectory);

            //Got error for the first file
            Assert.That(log.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(log.ErrorsAndWarnings()[0], Does.Match("Arrow.sketch.*I fail"));

            //Called builder for the second file, and only that
            builder.ReceivedWithAnyArgs(1).Build(null, null);
            builder.Received(1).Build(sketchDocument, TempDirectory);
        }
        public void WhenOneFileDoesntExist_ReportsErrorAndKeepsConverting()
        {
            var parser         = Substitute.For <ISketchParser>();
            var guid           = Guid.NewGuid();
            var sketchDocument = new SketchDocument(guid, new List <SketchPage>());

            parser.Parse(Arg.Any <SketchArchive>()).Returns(_ => sketchDocument);

            var builder   = Substitute.For <IUxBuilder>();
            var log       = new MessageListLogger();
            var converter = new Converter(parser, builder, log);

            var doesntExist = Path.Combine(TempDirectory, "IDontExist.sketch");
            var arrowSketch = Path.Combine(FilesDirectory, "Arrow.sketch");

            converter.Convert(new[] { doesntExist, arrowSketch }, TempDirectory);

            //Got error for the first file
            Assert.That(log.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(log.ErrorsAndWarnings()[0], Does.Match("Can't convert non-existing Sketch-file.*IDontExist.sketch"));

            //Called builder for the second file, and only that
            builder.ReceivedWithAnyArgs(1).Build(null, null);
            builder.Received(1).Build(sketchDocument, TempDirectory);
        }
Exemple #5
0
        public void ParseErrorInLayerLogsAndSkips()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.PathInvalidJson);
            var log = new MessageListLogger();

            var document = new SketchParser(log).Parse(mockSketchArchive);

            Assert.That(document.Pages.Count, Is.EqualTo(1));
            Assert.That(document.Pages[0].Layers.Count, Is.EqualTo(0));
            Assert.That(log.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(log.ErrorsAndWarnings()[0], Does.Match("Failed to parse layer"));
        }
        public void CanBeCalledTwice()
        {
            var log         = new MessageListLogger();
            var converter   = new Converter(new SketchParser(log), new SymbolsUxBuilder(log), log);
            var arrowSketch = Path.Combine(FilesDirectory, "Arrow.sketch");

            Assert.That(File.Exists(arrowSketch));
            converter.Convert(new [] { arrowSketch }, TempDirectory);
            Assert.That(log.ErrorsAndWarnings(), Is.Empty);
            converter.Convert(new [] { arrowSketch }, TempDirectory);
            Assert.That(log.ErrorsAndWarnings(), Is.Empty);
        }
Exemple #7
0
        public void UnsupportedLayerWarnsAndSkips()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.JellyfishLayerJson);
            var log = new MessageListLogger();

            var document = new SketchParser(log).Parse(mockSketchArchive);

            Assert.That(document.Pages.Count, Is.EqualTo(1));
            Assert.That(document.Pages[0].Layers.Count, Is.EqualTo(0));
            Assert.That(log.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(log.ErrorsAndWarnings()[0], Does.Match("Skipping layer 'Jellyfish' of unsupported type 'jellyfish'"));
        }
Exemple #8
0
        public void NoSymbolsInSketchDocumentProducesInfo()
        {
            var document = DocumentBuilder.SketchDocument();
            var logger   = new MessageListLogger();
            var builder  = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);
            var files = Directory.EnumerateFiles(_outputDirectory);

            Assert.IsEmpty(files);
            Assert.AreEqual(1, logger.Messages.Count);
            Assert.That(logger.Messages.First(), Does.Match("INFO.*No UX generated"));
        }
        public void UnimplementedLayerTypeFailsGracefullyWithWarning()
        {
            var log     = new MessageListLogger();
            var builder = new UxBuilder(new SymbolClassNameBuilder(), Substitute.For <IAssetEmitter>(), log);
            var uxNode  = builder.BuildLayer(new UnimplementedLayerType());

            Assert.That(log.ErrorsAndWarnings().Count, Is.EqualTo(1));
            var expected = "Unimplemented layer type: UnimplementedLayerType";

            Assert.That(log.ErrorsAndWarnings()[0], Does.Match(expected));
            var ux = uxNode.SerializeUx(new UxSerializerContext());

            Assert.That(ux, Does.Match("<!-- " + expected + " -->"));
        }
Exemple #10
0
        public void ParseLayerWithVerticalFlip()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.ShapeWithVerticalFlip);
            var log = new MessageListLogger();

            var sketchDocument = new SketchParser(log).Parse(mockSketchArchive);

            var shapePath = sketchDocument.Pages[0].Layers[0] as SketchShapePath;

            Assert.NotNull(shapePath);
            Assert.That(shapePath.Path.IsClosed, Is.False);
            Assert.That(shapePath.IsFlippedVertical, Is.True);
            Assert.That(shapePath.IsFlippedHorizontal, Is.False);
            Assert.That(log.ErrorsAndWarnings().Count, Is.Zero);
        }
Exemple #11
0
        public void OneSymbolCreateOneUxClass()
        {
            var sketchSymbolMaster = DocumentBuilder.SketchSymbolMaster("MySymbol");
            var document           = DocumentBuilder.SketchDocument()
                                     .WithSymbol(sketchSymbolMaster);

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);

            var files = Directory.EnumerateFiles(_outputDirectory);

            Assert.AreEqual(1, files.Count());
            Assert.IsTrue(files.First().EndsWith("MySymbol.ux"));
        }
Exemple #12
0
        public void ConvertingNonZipArchiveSketchFileReportsError()
        {
            var invalidSketchArchive = Path.Combine(Path.GetTempPath(), "invalid.sketch");

            using (var sw = new StreamWriter(invalidSketchArchive))
            {
                sw.WriteLine("This is not a sketch archive");
            }

            var log       = new MessageListLogger();
            var converter = new Converter(new SketchParser(log), new SymbolsUxBuilder(log), log);

            converter.Convert(new [] { invalidSketchArchive }, Path.GetTempPath());
            Assert.That(log.ErrorsAndWarnings().First(), Does.Match(invalidSketchArchive.Replace(@"\", @"\\") + ".*Can't open sketch file. This file might be on an old format."));

            File.Delete(invalidSketchArchive);
        }
Exemple #13
0
        public void SymbolWithReservedNameGetsSkippedAndLogged()
        {
            var sketchSymbolMaster = DocumentBuilder.SketchSymbolMaster("class");
            var document           = DocumentBuilder.SketchDocument()
                                     .WithSymbol(sketchSymbolMaster);

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);

            var files = Directory.EnumerateFiles(_outputDirectory);

            Assert.That(files.Count(), Is.EqualTo(0));
            Assert.That(logger.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(logger.ErrorsAndWarnings()[0], Does.Contain("The symbol name 'class' is a reserved word."));
        }
Exemple #14
0
        public void SymbolWithInvalidCharacterInNameGetsSkippedAndLogged()
        {
            var sketchSymbolMaster = DocumentBuilder.SketchSymbolMaster("a b");
            var document           = DocumentBuilder.SketchDocument()
                                     .WithSymbol(sketchSymbolMaster);

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);

            var files = Directory.EnumerateFiles(_outputDirectory);

            Assert.That(files.Count(), Is.EqualTo(0));
            Assert.That(logger.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(logger.ErrorsAndWarnings()[0], Does.Contain("The symbol name 'a b' contains an invalid character"));
        }
Exemple #15
0
        public void SymbolWithNoLayersDoesNotGetWritten()
        {
            var document = DocumentBuilder.SketchDocument()
                           .WithSymbol(DocumentBuilder.SketchSymbolMasterWithNoLayers("Harry"));

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);

            var file = Directory.EnumerateFiles(_outputDirectory);

            Assert.AreEqual(0, file.Count());

            Assert.AreEqual(1, logger.ErrorsAndWarnings().Count);
            Assert.That(logger.ErrorsAndWarnings().First(),
                        Does.Match("Skipping symbol 'Sketch.Harry' which has no supported layers."));
        }
Exemple #16
0
        public void TwoSketchSymbolsProducesTwoUxClassesInTwoFiles()
        {
            var document = DocumentBuilder.SketchDocument()
                           .WithSymbol(DocumentBuilder.SketchSymbolMaster("MySymbol").WithLayer(DocumentBuilder.Rectangle("R")))
                           .WithSymbol(DocumentBuilder.SketchSymbolMaster("MySymbol2").WithLayer(DocumentBuilder.Rectangle("R2")));

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);


            var files = Directory.EnumerateFiles(_outputDirectory).ToList();

            Assert.AreEqual(2, files.Count());
            Assert.IsTrue(files.First().EndsWith("MySymbol.ux"));
            Assert.IsTrue(files.Last().EndsWith("MySymbol2.ux"));
            Assert.AreEqual(0, logger.ErrorsAndWarnings().Count);
        }
Exemple #17
0
        public void ParseColoredTextSymbolVersion93()
        {
            // copy paste of _archive property on archevedAttributedString in TextSymbol from json-dump of DefaultText.sketch
            // Sketch version 93
            var jsonobj = @"YnBsaXN0MDDUAQIDBAUGX2BYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoK8QHAcIDxAcHR4fKywtLi8wMTIzOT1FRkdISUxQWFtVJG51bGzTCQoLDA0OWE5TU3RyaW5nViRjbGFzc1xOU0F0dHJpYnV0ZXOAAoAbgANbVGhlIGNvbnRlbnTTERIKExcbV05TLmtleXNaTlMub2JqZWN0c6MUFRaABIAFgAajGBkagAeAEYAZgBBfECpNU0F0dHJpYnV0ZWRTdHJpbmdDb2xvckRpY3Rpb25hcnlBdHRyaWJ1dGVfEB9NU0F0dHJpYnV0ZWRTdHJpbmdGb250QXR0cmlidXRlXxAQTlNQYXJhZ3JhcGhTdHlsZdMREgogJRukISIjJIAIgAmACoALpCYnKCmADIANgA6AD4AQU3JlZFVhbHBoYVRibHVlVWdyZWVuIz/nrQ5gAAAAIz/wAAAAAAAAIz/sIMZAAAAAIz+vTqY/////0jQ1NjdaJGNsYXNzbmFtZVgkY2xhc3Nlc1xOU0RpY3Rpb25hcnmiNjhYTlNPYmplY3TSCjo7PF8QGk5TRm9udERlc2NyaXB0b3JBdHRyaWJ1dGVzgBiAEtMREgo+QUSiP0CAE4AUokJDgBWAFoAXXxATTlNGb250U2l6ZUF0dHJpYnV0ZV8QE05TRm9udE5hbWVBdHRyaWJ1dGUjQCgAAAAAAABdSGVsdmV0aWNhTmV1ZdI0NUpLXxATTlNNdXRhYmxlRGljdGlvbmFyeaNKNjjSNDVNTl8QEE5TRm9udERlc2NyaXB0b3KiTzhfEBBOU0ZvbnREZXNjcmlwdG9y1FFSUwpUVVZXWk5TVGFiU3RvcHNbTlNBbGlnbm1lbnRfEB9OU0FsbG93c1RpZ2h0ZW5pbmdGb3JUcnVuY2F0aW9ugAAQBBABgBrSNDVZWl8QEE5TUGFyYWdyYXBoU3R5bGWiWTjSNDVcXV8QEk5TQXR0cmlidXRlZFN0cmluZ6JeOF8QEk5TQXR0cmlidXRlZFN0cmluZ18QD05TS2V5ZWRBcmNoaXZlctFhYlRyb290gAEACAARABoAIwAtADIANwBWAFwAYwBsAHMAgACCAIQAhgCSAJkAoQCsALAAsgC0ALYAugC8AL4AwADCAO8BEQEkASsBMAEyATQBNgE4AT0BPwFBAUMBRQFHAUsBUQFWAVwBZQFuAXcBgAGFAZABmQGmAakBsgG3AdQB1gHYAd8B4gHkAeYB6QHrAe0B7wIFAhsCJAIyAjcCTQJRAlYCaQJsAn8CiAKTAp8CwQLDAsUCxwLJAs4C4QLkAukC/gMBAxYDKAMrAzAAAAAAAAACAQAAAAAAAABjAAAAAAAAAAAAAAAAAAADMg==";

            var logger       = new MessageListLogger();
            var stringParser = new AttributedStringParser(logger);
            var sketchString = stringParser.Parse(jsonobj);

            Assert.That(sketchString, Is.Not.Null);
            Assert.That(sketchString.Attributes.Count, Is.EqualTo(1));
            Assert.That(sketchString.Attributes.First().Color.Red, Is.EqualTo(0.73987501859664895));
            Assert.That(sketchString.Attributes.First().Color.Green, Is.EqualTo(0.061146922409534399));
            Assert.That(sketchString.Attributes.First().Color.Blue, Is.EqualTo(0.87900078296661399));
            Assert.That(sketchString.Attributes.First().Color.Alpha, Is.EqualTo(1));

            Assert.That(sketchString.Contents, Is.EqualTo("The content"));
        }
Exemple #18
0
        public void TwoSymbolsWithSameNameGivesErrorAndOnlyWritesOne()
        {
            var document = DocumentBuilder.SketchDocument()
                           .WithSymbol(DocumentBuilder.SketchSymbolMaster("NameOfTheGame").WithLayer(DocumentBuilder.Rectangle("R")))
                           .WithSymbol(DocumentBuilder.SketchSymbolMaster("NameOfTheGame").WithLayer(DocumentBuilder.Rectangle("R")));

            var logger  = new MessageListLogger();
            var builder = new SymbolsUxBuilder(logger);

            builder.Build(document, _outputDirectory);


            var files = Directory.EnumerateFiles(_outputDirectory).ToList();

            Assert.That(files.Count(), Is.EqualTo(1));
            Assert.That(files.First(), Does.EndWith("NameOfTheGame.ux"));
            Assert.That(logger.ErrorsAndWarnings().Count, Is.EqualTo(1));
            Assert.That(logger.ErrorsAndWarnings()[0], Does.Match("More than one symbol named 'NameOfTheGame' was found!"));
        }
Exemple #19
0
        public void ParseColoredTextSymbolVersion91()
        {
            // copy paste of _archive property on archevedAttributedString in TextSymbol from json-dump of TestProject.sketch
            // Sketch version 91
            var jsonobj = @"YnBsaXN0MDDUAQIDBAUGZ2hYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoK8QGQcIDxAcHR4fJysyNT9CRUlNVVZXWFldYWNVJG51bGzTCQoLDA0OWE5TU3RyaW5nViRjbGFzc1xOU0F0dHJpYnV0ZXOAAoAYgANSQWHTERIKExcbV05TLmtleXNaTlMub2JqZWN0c6MUFRaABIAFgAajGBkagAeAC4APgBdXTlNDb2xvcl8QEE5TUGFyYWdyYXBoU3R5bGVfEB9NU0F0dHJpYnV0ZWRTdHJpbmdGb250QXR0cmlidXRl1CAhIgojJCUmVU5TUkdCXE5TQ29sb3JTcGFjZV8QEk5TQ3VzdG9tQ29sb3JTcGFjZUYxIDEgMQAQAYAIgArSKAopKlROU0lEEAGACdIsLS4vWiRjbGFzc25hbWVYJGNsYXNzZXNcTlNDb2xvclNwYWNlojAxXE5TQ29sb3JTcGFjZVhOU09iamVjdNIsLTM0V05TQ29sb3KiMzHVNjcKODk6Ozw9PVpOU1RhYlN0b3BzW05TQWxpZ25tZW50XE5TVGV4dEJsb2Nrc1tOU1RleHRMaXN0c4AAEAKADoAMgAzSEgpAQaCADdIsLUNEV05TQXJyYXmiQzHSLC1GR18QF05TTXV0YWJsZVBhcmFncmFwaFN0eWxlo0ZIMV8QEE5TUGFyYWdyYXBoU3R5bGXSCkpLTF8QGk5TRm9udERlc2NyaXB0b3JBdHRyaWJ1dGVzgBaAENMREgpOUVSiT1CAEYASolJTgBOAFIAVXxATTlNGb250U2l6ZUF0dHJpYnV0ZV8QE05TRm9udE5hbWVBdHRyaWJ1dGUjQDAAAAAAAABdSGVsdmV0aWNhTmV1ZdIsLVpbXxATTlNNdXRhYmxlRGljdGlvbmFyeaNaXDFcTlNEaWN0aW9uYXJ50iwtXl9fEBBOU0ZvbnREZXNjcmlwdG9yomAxXxAQTlNGb250RGVzY3JpcHRvctIsLVxiolwx0iwtZGVfEBJOU0F0dHJpYnV0ZWRTdHJpbmeiZjFfEBJOU0F0dHJpYnV0ZWRTdHJpbmdfEA9OU0tleWVkQXJjaGl2ZXLRaWpUcm9vdIABAAgAEQAaACMALQAyADcAUwBZAGAAaQBwAH0AfwCBAIMAhgCNAJUAoACkAKYAqACqAK4AsACyALQAtgC+ANEA8wD8AQIBDwEkASsBLQEvATEBNgE7AT0BPwFEAU8BWAFlAWgBdQF+AYMBiwGOAZkBpAGwAb0ByQHLAc0BzwHRAdMB2AHZAdsB4AHoAesB8AIKAg4CIQImAkMCRQJHAk4CUQJTAlUCWAJaAlwCXgJ0AooCkwKhAqYCvALAAs0C0gLlAugC+wMAAwMDCAMdAyADNQNHA0oDTwAAAAAAAAIBAAAAAAAAAGsAAAAAAAAAAAAAAAAAAANR";

            var logger       = new MessageListLogger();
            var stringParser = new AttributedStringParser(logger);
            var sketchString = stringParser.Parse(jsonobj);

            Assert.That(sketchString, Is.Not.Null);
            Assert.That(sketchString.Attributes.Count, Is.EqualTo(1));
            Assert.That(sketchString.Attributes.First().Color.Red, Is.EqualTo(1));
            Assert.That(sketchString.Attributes.First().Color.Green, Is.EqualTo(1));
            Assert.That(sketchString.Attributes.First().Color.Blue, Is.EqualTo(1));
            Assert.That(sketchString.Attributes.First().Color.Alpha, Is.EqualTo(1));

            Assert.That(sketchString.Contents, Is.EqualTo("Aa"));
        }
        public void IsCultureInsensitive()
        {
            var archive             = Substitute.For <ISketchArchive>();
            var appVerion           = 3.14;
            var version             = CompatibilityChecker.SketchCompatibilityVersion;
            var compatibiltyVersion = version;

            var json = GenerateMetaJson(appVerion, compatibiltyVersion, version);

            using (var jsonStream = new MemoryStream(Encoding.ASCII.GetBytes(json)))
            {
                archive.OpenFile("meta.json")
                .Returns(jsonStream);

                var log = new MessageListLogger();

                Thread.CurrentThread.CurrentCulture = new CultureInfo("nb-NO");
                CompatibilityChecker.Check("dummy.sketch", archive, log);
            }
        }
Exemple #21
0
        //This is important since we for instance parse pages in parallel
        public void ReportsAggregateExceptions()
        {
            var manyExceptions = new AggregateException(new List <Exception> {
                new Exception("foo"), new Exception("bar")
            });
            var parser = Substitute.For <ISketchParser>();

            parser.Parse(Arg.Any <SketchArchive>()).Throws(manyExceptions);

            var builder   = Substitute.For <IUxBuilder>();
            var log       = new MessageListLogger();
            var converter = new Converter(parser, builder, log);

            //Arbitrary existing file, just so we can get to `parser.Parse()`
            var arrowSketch = Path.Combine(FilesDirectory, "Arrow.sketch");

            converter.Convert(new [] { arrowSketch }, TempDirectory);
            Assert.That(log.ErrorsAndWarnings().Count, Is.EqualTo(2));
            Assert.That(log.ErrorsAndWarnings(), Has.Some.Match("foo"));
            Assert.That(log.ErrorsAndWarnings(), Has.Some.Match("bar"));
        }
Exemple #22
0
        public void BuildUxForSketchShapeGroupWithoutMaskingGivesNoWarnings()
        {
            var rectangle = new SketchRectangle(
                CreateLayer(5, 5),
                new SketchPath(CurvePointUtils.RectanglePath(new CornerRadius(2)), true),
                SketchBooleanOperation.NoOperation);

            var parentGroup =
                new SketchGroup(
                    new SketchLayer(
                        new SketchLayer(
                            Guid.Empty,
                            new SketchLayer(
                                CreateLayer(20, 20),
                                new List <SketchLayer>()),
                            new SketchRect(0, 0, 10, 10, false),
                            "Dummy",
                            false,
                            DummyAlignment(),
                            0, false, false,
                            Optional.None(),
                            new List <SketchLayer>()),
                        new List <SketchLayer> {
                rectangle
            }));

            rectangle.Parent = parentGroup;

            var log       = new MessageListLogger();
            var uxBuilder = new UxBuilder(new SymbolClassNameBuilder(), Substitute.For <IAssetEmitter>(), log);

            var uxNode = uxBuilder.BuildLayer(parentGroup);

            Assert.That(uxNode, Is.Not.Null);

            var ux = uxNode.SerializeUx(new UxSerializerContext());

            Assert.That(ux, Is.EqualTo("<Panel Width=\"50%\" Height=\"50%\" Alignment=\"TopLeft\" Margin=\"0\">\n\t<!-- Dummy -->\n\t<Rectangle CornerRadius=\"2\" Width=\"50%\" Height=\"50%\" Alignment=\"TopLeft\" Margin=\"0\">\n\t\t<!-- Dummy -->\n\t</Rectangle>\n</Panel>"));
            Assert.That(log.ErrorsAndWarnings(), Is.Empty);
        }
Exemple #23
0
        public void BuildUxForSketchShapeGroupWithMaskingGivesUnsupportedWarnings()
        {
            var shapeGroup = new SketchShapeGroup(
                new SketchLayer(CreateLayer(5, 5), new List <SketchLayer>()),
                Mask);

            var parentGroup =
                new SketchGroup(
                    new SketchLayer(
                        new SketchLayer(
                            Guid.Empty,
                            new SketchLayer(
                                CreateLayer(20, 20),
                                new List <SketchLayer>()),
                            new SketchRect(0, 0, 10, 10, false),
                            "Dummy",
                            false,
                            DummyAlignment(),
                            0, false, false,
                            Optional.None(),
                            new List <SketchLayer>()),
                        new List <SketchLayer> {
                shapeGroup
            }));

            shapeGroup.Parent = parentGroup;

            var log       = new MessageListLogger();
            var uxBuilder = new UxBuilder(new SymbolClassNameBuilder(), Substitute.For <IAssetEmitter>(), log);

            var uxNode = uxBuilder.BuildLayer(parentGroup);

            Assert.That(uxNode, Is.Not.Null);

            var ux = uxNode.SerializeUx(new UxSerializerContext());

            Assert.That(ux, Is.EqualTo("<Panel Width=\"50%\" Height=\"50%\" Alignment=\"TopLeft\" Margin=\"0\">\n\t<!-- Dummy -->\n\t<!-- Masked shape group is not supported in UX -->\n</Panel>"));
            Assert.That(log.ErrorsAndWarnings().First(), Does.Match("WARNING:\tMasked shapes are not supported Dummy"));
        }
        public void SketchFileProducedWithOlderVersionThanSupportedGivesWarning()
        {
            var archive             = Substitute.For <ISketchArchive>();
            var appVerion           = 3.14;
            var version             = CompatibilityChecker.SketchCompatibilityVersion - 3;
            var compatibiltyVersion = version;

            var json = GenerateMetaJson(appVerion, compatibiltyVersion, version);

            using (var jsonStream = new MemoryStream(Encoding.ASCII.GetBytes(json))) {
                archive.OpenFile("meta.json")
                .Returns(jsonStream);

                var log = new MessageListLogger();

                CompatibilityChecker.Check("dummy.sketch", archive, log);

                Assert.AreEqual(1, log.ErrorsAndWarnings().Count);
                Assert.AreEqual(3, log.Messages.Count);
                Assert.That(log.ErrorsAndWarnings().First(),
                            Does.StartWith("WARNING:" + "\t" + "The sketch file was created with an older version"));
            }
        }
Exemple #25
0
        public void ParseEmptySketchDocument()
        {
            // Create Sketch document where page has an empty layer list
            // When saving an empty sketch file, the document-class doesn't have an do_objectID

            var mockSketchArchive = Substitute.For <ISketchArchive>();

            mockSketchArchive
            .OpenFile("document.json")
            .Returns(
                new MemoryStream(Encoding.ASCII.GetBytes(
                                     @"{
							'_class': 'document',
							'pages': []
						 }"
                                     )));

            var log = new MessageListLogger();

            var sketchDocument = new SketchParser(log).Parse(mockSketchArchive);

            Assert.NotNull(sketchDocument);
        }