Пример #1
0
        public void ParseSketchRectangleTest()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.RectangleJson);
            var log = Substitute.For <ILogger>();

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

            Assert.AreEqual(1, sketchDocument.Pages.Count);
            Assert.NotNull(sketchDocument.Pages[0].Layers);
            Assert.IsInstanceOf(typeof(SketchRectangle), sketchDocument.Pages[0].Layers[0]);
        }
Пример #2
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'"));
        }
Пример #3
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"));
        }
Пример #4
0
        public void ParseShapeGroupWithClippingMaskOn()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.MaskedShapeGroup);
            var log = Substitute.For <ILogger>();

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

            Assert.That(sketchDocument.Pages.Count, Is.EqualTo(1));
            var shapeGroup = sketchDocument.Pages.First().Layers.First() as SketchShapeGroup;

            Assert.That(shapeGroup, Is.Not.Null);
            Assert.That(shapeGroup.HasClippingMask, Is.True);
        }
Пример #5
0
        public void ParseStarShape()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.Star);
            var log = Substitute.For <ILogger>();

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

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

            Assert.NotNull(shapePath);
            Assert.AreEqual(10, shapePath.Path.Points.Count);
            Assert.AreEqual(10, shapePath.Path.Points.Count(p => p.Mode == SketchCurvePoint.CurveMode.Line));
            Assert.That(shapePath.Path.IsClosed, Is.True);
        }
Пример #6
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);
        }
Пример #7
0
        public void ParseShapePathWithLinesAndCurves()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.VectorPath);
            var log = Substitute.For <ILogger>();

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

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

            Assert.NotNull(shapePath);
            Assert.IsFalse(shapePath.Path.IsClosed);
            Assert.AreEqual(11, shapePath.Path.Points.Count);

            Assert.AreEqual(6, shapePath.Path.Points.Count(p => p.Mode == SketchCurvePoint.CurveMode.Line));
            Assert.AreEqual(5, shapePath.Path.Points.Count(p => p.Mode == SketchCurvePoint.CurveMode.Curve));
        }
Пример #8
0
        public void ParseNestedSketchSymbolTest()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.SymbolMasterWithInstance);
            var log = Substitute.For <ILogger>();

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

            Assert.NotNull(sketchDocument);
            Assert.AreEqual(1, sketchDocument.Pages.Count);
            Assert.NotNull(sketchDocument.Pages[0].Layers);
            Assert.IsInstanceOf <SketchSymbolMaster>(sketchDocument.Pages[0].Layers[0]);

            var symbolMaster = sketchDocument.Pages[0].Layers[0] as SketchSymbolMaster;

            Assert.AreEqual("Rectangle", symbolMaster.Name);
            Assert.AreEqual(1, symbolMaster.Layers.Count(l => l.GetType() == typeof(SketchSymbolInstance)));
        }
Пример #9
0
        public void ParseShapePathWithStraightLine()
        {
            var mockSketchArchive = MockSketchArchive.Create(Snippets.ShapePathJson);
            var log = Substitute.For <ILogger>();

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

            Assert.NotNull(sketchDocument);
            Assert.AreEqual(1, sketchDocument.Pages.Count);
            Assert.NotNull(sketchDocument.Pages[0].Layers);
            Assert.IsInstanceOf <SketchShapePath>(sketchDocument.Pages[0].Layers[0]);

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

            Assert.IsFalse(shapePath.Path.IsClosed);
            Assert.AreEqual(2, shapePath.Path.Points.Count);
        }