初めてChaining Assertionを学びましたので、備忘録として残します。
Chaining Assertionとは何か
C#の単体テストのためのライブラリです。
テストコードを書きやすくする[Chaining Assertion]とサーバーに接続しなくてもテストできる[Moq]があります。
インストール
インストールは[NuGetパッケージの管理]から行います。
メニューのプロジェクトから開きます。
それぞれインストールします。
ViewModelBase.csの追加
クラスを追加して、以下のように記述します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.ComponentModel;
namespace DDD.WinForm.ViewModels
{
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(
ref T field, T value, [CallerMemberName]string propertyName = null)
{
if(Equals(field, value))
{
return false;
}
field = value;
var h = this.PropertyChanged;
if (h != null)
{
h(this, new PropertyChangedEventArgs(propertyName));
}
return true;
}
}
}
このコードを配置することによりテストするファイル(View)とテストコード(ViewModel)がデータバインドしてテスト出来るようになります。