{"id":21857533,"url":"https://github.com/hjerpbakk/notifypropertychanged.verifier","last_synced_at":"2025-04-14T18:31:22.514Z","repository":{"id":52706127,"uuid":"216520475","full_name":"hjerpbakk/NotifyPropertyChanged.Verifier","owner":"hjerpbakk","description":"A fluent extension of xUnit for testing implementations of INotifyPropertyChanged in ViewModels.","archived":false,"fork":false,"pushed_at":"2021-04-21T11:17:45.000Z","size":94,"stargazers_count":5,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T05:47:28.378Z","etag":null,"topics":["dotnet","inotifypropertychanged","testing","uwp","wpf","xamarin-forms","xunit"],"latest_commit_sha":null,"homepage":"https://hjerpbakk.com/blog/2019/10/25/inotifypropertychanged-verifier","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hjerpbakk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-21T08:48:27.000Z","updated_at":"2023-03-17T12:19:44.000Z","dependencies_parsed_at":"2022-08-21T19:40:17.699Z","dependency_job_id":null,"html_url":"https://github.com/hjerpbakk/NotifyPropertyChanged.Verifier","commit_stats":null,"previous_names":["hjerpbakk/notifypropertychanged.verifier","sankra/notifypropertychanged.verifier"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjerpbakk%2FNotifyPropertyChanged.Verifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjerpbakk%2FNotifyPropertyChanged.Verifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjerpbakk%2FNotifyPropertyChanged.Verifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjerpbakk%2FNotifyPropertyChanged.Verifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hjerpbakk","download_url":"https://codeload.github.com/hjerpbakk/NotifyPropertyChanged.Verifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248936620,"owners_count":21186064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","inotifypropertychanged","testing","uwp","wpf","xamarin-forms","xunit"],"created_at":"2024-11-28T02:29:31.194Z","updated_at":"2025-04-14T18:31:22.494Z","avatar_url":"https://github.com/hjerpbakk.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NotifyPropertyChanged.Verifier\n\nIntroducing [NotifyPropertyChanged.Verifier](https://www.nuget.org/packages/NotifyPropertyChanged.Verifier/), a fluent extension of xUnit for testing implementations of INotifyPropertyChanged in ViewModels.\n\n[![Build status](https://github.com/sankra/NotifyPropertyChanged.Verifier/workflows/CI/badge.svg)](https://github.com/Sankra/NotifyPropertyChanged.Verifier/actions) [![codecov](https://codecov.io/gh/Sankra/NotifyPropertyChanged.Verifier/branch/master/graph/badge.svg)](https://codecov.io/gh/Sankra/NotifyPropertyChanged.Verifier) [![codecov](https://img.shields.io/nuget/v/NotifyPropertyChanged.Verifier.svg)](https://www.nuget.org/packages/NotifyPropertyChanged.Verifier) [![codecov](https://img.shields.io/nuget/dt/NotifyPropertyChanged.Verifier.svg)](https://www.nuget.org/packages/NotifyPropertyChanged.Verifier)\n\n![mvvm](/doc/mvvm.svg)\n\n## tl;dr\n\n```csharp\nvm.ShouldNotifyOn(vm =\u003e vm.PropertyWithNotify)\n  .When(vm =\u003e vm.PropertyWithNotify = 42);\n\nvm.ShouldNotNotifyOn(vm =\u003e vm.PropertyWithoutNotify)\n  .When(vm =\u003e vm.PropertyWithoutNotify = -1);\n```\n\n## Usage\n\nConsider the following ViewModel:\n\n```csharp\npublic class ViewModel : INotifyPropertyChanged {\n  int backingField;\n  string backingField2;\n\n  public int PropertyWithoutNotify { get; set; }\n\n  public int PropertyWithNotify {\n      get =\u003e backingField;\n      set {\n        backingField = value;\n        OnPropertyChanged();\n      }\n  }\n\n  public string PropertyWithMultipleNotifies {\n      get =\u003e backingField2;\n      set {\n          PropertyWithNotify = int.Parse(value);\n          OnPropertyChanged();\n      }\n  }\n\n  public event PropertyChangedEventHandler PropertyChanged;\n\n  private void OnPropertyChanged([CallerMemberName] string propertyName = \"\") =\u003e\n      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));\n}\n```\n\nTo test it, create an xUnit-test project and add a NuGet reference to [NotifyPropertyChanged.Verifier](https://www.nuget.org/packages/NotifyPropertyChanged.Verifier/). It's a .Net Standard 2.0 library and can be used both in .Net Core and the full .NET Framework. The preceding ViewModel can test its implementation of INotifyPropertyChanged doing:\n\n```csharp\nusing NotifyPropertyChanged.Verifier;\nusing Xunit;\n\nnamespace Tests {\n    public class UnitTests {\n        readonly ViewModel vm;\n\n        public UnitTests() =\u003e vm = new ViewModel();\n\n        [Fact]\n        public void PropertyWithNotify_WillRaiseNotifyEvent() =\u003e\n            vm.ShouldNotifyOn(vm =\u003e vm.PropertyWithNotify)\n              .When(vm =\u003e vm.PropertyWithNotify = 42);\n\n        [Fact]\n        public void PropertyWithoutNotify_WillNotRaiseNotifyEvent() =\u003e\n            vm.ShouldNotNotifyOn(vm =\u003e vm.PropertyWithoutNotify)\n              .When(vm =\u003e vm.PropertyWithoutNotify = -1);\n\n        [Fact]\n        public void PropertyWithMultipleNotifies_WillRaiseMultipleNotifyEvents() =\u003e\n            vm.ShouldNotNotifyOn(vm =\u003e vm.PropertyWithNotify,\n                                 vm =\u003e vm.PropertyWithMultipleNotifies)\n              .When(vm =\u003e vm.PropertyWithMultipleNotifies = \"42\");\n    }\n}\n```\n\nThe library consists of two extension methods on INotifyPropertyChanged, `ShouldNotifyOn` and `ShouldNotNotifyOn` which takes 1 or more property expressions as input. These are the properties that should either receive or not receive a NotifyPropertyChanged-event when an `Action\u003cT\u003e` is called by the `When` method. This can anything, not only methods or properties on the ViewModel itself.\n\n\nInspired by this [blogpost](https://blog.ploeh.dk/2009/08/06/AFluentInterfaceForTestingINotifyPropertyChanged/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhjerpbakk%2Fnotifypropertychanged.verifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhjerpbakk%2Fnotifypropertychanged.verifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhjerpbakk%2Fnotifypropertychanged.verifier/lists"}