using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; using ShareeBike.Model; using ShareeBike.ViewModel.WhatsNew; using Xamarin.Essentials; namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests { [TestFixture] public class TestWhatsNew { [Test] public void TestIsMessagesConsistent() { foreach (AppFlavor app in Enum.GetValues(typeof(AppFlavor))) { foreach (DevicePlatform platform in new List { DevicePlatform.iOS, DevicePlatform.Android }) Assert.That( () => new WhatsNew( WhatsNew.AllFlavorsAndPlatformMessages[WhatsNew.AllFlavorsAndPlatformMessages.Count - 1].Version, WhatsNew.AllFlavorsAndPlatformMessages[0].Version, WhatsNew.AllFlavorsAndPlatformMessages[0].Version, app, platform).WhatsNewText, Throws.Nothing, "Invalid entries detected."); } } [Test] public void TestIsShowRequired_CleanInstall() { Assert.That(new WhatsNew( new Version(2, 4), /* Current version */ null, // last version null, /* Whats new was never shown */ AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.False); } /// /// This test verified old implementation which worked with the different versions to determine whenther whats new has to be shown or not. /// Test updated to new implementation (based on filtering of AllFlavorsAndPlatformMessages) /// [Test] public void TestIsShowRequired_Update_VersionWhichSupporsWhatsNew() { Assert.That( new WhatsNew( new Version(3, 0, 335), /* Current version */ new Version(3, 0, 333), /* last version */ new Version(3, 0, 111), /* Version when whats new was shown */ AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.True, "If whats new was last shown for version 3.0.111 and current version is 2.0.335 info must be shown"); } /// /// This test verified old implementation which worked with the different versions to determine whenther whats new has to be shown or not. /// Test updated to new implementation (based on filtering of AllFlavorsAndPlatformMessages) /// [Test] public void TestIsShowRequired_Update_VersionWithoutWhatsNew() { Assert.That( new WhatsNew( new Version(3, 0, 335), /* Current version */ new Version(3, 0, 333), /* last version */ null, /* Whats new was never shown */ AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.True, "If whats new was never shown but last version was 3.0.333 (not clean install) info must be shown"); } [Test] public void TestIsShowRequired_False() { Assert.That( new WhatsNew(new Version(2, 5), new Version(2, 5), new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.False, "Whats new must never be presented twice."); } [Test] public void TestIsShowRequired_False_Errors() { Assert.That(new WhatsNew(null, new Version(2, 6), new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.False); Assert.That(new WhatsNew(new Version(2, 6), null, new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.False); Assert.That(new WhatsNew(null, null, new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired, Is.False); } [Test] public void TestWhatsNewText_MajorUpdate() { Assert.That( WhatsNewViewModel.GetWhatNextHtmlText(new WhatsNew(new Version(3, 0, 120), new Version(3, 0, 0, 114), new Version(3, 0, 0, 114), AppFlavor.ShareeBike, DevicePlatform.Android).WhatsNewText), Is.EqualTo("

3.0.0.115
Benutzeroberfläche verbessert.\r\n\r\n" + "

3.0.120
Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n

"), "Current version is 30.0.120, last whats new was shown in version 3.0.0.114: Two changes to be notified about."); } [Test] public void TestWhatsNewText_MinorUpdate() { Assert.That( WhatsNewViewModel.GetWhatNextHtmlText(new WhatsNew(new Version(3, 0, 120), new Version(3, 0, 0, 115), new Version(3, 0, 0, 115), AppFlavor.ShareeBike, DevicePlatform.Android).WhatsNewText), Is.EqualTo("

3.0.120
Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n

")); } [Test] public void TestWhatsNewGetFileredMessages_GeneralMessage() { Assert.That( new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.iOS, new WhatsNewMessages { { new Version(3, 0, 0, 115), "Benutzeroberfläche verbessert.\r\n\r\n" } }).WhatsNewText.Count(), Is.EqualTo(1)); } [Test] public void TestWhatsNewGetFileredMessages_LastenradBayernOnly_Included() { Assert.That( new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.LastenradBayern, DevicePlatform.iOS, new WhatsNewMessages { { new Version(3, 0, 0, 115), "Benutzeroberfläche verbessert.\r\n\r\n", new List {AppFlavor.LastenradBayern} } }).WhatsNewText.Count(), Is.EqualTo(1)); } [Test] public void TestWhatsNewGetFileredMessages_LastenradBayernOnly_Excluded() { Assert.That( new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.iOS, new WhatsNewMessages { { new Version(3, 0, 0, 115), "Benutzeroberfläche verbessert.\r\n\r\n", new List {AppFlavor.LastenradBayern} } }).WhatsNewText.Count(), Is.EqualTo(0)); } [Test] public void TestWhatsNewGetFileredMessages_iOSOnly_Included() { Assert.That( new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.iOS, new WhatsNewMessages { { new Version(3, 0, 0, 115), "Benutzeroberfläche verbessert.\r\n\r\n", null, new List {DevicePlatform.iOS} } }).WhatsNewText.Count(), Is.EqualTo(1)); } [Test] public void TestWhatsNewGetFileredMessages_iOSOnly_Exclued() { Assert.That( new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.Android, new WhatsNewMessages { { new Version(3, 0, 0, 115), "Benutzeroberfläche verbessert.\r\n\r\n", null, new List {DevicePlatform.iOS} } }).WhatsNewText.Count(), Is.EqualTo(0)); } } }