diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core.UnitTests/FormattedStringTests.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests/FormattedStringTests.cs')
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/FormattedStringTests.cs | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/FormattedStringTests.cs b/Xamarin.Forms.Core.UnitTests/FormattedStringTests.cs new file mode 100644 index 00000000..7c247bda --- /dev/null +++ b/Xamarin.Forms.Core.UnitTests/FormattedStringTests.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.ObjectModel; +using NUnit.Framework; + +namespace Xamarin.Forms.Core.UnitTests +{ + [TestFixture] + public class FormattedStringTests : BaseTestFixture + { + [SetUp] + public override void Setup () + { + base.Setup (); + Device.PlatformServices = new MockPlatformServices (); + } + + [TearDown] + public override void TearDown () + { + base.Setup (); + Device.PlatformServices = null; + } + + [Test] + public void NullSpansNotAllowed() + { + var fs = new FormattedString(); + Assert.That (() => fs.Spans.Add (null), Throws.InstanceOf<ArgumentNullException>()); + + fs = new FormattedString(); + fs.Spans.Add (new Span()); + + Assert.That (() => { + fs.Spans[0] = null; + }, Throws.InstanceOf<ArgumentNullException>()); + } + + [Test] + public void SpanChangeTriggersSpansPropertyChange() + { + var span = new Span(); + var fs = new FormattedString(); + fs.Spans.Add (span); + + bool spansChanged = false; + fs.PropertyChanged += (s, e) => { + if (e.PropertyName == "Spans") + spansChanged = true; + }; + + span.Text = "New text"; + + Assert.That (spansChanged, Is.True); + } + + [Test] + public void SpanChangesUnsubscribes() + { + var span = new Span(); + var fs = new FormattedString(); + fs.Spans.Add (span); + fs.Spans.Remove (span); + + bool spansChanged = false; + fs.PropertyChanged += (s, e) => { + if (e.PropertyName == "Spans") + spansChanged = true; + }; + + span.Text = "New text"; + + Assert.That (spansChanged, Is.False); + } + + [Test] + public void AddingSpanTriggersSpansPropertyChange() + { + var span = new Span(); + var fs = new FormattedString(); + + bool spansChanged = false; + fs.PropertyChanged += (s, e) => { + if (e.PropertyName == "Spans") + spansChanged = true; + }; + + fs.Spans.Add (span); + + Assert.That (spansChanged, Is.True); + } + + [Test] + public void ImplicitStringConversion() + { + string original = "fubar"; + FormattedString fs = original; + Assert.That (fs, Is.Not.Null); + Assert.That (fs.Spans.Count, Is.EqualTo (1)); + Assert.That (fs.Spans[0], Is.Not.Null); + Assert.That (fs.Spans[0].Text, Is.EqualTo (original)); + } + + [Test] + public void ImplicitStringConversionNull() + { + string original = null; + FormattedString fs = original; + Assert.That (fs, Is.Not.Null); + Assert.That (fs.Spans.Count, Is.EqualTo (1)); + Assert.That (fs.Spans[0], Is.Not.Null); + Assert.That (fs.Spans[0].Text, Is.EqualTo (original)); + } + } +}
\ No newline at end of file |