This repository has been archived by the owner on May 1, 2024. It is now read-only.
/
StyleTests.cs
82 lines (68 loc) · 2.26 KB
/
StyleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.StyleSheets.UnitTests
{
[TestFixture]
public class StyleTests
{
[SetUp]
public void SetUp()
{
Device.PlatformServices = new MockPlatformServices();
Internals.Registrar.RegisterAll(new Type[0]);
}
[Test]
public void PropertiesAreApplied()
{
var styleString = @"background-color: #ff0000;";
var style = Style.Parse(new CssReader(new StringReader(styleString)), '}');
Assume.That(style, Is.Not.Null);
var ve = new VisualElement();
Assume.That(ve.BackgroundColor, Is.EqualTo(Color.Default));
style.Apply(ve);
Assert.That(ve.BackgroundColor, Is.EqualTo(Color.Red));
}
[Test]
public void PropertiesSetByStyleDoesNotOverrideManualOne()
{
var styleString = @"background-color: #ff0000;";
var style = Style.Parse(new CssReader(new StringReader(styleString)), '}');
Assume.That(style, Is.Not.Null);
var ve = new VisualElement() { BackgroundColor = Color.Pink };
Assume.That(ve.BackgroundColor, Is.EqualTo(Color.Pink));
style.Apply(ve);
Assert.That(ve.BackgroundColor, Is.EqualTo(Color.Pink));
}
[Test]
public void StylesAreCascading()
{
var styleString = @"background-color: #ff0000; color: #00ff00;";
var style = Style.Parse(new CssReader(new StringReader(styleString)), '}');
Assume.That(style, Is.Not.Null);
var label = new Label();
var layout = new StackLayout {
Children = {
label,
}
};
Assume.That(layout.BackgroundColor, Is.EqualTo(Color.Default));
Assume.That(label.BackgroundColor, Is.EqualTo(Color.Default));
Assume.That(label.TextColor, Is.EqualTo(Color.Default));
style.Apply(layout);
Assert.That(layout.BackgroundColor, Is.EqualTo(Color.Red));
Assert.That(label.BackgroundColor, Is.EqualTo(Color.Red));
Assert.That(label.TextColor, Is.EqualTo(Color.Lime));
}
[Test]
public void PropertiesAreOnlySetOnMatchingElements()
{
var styleString = @"background-color: #ff0000; color: #00ff00;";
var style = Style.Parse(new CssReader(new StringReader(styleString)), '}');
Assume.That(style, Is.Not.Null);
var layout = new StackLayout();
Assert.That(layout.GetValue(TextElement.TextColorProperty), Is.EqualTo(Color.Default));
}
}
}