本文整理匯總了C#中Moq.MockRepository.Of方法的典型用法代碼示例。如果您正苦於以下問題:C# MockRepository.Of方法的具體用法?C# MockRepository.Of怎麽用?C# MockRepository.Of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Moq.MockRepository
的用法示例。
在下文中一共展示了MockRepository.Of方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: EatArgumentsTest
public void EatArgumentsTest()
{
// Arrange
var expression = Mock.Of<ICSharpExpression>();
var mockRep = new MockRepository(MockBehavior.Default);
var args = new TreeNodeCollection<ICSharpArgument>(mockRep.Of<ICSharpArgument>().Where(t => t.Value == expression).Take(10).ToArray());
var snapshot = Mock.Of<ISnapshot>();
var eater = new Mock<IEater>();
var argumentsEater = new ArgumentsEater(eater.Object);
// Act
argumentsEater.Eat(snapshot, args);
// Assert
eater.Verify(t => t.Eat(snapshot, expression), Times.Exactly(10));
}
示例2: RepoTestMethod
public void RepoTestMethod()
{
var repository = new MockRepository(MockBehavior.Default);
ILoggerSomeDependency logger = repository.Of<ILoggerSomeDependency>()
.Where(ld => ld.GetLoggerInstance == "GetLoggerInstance")
.Where(ld => ld.GetApplicationDirectory() == "C:\\Windows\\Fenestra")
.Where(ld => ld.GetDirectoryForDependencyByLoggerName
(It.IsAny<string>()) == "C:\\Windows\\Temp")
.First();
Assert.That(logger.GetApplicationDirectory(), Is.EqualTo("C:\\Windows\\Fenestra"));
Assert.That(logger.GetLoggerInstance, Is.EqualTo("GetLoggerInstance"));
Assert.That(logger.GetDirectoryForDependencyByLoggerName
("CustomLogger"), Is.EqualTo("C:\\Windows\\Temp"));
}
示例3: Test_Initialize_Multiple_Stubs_Using_Repository_Of_Method
public void Test_Initialize_Multiple_Stubs_Using_Repository_Of_Method()
{
// There is another way to initialize multiple stubs inside one
// expression using LINQ-style syntax (using moq functional specification)
// using MockRepository class
// Arrange
var repository = new MockRepository(MockBehavior.Default);
ILoggerDependency logger = repository.Of<ILoggerDependency>()
.Where(ld => ld.DefaultLogger == "DefaultLogger")
.Where(ld => ld.GetCurrentDirectory() == "D:\\Temp")
.Where(ld => ld.GetDirectoryByLoggerName(It.IsAny<string>()) == "C:\\Temp")
.First();
// Assert
Assert.That(logger.GetCurrentDirectory(), Is.EqualTo("D:\\Temp"));
Assert.That(logger.DefaultLogger, Is.EqualTo("DefaultLogger"));
Assert.That(logger.GetDirectoryByLoggerName("CustomLogger"), Is.EqualTo("C:\\Temp"));
}