using Amphora; using Prism; using UnitTestSharp; namespace Glass.UnitTests.Materials { public class FlashingTextMaterialTests : TestFixture { public static readonly Color Red = Color.FromArgb(255, 200, 100, 0); public static FlashingTextMaterial FlashOf(Duration startAge, Duration length) { return new FlashingTextMaterial(BakedTextMaterialTests.Style(), "ab", Red, startAge, length); } public class CtorTests : TestFixture { public void KeepsTheTextAndTheStyle() { FlashingTextMaterial material = FlashOf(Duration.Zero, Duration.FromSeconds(1)); CheckEqual("ab", material.Text.ToString()); CheckEqual(BakedTextMaterialTests.Style(), material.Style); } public void KeepsTheFlashColorStartAndLength() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(3)); CheckEqual(Red, material.FlashColor); CheckEqual(Duration.FromSeconds(2), material.StartAge); CheckEqual(Duration.FromSeconds(3), material.Length); } public void WithCopy_KeepsTheFlash() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(3)); FlashingTextMaterial copy = material with { Scale = 2 }; CheckEqual(Red, copy.FlashColor); CheckEqual(Duration.FromSeconds(2), copy.StartAge); CheckEqual(Duration.FromSeconds(3), copy.Length); } } public class IsFlashingAtTests : TestFixture { public void BeforeTheStart_IsFalse() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckFalse(material.IsFlashingAt(Duration.FromSeconds(1.9))); } public void AtTheStart_IsTrue() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckTrue(material.IsFlashingAt(Duration.FromSeconds(2))); } public void JustBeforeTheEnd_IsTrue() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckTrue(material.IsFlashingAt(Duration.FromSeconds(2.9))); } public void AtTheEnd_IsFalse() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckFalse(material.IsFlashingAt(Duration.FromSeconds(3))); } public void AZeroLength_IsNeverTrue() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.Zero); CheckFalse(material.IsFlashingAt(Duration.FromSeconds(2))); } } public class ColorAtTests : TestFixture { public void AtTheStart_IsTheFlashColor() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckEqual(Red, material.ColorAt(Duration.FromSeconds(2), Colors.Black)); } public void HalfwayThrough_IsHalfwayToTheNormalColor() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckEqual(Color.FromArgb(255, 100, 50, 0), material.ColorAt(Duration.FromSeconds(2.5), Colors.Black)); } public void FadesTheAlphaToo() { var material = new FlashingTextMaterial(BakedTextMaterialTests.Style(), "ab", Color.FromArgb(200, 10, 20, 30), Duration.Zero, Duration.FromSeconds(1)); CheckEqual(Color.FromArgb(100, 5, 10, 15), material.ColorAt(Duration.FromSeconds(0.5), Color.FromArgb(0, 0, 0, 0))); } public void WithNoNormalColor_FadesToWhite() { FlashingTextMaterial material = FlashOf(Duration.Zero, Duration.FromSeconds(4)); CheckEqual(Color.FromArgb(255, 214, 139, 64), material.ColorAt(Duration.FromSeconds(1), null)); } public void BeforeTheStart_IsNull() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckNull(material.ColorAt(Duration.FromSeconds(1), Colors.Black)); } public void AtTheEnd_IsNull() { FlashingTextMaterial material = FlashOf(Duration.FromSeconds(2), Duration.FromSeconds(1)); CheckNull(material.ColorAt(Duration.FromSeconds(3), Colors.Black)); } } } }