|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Linq; |
| 6 | +using Microsoft.Toolkit.Uwp.Notifications; |
| 7 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 8 | + |
| 9 | +namespace UnitTests.Notifications |
| 10 | +{ |
| 11 | +#if !WINRT |
| 12 | + [TestClass] |
| 13 | + public class TestTileContentBuilder |
| 14 | + { |
| 15 | + [TestMethod] |
| 16 | + public void AddTextTest_OnSmallTileOnly() |
| 17 | + { |
| 18 | + // Arrange |
| 19 | + string text = "text on small tile"; |
| 20 | + TileContentBuilder builder = new TileContentBuilder(); |
| 21 | + builder.AddTile(TileSize.Small); |
| 22 | + |
| 23 | + // Act |
| 24 | + builder.AddText(text); |
| 25 | + |
| 26 | + // Assert |
| 27 | + var tileText = GetTileAdaptiveText(builder, TileSize.Small); |
| 28 | + Assert.IsNotNull(tileText); |
| 29 | + Assert.AreSame("text on small tile", (string)tileText.Text); |
| 30 | + } |
| 31 | + |
| 32 | + [TestMethod] |
| 33 | + public void AddTextTest_OnMediumTileOnly() |
| 34 | + { |
| 35 | + // Arrange |
| 36 | + string text = "text on medium tile"; |
| 37 | + TileContentBuilder builder = new TileContentBuilder(); |
| 38 | + builder.AddTile(TileSize.Medium); |
| 39 | + |
| 40 | + // Act |
| 41 | + builder.AddText(text); |
| 42 | + |
| 43 | + // Assert |
| 44 | + var tileText = GetTileAdaptiveText(builder, TileSize.Medium); |
| 45 | + Assert.IsNotNull(tileText); |
| 46 | + Assert.AreSame("text on medium tile", (string)tileText.Text); |
| 47 | + } |
| 48 | + |
| 49 | + [TestMethod] |
| 50 | + public void AddTextTest_OnWideTileOnly() |
| 51 | + { |
| 52 | + // Arrange |
| 53 | + string text = "text on wide tile"; |
| 54 | + TileContentBuilder builder = new TileContentBuilder(); |
| 55 | + builder.AddTile(TileSize.Wide); |
| 56 | + |
| 57 | + // Act |
| 58 | + builder.AddText(text); |
| 59 | + |
| 60 | + // Assert |
| 61 | + var tileText = GetTileAdaptiveText(builder, TileSize.Wide); |
| 62 | + Assert.IsNotNull(tileText); |
| 63 | + Assert.AreSame("text on wide tile", (string)tileText.Text); |
| 64 | + } |
| 65 | + |
| 66 | + [TestMethod] |
| 67 | + public void AddTextTest_OnLargeTileOnly() |
| 68 | + { |
| 69 | + // Arrange |
| 70 | + string text = "text on large tile"; |
| 71 | + TileContentBuilder builder = new TileContentBuilder(); |
| 72 | + builder.AddTile(TileSize.Large); |
| 73 | + |
| 74 | + // Act |
| 75 | + builder.AddText(text); |
| 76 | + |
| 77 | + // Assert |
| 78 | + var tileText = GetTileAdaptiveText(builder, TileSize.Large); |
| 79 | + Assert.IsNotNull(tileText); |
| 80 | + Assert.AreSame("text on large tile", (string)tileText.Text); |
| 81 | + } |
| 82 | + |
| 83 | + private static AdaptiveText GetTileAdaptiveText(TileContentBuilder builder, TileSize size) |
| 84 | + { |
| 85 | + TileBinding tileBinding; |
| 86 | + switch (size) |
| 87 | + { |
| 88 | + case TileSize.Small: |
| 89 | + tileBinding = builder.Content.Visual.TileSmall; |
| 90 | + break; |
| 91 | + |
| 92 | + case TileSize.Medium: |
| 93 | + tileBinding = builder.Content.Visual.TileMedium; |
| 94 | + break; |
| 95 | + |
| 96 | + case TileSize.Wide: |
| 97 | + tileBinding = builder.Content.Visual.TileWide; |
| 98 | + break; |
| 99 | + |
| 100 | + case TileSize.Large: |
| 101 | + tileBinding = builder.Content.Visual.TileLarge; |
| 102 | + break; |
| 103 | + |
| 104 | + default: |
| 105 | + return null; |
| 106 | + } |
| 107 | + |
| 108 | + var content = (TileBindingContentAdaptive)tileBinding.Content; |
| 109 | + return content.Children.FirstOrDefault() as AdaptiveText; |
| 110 | + } |
| 111 | + } |
| 112 | +#endif |
| 113 | +} |
0 commit comments