-
-
Save yuta-kaseda/a0458df78ec0c6b7e635486acd660583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//モック用のinterfaceが必要 | |
public interface IMockInterface | |
{ | |
int Hoge { get; } | |
void HogeMethod(); | |
void FugaMethod(int a); | |
} | |
public static class MockFactory | |
{ | |
public static IMockInterface CreateMock() | |
{ | |
//Mockクラスを作成する | |
var mock = Substitute.For<IMockInterface>(); | |
//Mockクラスのフィールドやメソッドの動作を定義していく | |
//Hogeの参照は1を返すようにする | |
mock.Hoge.Return(1); | |
//HogeMethodの動作を定義する | |
mock | |
.When(m => m.HogeMethod()) | |
.Do(() => { 動作内容 }); | |
//引数ありの場合は引数を定義する | |
mock | |
.When(m => m.FugaMethod(Arg.Any<int>())) | |
.Do((arg) => { 動作内容 }); | |
return mock; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment