本文整理汇总了C#中Moq.Moq.Mock类的典型用法代码示例。如果您正苦于以下问题:C# Moq.Mock类的具体用法?C# Moq.Mock怎么用?C# Moq.Mock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Moq.Mock类属于Moq命名空间,在下文中一共展示了Moq.Mock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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();
}
示例3: Setup
public void Setup()
{
_order = new Order();
_mockNotifier = new Moq.Mock<INotify>();
_orderProcessor =
new OrderProcessor(_mockNotifier.Object);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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++;
}
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例15: shouldBeAbleToReportWarnings
public void shouldBeAbleToReportWarnings() {
var avegaContactServiceMock = new Moq.Mock<IAvegaContactService>();
var avetaContactService = avegaContactServiceMock.Object;
avetaContactService.Warning += (sender, ev) => {
Console.WriteLine(ev.Message);
};
}