本文整理汇总了C#中Moq.Moq.Mock类的典型用法代码示例。如果您正苦于以下问题:C# Moq.Mock类的具体用法?C# Moq.Mock怎么用?C# Moq.Mock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Moq.Mock类属于Moq命名空间,在下文中一共展示了Moq.Mock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ActivateAd_ActivationTokenDoesNotWork_ReturnModelIsActivatedFalse
public void ActivateAd_ActivationTokenDoesNotWork_ReturnModelIsActivatedFalse()
{
// Given
BaseAd ad = new Ad()
{
IsActivated = false,
ActivationToken = "AAA"
};
long adId = 78;
var repoMock = new Moq.Mock<IRepository>();
repoMock.Setup(x => x.Get<BaseAd>(adId)).Returns(ad);
AdActivationServices service = new AdActivationServices(repoMock.Object, null, null, null);
// When
AdActivationResultModel model = service.ActivateAd(adId, "BBB");
// Then
Assert.IsFalse(model.IsActivated);
Assert.AreEqual(78, model.AdId);
Assert.AreEqual("Vous ne pouvez pas activer cette annonce.", model.InfoMessage);
repoMock.Verify(x => x.Save(ad), Moq.Times.Never());
repoMock.Verify(x => x.Save(Moq.It.IsAny<SearchAdCache>()), Moq.Times.Never());
}
开发者ID:bea-project,项目名称:bea-web,代码行数:26,代码来源:AdActivationServicesTest.cs
示例2: shouldHaveSynchronizeWithGoogleFunction
public void shouldHaveSynchronizeWithGoogleFunction() {
var avegaContactServiceMock = new Moq.Mock<IAvegaContactService>();
avegaContactServiceMock.Setup(x => x.SynchronizeWithGoogleContact(It.IsAny<AvegaContact>()))
.Returns(new SynchronizationStatus(true, false, false));
var avetaContactService = avegaContactServiceMock.Object;
avetaContactService.SynchronizeWithGoogleContact(new AvegaContact("MyContact"));
avegaContactServiceMock.Verify();
}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:10,代码来源:IAvegaContactServiceTest.cs
示例3: Setup
public void Setup()
{
_order = new Order();
_mockNotifier = new Moq.Mock<INotify>();
_orderProcessor =
new OrderProcessor(_mockNotifier.Object);
}
开发者ID:henriksen,项目名称:TDDWorkshop,代码行数:7,代码来源:OrderProcessorTests.cs
示例4: StepDefinitions
public StepDefinitions()
{
var mock = new Moq.Mock<IUserAuthentication>();
mock.Expect(x => x.IsValidLogin("admin", "password")).Returns(true);
//mock.Expect(x => x.IsValidLogin(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
_auth = mock.Object;
}
开发者ID:JorgeMCSilva,项目名称:NetPonto,代码行数:7,代码来源:UserAuthentication.cs
示例5: AsteroidHasDifficulty
public void AsteroidHasDifficulty()
{
var veldnium = new ItemInfo(ItemCode.Veldnium);
var itemFactory = new Moq.Mock<IItemFactory>(MockBehavior.Strict);
itemFactory.Setup(x => x.Build(ItemCode.Veldnium, It.IsAny<uint>()))
.Returns<ItemCode, uint>((item, quantity) => new Item(veldnium, quantity));
var mining = new MiningTask(itemFactory.Object) { };
mining.SetParameters(new MineAsteroidParameters(_ship, _difficultAsteroid));
var result = mining.Mine();
Assert.That(result.Success, Is.True);
Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.Pending));
Assert.That(_difficultAsteroid.AmountRemaining, Is.EqualTo(1000));
Assert.That(_ship.Tasks, Contains.Item(mining));
result = mining.Mine();
Assert.That(result.Success, Is.True);
Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.Success));
Assert.That(result.Ore.Quantity, Is.EqualTo(2));
Assert.That(_difficultAsteroid.AmountRemaining, Is.EqualTo(998));
_ship.Tasks.ShouldNotContain(mining);
}
开发者ID:andy-uq,项目名称:Echo,代码行数:25,代码来源:MiningTests.cs
示例6: GetDataServiceMock
private static IDataService GetDataServiceMock(List<Product> products)
{
var dataServiceMock = new Moq.Mock<IDataService>(MockBehavior.Strict);
dataServiceMock.Setup(s => s.GetProductsByProductCode(It.IsAny<int>())).Returns(products);
return dataServiceMock.Object;
}
开发者ID:halcwb,项目名称:GenImport,代码行数:7,代码来源:WcfServiceShould.cs
示例7: OwinServerFixture
public OwinServerFixture()
{
var list = new List<TodoItem> {
new TodoItem() { Id = 1, Completed = false, Title = "Test 1" },
new TodoItem() { Id = 2, Completed = true, Title = "Test 2" }
};
ServiceMock = new Moq.Mock<ITodoService>();
ServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);
var notCompleted = list.Where(x => x.Completed == false).ToList();
ServiceMock.Setup(x => x.ClearCompleted()).ReturnsAsync(notCompleted);
var newTask = new TodoItem() { Completed = false, Title = "Test 3" };
ServiceMock.Setup(x => x.AddAsync(It.IsAny<TodoItem>())).ReturnsAsync(newTask);
const int taskId = 2;
var existingTask = new TodoItem() { Id = 2, Completed = false, Title = "Test 3" };
ServiceMock.Setup(x => x.UpdateAsync(taskId, It.IsAny<TodoItem>())).ReturnsAsync(existingTask);
ServiceMock.Setup(x => x.DeleteAsync(taskId)).ReturnsAsync(true);
const int missingTaskId = 4;
ServiceMock.Setup(x => x.UpdateAsync(missingTaskId, existingTask)).ReturnsAsync(null);
ServiceMock.Setup(x => x.DeleteAsync(missingTaskId)).ReturnsAsync(false);
TestServer = TestServer.Create(Configuration);
}
开发者ID:rdacorp,项目名称:UnitTesting-Lab,代码行数:27,代码来源:OwinServerFixture.cs
示例8: Test_NormalViewModel
public void Test_NormalViewModel()
{
ClearAll();
IMvxViewModel outViewModel = new Test2ViewModel();
var mockLocator = new Mock<IMvxViewModelLocator>();
mockLocator.Setup(
m => m.Load(It.IsAny<Type>(), It.IsAny<IMvxBundle>(), It.IsAny<IMvxBundle>()))
.Returns(() => outViewModel);
var mockCollection = new Moq.Mock<IMvxViewModelLocatorCollection>();
mockCollection.Setup(m => m.FindViewModelLocator(It.IsAny<MvxViewModelRequest>()))
.Returns(() => mockLocator.Object);
Ioc.RegisterSingleton(mockCollection.Object);
var parameters = new Dictionary<string, string> { { "foo", "bar" } };
var request = new MvxViewModelRequest<Test2ViewModel>(new MvxBundle(parameters), null,
MvxRequestedBy.UserAction);
var state = new MvxBundle();
var loader = new MvxViewModelLoader();
var viewModel = loader.LoadViewModel(request, state);
Assert.AreSame(outViewModel, viewModel);
Assert.AreEqual(MvxRequestedBy.UserAction, viewModel.RequestedBy);
}
开发者ID:talisqualis,项目名称:MvvmCross-Build,代码行数:27,代码来源:MvxViewModelLoaderTest.cs
示例9: WhenAPageWithResultsIsReturnedTheResultsShouldBeExtracted
public void WhenAPageWithResultsIsReturnedTheResultsShouldBeExtracted()
{
// ARRANGE
List<QUnitTest> expectedResult = new List<QUnitTest>();
expectedResult.Add(new QUnitTest { TestName = "IE browser should call IE branch", Result = "pass", Message = "", FileName = "" });
expectedResult.Add(new QUnitTest { TestName = "Firefox browser should call its branch", Result = "fail", Message = "Register Css For Firefox is called Once", FileName = "" });
var mockWebResponse = new Mock<WebResponse>();
var embeddedResourceHelper = new EmbeddedResourceHelper(
Assembly.GetExecutingAssembly(),
FullDataResource("QUnitResults.htm"),
"QUnitResults.htm"
);
var testUrl = String.Format("file://{0}", embeddedResourceHelper.FullPath);
Moq.Mock<IBrowser> mockBrowser = new Moq.Mock<IBrowser>();
// ACT
var sut = new QUnitParserHtmlUnit(5000,new HtmlUnitBrowser());
var result = sut.GetQUnitTestResults(testUrl);
// ASSERT
var resultEnumerator = result.GetEnumerator();
var expectedItem = 0;
while (resultEnumerator.MoveNext())
{
Assert.That(resultEnumerator.Current.Result, Is.EqualTo(expectedResult[expectedItem].Result));
Assert.That(resultEnumerator.Current.Message, Is.EqualTo(expectedResult[expectedItem].Message));
Assert.That(resultEnumerator.Current.FileName, Is.EqualTo(expectedResult[expectedItem].FileName));
Assert.That(resultEnumerator.Current.InitializationException, Is.EqualTo(expectedResult[expectedItem].InitializationException));
Assert.That(resultEnumerator.Current.TestName, Is.EqualTo(expectedResult[expectedItem].TestName));
expectedItem++;
}
}
开发者ID:mattdotmatt,项目名称:NQUnit,代码行数:35,代码来源:HtmlUnitQUnitParserTests.cs
示例10: AdvancedSearchAds_SearchThroughAds_CallSearchRepoOnAds
public void AdvancedSearchAds_SearchThroughAds_CallSearchRepoOnAds()
{
// Given
Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.Ad };
AdSearchModel model = new AdSearchModel();
model.CategorySelectedId = 1;
model.SearchString = "toto";
model.CitySelectedId = 12;
IList<SearchAdCache> searchResult = new List<SearchAdCache>();
searchResult.Add(new SearchAdCache
{
Title = "ship",
City = new City() { Label = "the city" },
Category = cat
});
var repoMock = new Moq.Mock<IRepository>();
repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);
var searchRepoMock = new Moq.Mock<ISearchRepository>();
searchRepoMock.Setup(r => r.SearchAds(It.Is<String[]>(x => x[0] == "toto"), 12, It.Is<int[]>(x => x[0] == 1))).Returns(searchResult);
SearchServices service = new SearchServices(repoMock.Object, null, searchRepoMock.Object, null, null, null);
// When
AdSearchResultModel result = service.LightSearchAds(model);
// Then
Assert.AreEqual(1, result.SearchResultTotalCount);
}
开发者ID:bea-project,项目名称:bea-web,代码行数:32,代码来源:SearchServicesTest.cs
示例11: SetUp
public void SetUp()
{
var mock = new Moq.Mock<ILocationServices>();
mock.Setup(x => x.GetExitPosition(It.IsAny<ILocation>())).Returns<ILocation>(l => l.Position.LocalCoordinates);
_task = new JumpShipTask(mock.Object);
}
开发者ID:andy-uq,项目名称:Echo,代码行数:7,代码来源:JumpShipTaskTests.cs
示例12: ActivateAd_ActivationTokenWorks_ReturnModelIsActivatedTrueAndActivatesAd
public void ActivateAd_ActivationTokenWorks_ReturnModelIsActivatedTrueAndActivatesAd()
{
// Given
BaseAd ad = new Ad()
{
IsActivated = false,
ActivationToken = "AAA",
City = new City(),
Category = new Category()
};
long adId = 78;
var repoMock = new Moq.Mock<IRepository>();
repoMock.Setup(x => x.Get<BaseAd>(adId)).Returns(ad);
AdActivationServices service = new AdActivationServices(repoMock.Object, null, null, null);
// When
AdActivationResultModel model = service.ActivateAd(78, "AAA");
// Then
Assert.IsTrue(model.IsActivated);
Assert.AreEqual(78, model.AdId);
Assert.AreEqual("Merci d'avoir activé votre annonce.", model.InfoMessage);
repoMock.Verify(x => x.Save(ad), Moq.Times.Once());
repoMock.Verify(x => x.Save(Moq.It.IsAny<SearchAdCache>()), Moq.Times.Once());
}
开发者ID:bea-project,项目名称:bea-web,代码行数:28,代码来源:AdActivationServicesTest.cs
示例13: ClientSideValidationRules_Helper_Passes_ActiveRuleProvider_Output_To_Formatter
public void ClientSideValidationRules_Helper_Passes_ActiveRuleProvider_Output_To_Formatter()
{
// Arrange
var html = new HtmlHelperMocks<object>().HtmlHelper;
var arbitraryType = typeof (DateTime);
var ruleProvider = new Moq.Mock<IRulesProvider>();
var rules = new RuleSet(new[] { "someProperty" }.ToLookup(x => x, x => (Rule)new RequiredRule()));
ruleProvider.Expect(x => x.GetRulesFromType(arbitraryType)).Returns(rules);
ActiveRuleProviders.Providers.Clear();
ActiveRuleProviders.Providers.Add(ruleProvider.Object);
// Capture params passed to mockFormatter
var mockFormatter = new Moq.Mock<IValidationConfigFormatter>(MockBehavior.Strict);
RuleSet passedRules = null;
Action<RuleSet> callback = x =>
{
passedRules = x;
};
mockFormatter.Expect(x => x.FormatRules(It.IsAny<RuleSet>()))
.Callback(callback)
.Returns("ok");
ValidationInfo.Formatter = mockFormatter.Object;
// Act
var result = html.ClientSideValidationRules(arbitraryType);
// Assert
Assert.Equal("ok", result.ToString());
Assert.Equal(1, passedRules.Keys.Count());
Assert.Same(rules["someProperty"].Single(), passedRules["someProperty"].First());
}
开发者ID:chakrit,项目名称:xVal-mirror,代码行数:31,代码来源:HtmlHelpersTests.cs
示例14: GoalSetup
private void GoalSetup()
{
AutoMapper.Mapper.CreateMap<ContestEventGoal, ContestEventGoalViewModel>()
.ForMember(dest => dest.Result, opt => opt.ResolveUsing<GoalDataResolver>());
profileRepositoryMock = new Moq.Mock<IProfileRepository>();
profileRepositoryMock.Setup(t => t.RetrieveGoals()).Returns(goals);
controller = new GoalController(profileRepositoryMock.Object);
}
开发者ID:dimtruck,项目名称:The-Challenge,代码行数:8,代码来源:GoalTest.cs
示例15: shouldBeAbleToReportWarnings
public void shouldBeAbleToReportWarnings() {
var avegaContactServiceMock = new Moq.Mock<IAvegaContactService>();
var avetaContactService = avegaContactServiceMock.Object;
avetaContactService.Warning += (sender, ev) => {
Console.WriteLine(ev.Message);
};
}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:8,代码来源:IAvegaContactServiceTest.cs
示例16: MockProductsRepository
static IProductsRepository MockProductsRepository(params Product[] prods)
{
var mockProductsRepos = new Moq.Mock<IProductsRepository>();
mockProductsRepos.Setup(x => x.Products).Returns(prods.AsQueryable());
return mockProductsRepos.Object;
}
开发者ID:RocGod,项目名称:brianrepo,代码行数:8,代码来源:ProductControllerTests.cs
示例17: shouldHaveGetAll
public void shouldHaveGetAll() {
var avegaContactRepositoryMock = new Moq.Mock<IAvegaClientRepository>();
avegaContactRepositoryMock.Setup(x=>x.GetAll())
.Returns(new List<AvegaContact>());
IAvegaClientRepository avegaContactRepository = avegaContactRepositoryMock.Object;
avegaContactRepository.GetAll();
}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:9,代码来源:IAvegaClientRepositoryTest.cs
示例18: shouldBeAbleToValidateAuthentication
public void shouldBeAbleToValidateAuthentication() {
var avegaClientRepositoryMock = new Moq.Mock<IAvegaClientRepository>();
avegaClientRepositoryMock.Setup(x => x.IsAuthenticationValid).Returns(true);
Assert.IsTrue(avegaClientRepositoryMock.Object.IsAuthenticationValid);
}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:9,代码来源:IAvegaClientRepositoryTest.cs
示例19: AddTaskQueue
public void AddTaskQueue()
{
var mock = new Moq.Mock<ITask>();
var queue = new TaskQueue();
queue.Add(mock.Object);
Assert.That(queue.Count, Is.EqualTo(1));
}
开发者ID:andy-uq,项目名称:Echo,代码行数:9,代码来源:TaskQueueTests.cs
示例20: GetMockedScriptModuleRepositoryForDependencyGraph
IScriptModuleRepository GetMockedScriptModuleRepositoryForDependencyGraph(IEnumerable<string> dependencyGraph, out ModuleInfo mainModule)
{
var moduleRepo = new Moq.Mock<IScriptModuleRepository>();
foreach (var moduleInfo in GetModuleArrayFromDependencyGraph(dependencyGraph, out mainModule))
{
moduleRepo.Setup((repo) => repo.GetModule(moduleInfo.Name)).Returns(moduleInfo);
}
return moduleRepo.Object;
}
开发者ID:karlbohlmark,项目名称:front,代码行数:9,代码来源:CombiningModulePackagerFacts.cs
注:本文中的Moq.Moq.Mock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论