????????????????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"));
}
??????????????????????????????IFake?????Mock<IFake>????? ?????IFake??
???????????????????Setup()???????????????????????Setup??????????????lambda????????????????????:???????????foo??????????????DoSomething()???????????Ping??????? Return (true)???????????????????????????檔???????????????????????????????DoSomething()???????????????????? Ping????????????true???????????????????????????ж???????????????
???????Foo?????????????????????????????????????????????????????.
????It
??????????????????????????????????Is<TValue>?? IsAny<TValue>?? IsInRange<TValue>?? ??IsRegex?????????????????±??????
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);
}
?????κ???????Send()???????????????????κε?string???????????????true??
????????????????lambda????????????????
????var productRepository = new Mock<IProductRepository>();
????productRepository
????.Expect(p => p.Get(It.Is<int>(id => id > 0 && id < 6)))
????.Returns(newProduct.Object);
??????????????????????id??0??6???????????????μ??????????????????????????????ο???????? Moq’s QuickStart
????????????????????? Match<T>??????????????????????
????MockBehavior
????12????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????