???Moq?????????????
???????????? ???????[ 2013/11/18 16:49:27 ] ????????
????????????????unity???????????????????????Moq??
???????????????????????????????????????б?????????????????????????
????????Moq??
????Moq?????????Mock-you ???????mock??????????.Net????????????????????????????.NET3.5??LINQ??????????C#3.0?????????lambda???????????????????????????????????????е????????м??????????????????????????????????д?????????????????????????????????????????????????????????????
??????????Moq??
?????????????????????£?????????????? VS?е???Nuget?????Moq???????????????????
????????????????http://code.google.com/p/moq/??????Moq???°汾??
?????????????????????
????????????????????????
??????Σ?????????????????????Moq???????????????????????????£?????????????????????????????????????????????????????????????????????????
??????????????????????????п?????úü???service????????ζ????????Щservice??????????????????????????????????????service?????????????????????????????
????Moq???
????Moq???????????????????????????????????????????????????Moq??? Castle DynamicProxy ????????????????????????÷??????? Emit ??????????????????????????н???????????????????????κι???????????????????????Mock?????????????????DynamicProxy????????????????????????????????????????????
????Moq?е???????
????Mock
????????????????????????Mock<T>????T?????????????????????????public ??virtual???????????????±???????
//define interface to be mocked
public interface IFake
{
bool DoSomething(string actionname);
}
//define the test method
public void Test_Interface_IFake()
{
//make a mock Object by Moq
var mo = new Mock<IFake>();
//Setup our mock object
mo.Setup(foo => foo.DoSomething("Ping"))
.Returns(true);
//Assert it!
Assert.AreEqual(true?? mo.Object.DoSomething("Ping"));
}
|
public interface IEmailSender
{
bool Send(string subject?? string body?? string email);
}
public void User_Can_Send_Password()
{
var emailMock = new Mock<IEmailSender>();
emailMock
.Setup(sender => sender.Send(It.IsAny<string>()?? It.IsAny<string>()?? It.IsAny<string>()))
.Returns(true);
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11