using System; using System.Collections.Generic; using NUnit.Framework; namespace TINK.ViewModel.Settings { [TestFixture] public class TestServicesViewModel { [Test] public void TestCtor() { var servicesViewModel = new ServicesViewModel( new List { "ServiceA", "ServiceB", "ServiceB", // Dupes are removed "ServiceC" }, new Dictionary { { "ServiceA", "Top service of type A" }, { "ServiceB", "Supertop service of type B" }, { "OldsService", "This entry is discarded" }}, "ServiceB"); Assert.That( servicesViewModel.ServicesTextList, Is.EqualTo(new List { "ServiceC", "Supertop service of type B", "Top service of type A" }).AsCollection); Assert.That( servicesViewModel.Active, Is.EqualTo("ServiceB")); } [Test] public void TestCtorInvalidActive() { Assert.That( () => new ServicesViewModel( new List { "ServiceA", "ServiceB", "ServiceB", "ServiceC" }, new Dictionary { { "ServiceA", "Top service of type A" }, { "ServiceB", "Supertop service of type B" } }, "ServiceX"), Throws.TypeOf()); } [Test] public void TestCtorInvalidServiceNames() { Assert.That( () => new ServicesViewModel( new List { "ServiceA", "ServiceB", "ServiceC" }, new Dictionary { { "ServiceA", "Top fast" }, { "ServiceB", "Top fast" } }, "ServiceB"), Throws.TypeOf()); } [Test] public void TestGetActiveTextDisplayTextAvailable() { var servicesViewModel = new ServicesViewModel( new List { "ServiceB"}, new Dictionary { { "ServiceB", "Supertop service of type B" }}, "ServiceB"); Assert.That( servicesViewModel.ActiveText, Is.EqualTo("Supertop service of type B")); } [Test] public void TestGetActiveTextNoDisplayText() { var servicesViewModel = new ServicesViewModel( new List { "ServiceB"}, new Dictionary(), "ServiceB"); Assert.That( servicesViewModel.ActiveText, Is.EqualTo("ServiceB")); } [Test] public void TestSetActiveText() { var servicesViewModel = new ServicesViewModel( new List { "ServiceA", "ServiceB" }, new Dictionary(), "ServiceB") { ActiveText = "ServiceA" }; Assert.That( servicesViewModel.ActiveText, Is.EqualTo("ServiceA")); } [Test] public void TestSetActiveTextInvalid() { var servicesViewModel = new ServicesViewModel( new List { "ServiceA", "ServiceB" }, new Dictionary(), "ServiceB"); Assert.That( () => servicesViewModel.ActiveText = "ServiceX", Throws.InstanceOf()); } } }