public async void InitializeAsync_OrderReadFromOptions_OrdersFavouritesByLastUpdate(bool isOrderedByRank) { // Arrange var links = new List <LinkItem> { new LinkItem { ID = 0, Name = "A", Link = "http://test.com", LastUpdatedOn = DateTime.Now.AddDays(-5), Rank = 3 }, new LinkItem { ID = 1, Name = "B", Link = "http://test.com", LastUpdatedOn = DateTime.Now.AddDays(-4), Rank = 2 }, new LinkItem { ID = 2, Name = "C", Link = "http://test.com", LastUpdatedOn = DateTime.Now.AddDays(-3), Rank = 1 }, new LinkItem { ID = 3, Name = "D", Link = "http://test.com", LastUpdatedOn = DateTime.Now.AddDays(-2), Rank = 4 }, new LinkItem { ID = 4, Name = "E", Link = "http://test.com", LastUpdatedOn = DateTime.Now.AddDays(-1), Rank = 6 }, new LinkItem { ID = 5, Name = "F", Link = "http://test.com", LastUpdatedOn = DateTime.Now, Rank = 5 }, }; var database = new Mock <ILinkItemRepository>(); database.Setup(d => d.GetItemsAsync()).ReturnsAsync(links); var option = new Options { IsOrderedByRank = isOrderedByRank }; var optionsRepository = new Mock <IOptionsRepository>(); optionsRepository.Setup(o => o.GetOptionsAsync()) .ReturnsAsync(option); var resourcesProvider = new Mock <IResourcesProvider>(); resourcesProvider.Setup(rp => rp.Resources) .Returns(new ResourceDictionary()); var model = new StartPageViewModel(null, null, database.Object, optionsRepository.Object, resourcesProvider.Object); var harness = new NotifyPropertyChangedHarness(model); var expectedLinks = isOrderedByRank ? links.OrderByDescending(l => l.Rank) : links.OrderByDescending(l => l.LastUpdatedOn); // Act await model.InitializeAsync(null); // Assert Assert.NotEmpty(harness.Changes); Assert.Contains(nameof(model.FavoriteLinks), harness.Changes); Assert.Equal(expectedLinks, model.FavoriteLinks); }
public void SettingLink_NewValue_NotifiesPropertyChanged() { var model = new LinkItemViewModel(null, null, null, null, null); var harness = new NotifyPropertyChangedHarness(model); model.Link = "http://link.com"; Assert.NotNull(harness.Changes); Assert.Single(harness.Changes); Assert.Equal(nameof(model.Link), harness.Changes[0]); }
public void SettingName_NewValue_NotifiesPropertyChanged() { var model = new LinkItemViewModel(null, null, null, null, null); var harness = new NotifyPropertyChangedHarness(model); model.Name = "some name"; Assert.NotNull(harness.Changes); Assert.Single(harness.Changes); Assert.Equal(nameof(model.Name), harness.Changes[0]); }
public void SettingLink_SameValue_DoesNotNotifyPropertyChanged() { var model = new LinkItemViewModel(null, null, null, null, null); var link = "http://link.com"; model.Link = link; var harness = new NotifyPropertyChangedHarness(model); model.Link = link; Assert.Empty(harness.Changes); }
public void SettingName_SameValue_DoesNotNotifyPropertyChanged() { var model = new LinkItemViewModel(null, null, null, null, null); var name = "My name"; model.Name = name; var harness = new NotifyPropertyChangedHarness(model); model.Name = name; Assert.Empty(harness.Changes); }
public void SettingInfo_SameValue_DoesNotNotifyPropertyChanged() { var model = new LinkItemViewModel(null, null, null, null, null); var info = "some info"; model.Info = info; var harness = new NotifyPropertyChangedHarness(model); model.Info = info; Assert.Empty(harness.Changes); }
public void SetFavoriteLinksItemsCommand_ChangesFavoriteLinksProperty(string searchTerm) { var database = new Mock <ILinkItemRepository>(); database.Setup(d => d.GetItemsAsync()).ReturnsAsync(new List <LinkItem>()); var model = new StartPageViewModel(null, null, database.Object, null, null); var harness = new NotifyPropertyChangedHarness(model); model.SetFavoriteLinksItemsCommand.Execute(searchTerm); Assert.NotEmpty(harness.Changes); Assert.Single(harness.Changes); Assert.Equal(nameof(model.FavoriteLinks), harness.Changes[0]); }