public StrokeAttributesTests()
 {
     _attributes = new StrokeAttributes
     {
         Color          = ARGBColor.Default,
         Height         = 2,
         Width          = 2,
         IgnorePressure = true,
         IsHighlighter  = false,
         StylusTip      = StylusTip.Ellipse
     };
 }
 public SerializableStroke(StrokeAttributes attributes, Point[] points)
 {
     if (points is null)
     {
         throw new ArgumentNullException(nameof(points), "SerializableStroke cannot contain null points collection");
     }
     if (points.Length < 1)
     {
         throw new ArgumentException("SerializableStroke cannot contain empty points collection", nameof(points));
     }
     Attributes = attributes;
     Points     = new ReadOnlyCollection <Point>(points);
 }
Example #3
0
 public SnapshotInstructionTests()
 {
     _attributes = new StrokeAttributes
     {
         Color          = ARGBColor.Default,
         Height         = 2,
         Width          = 2,
         IgnorePressure = true,
         IsHighlighter  = false,
         StylusTip      = StylusTip.Ellipse
     };
     _points = Enumerable.Range(10, 100).Select(i => new Point(i, i)).ToArray();
 }
    public void GetHashCodeForNonEqualAttributes()
    {
        var anotherAttributes = new StrokeAttributes
        {
            Color          = _attributes.Color,
            Height         = _attributes.Height + 5,
            Width          = _attributes.Width + 1,
            IgnorePressure = _attributes.IgnorePressure,
            IsHighlighter  = !_attributes.IsHighlighter,
            StylusTip      = _attributes.StylusTip
        };

        var hash        = _attributes.GetHashCode();
        var anotherHash = anotherAttributes.GetHashCode();

        Assert.NotEqual(hash, anotherHash);
    }
    public static SerializableStroke FromStroke(Stroke stroke)
    {
        if (stroke == null)
        {
            throw new ArgumentNullException(nameof(stroke));
        }
        var attr = new StrokeAttributes
        {
            Color          = ARGBColor.FromColor(stroke.DrawingAttributes.Color),
            Height         = stroke.DrawingAttributes.Height,
            Width          = stroke.DrawingAttributes.Width,
            IgnorePressure = stroke.DrawingAttributes.IgnorePressure,
            IsHighlighter  = stroke.DrawingAttributes.IsHighlighter,
            StylusTip      = stroke.DrawingAttributes.StylusTip
        };

        var points = stroke.StylusPoints.Select(point => point.ToPoint()).ToArray();

        return(new SerializableStroke(attr, points));
    }
    public void GetHashCodeForNonEqualStrokesByAttributes()
    {
        var stroke        = new SerializableStroke(_attributes, _points);
        var anotherPoints = new Point[_points.Length];

        _points.CopyTo(anotherPoints, 0);
        var anotherAttributes = new StrokeAttributes
        {
            Color          = ARGBColor.Default,
            Height         = stroke.Attributes.Height + 2,
            Width          = 2,
            IgnorePressure = true,
            IsHighlighter  = !stroke.Attributes.IsHighlighter,
            StylusTip      = StylusTip.Ellipse
        };
        var anotherStroke = new SerializableStroke(anotherAttributes, anotherPoints);

        var strokeHash        = stroke.GetHashCode();
        var anotherStrokeHash = anotherStroke.GetHashCode();

        Assert.NotEqual(strokeHash, anotherStrokeHash);
    }
 public EraseInstructionTests()
 {
     _attributes = new StrokeAttributes
     {
         Color          = ARGBColor.Default,
         Height         = 2,
         Width          = 2,
         IgnorePressure = true,
         IsHighlighter  = false,
         StylusTip      = StylusTip.Ellipse
     };
     _points = Enumerable.Range(10, 100).Select(i => new Point(i, i)).ToArray();
     _nonSerializableStroke = new Stroke(new StylusPointCollection(_points),
                                         new DrawingAttributes
     {
         Color          = _attributes.Color.AsColor(),
         Height         = _attributes.Height,
         Width          = _attributes.Width,
         IgnorePressure = _attributes.IgnorePressure,
         IsHighlighter  = _attributes.IsHighlighter,
         StylusTip      = _attributes.StylusTip
     });
 }
    public void EqualityOperatorForNonEqualsStrokesByAttributes()
    {
        var stroke        = new SerializableStroke(_attributes, _points);
        var anotherPoints = new Point[_points.Length];

        _points.CopyTo(anotherPoints, 0);
        var anotherAttributes = new StrokeAttributes
        {
            Color          = ARGBColor.Default,
            Height         = stroke.Attributes.Height + 2,
            Width          = 2,
            IgnorePressure = true,
            IsHighlighter  = !stroke.Attributes.IsHighlighter,
            StylusTip      = StylusTip.Ellipse
        };
        var anotherStroke = new SerializableStroke(anotherAttributes, anotherPoints);

        var equalityResult    = stroke == anotherStroke;
        var nonEqualityResult = stroke != anotherStroke;

        Assert.False(equalityResult);
        Assert.True(nonEqualityResult);
    }