本文整理汇总了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"));
}