本文整理汇总了C#中Moq.Mock.Verify方法的典型用法代码示例。如果您正苦于以下问题:C# Moq.Mock.Verify方法的具体用法?C# Moq.Mock.Verify怎么用?C# Moq.Mock.Verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moq.Mock
的用法示例。
在下文中一共展示了Moq.Mock.Verify方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_execute_the_handler_when_an_event_is_raised
public void should_execute_the_handler_when_an_event_is_raised()
{
var handler = new Moq.Mock<CreateLotsForBrokerageTransactions>();
var @event = new BrokerageTransactionsPersisted(null);
new EventBus(handler.Object).Raise(@event);
handler.Verify(x => x.Handle(@event));
}
示例2: CanSaveEditedProducts
public void CanSaveEditedProducts()
{
var mockRepository = new Moq.Mock<IProductsRepository>();
var product = new Product();
var result = new AdminController(mockRepository.Object).Edit(product, null);
mockRepository.Verify(x => x.SaveProduct(product));
result.ShouldBeRedirectionTo(new { action = "Index" });
}
示例3: TestStartListner
public void TestStartListner()
{
Moq.Mock<Socket> mock = new Moq.Mock<Socket>(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketListener listener = new SocketListener(mock.Object);
listener.Start();
Assert.IsTrue(listener.Started);
Assert.AreEqual(listener.Server,mock.Object);
mock.Verify(s => s.AcceptAsync(Moq.It.IsAny<SocketAsyncEventArgs>()));
}
示例4: MoqTest
public void MoqTest()
{
Moq.Mock<IPushToServer> moq = new Moq.Mock<IPushToServer>();
TestMeClass testme = new TestMeClass(moq.Object);
//setup
moq.Setup(x => x.GetString()).Returns("Hello");
//action
testme.Do();
//verify
moq.Verify(x=>x.Push("Hello"),Moq.Times.AtLeast(3));
}
示例5: TestHeadsetConnected
public void TestHeadsetConnected()
{
var statusMock = new Moq.Mock<ICicStatusService>();
var deviceManagerMock = new Moq.Mock<IDeviceManager>();
var settingsManagerMock = new Moq.Mock<ISettingsManager>();
settingsManagerMock.SetupGet(s => s.HeadsetConnectStatusKey).Returns(STATUS_KEY);
settingsManagerMock.SetupGet(s => s.HeadsetConnectChangeStatus).Returns(true);
var target = new StatusChanger(null, statusMock.Object, deviceManagerMock.Object, settingsManagerMock.Object);
deviceManagerMock.Raise(d => d.HeadsetConnected += null, new Plantronics.UC.SpokesWrapper.ConnectedStateArgs(true, true));
statusMock.Verify(cic => cic.SetStatus(STATUS_KEY));
}
示例6: ShouldNotFailWhenMetricsIsInstalled
public void ShouldNotFailWhenMetricsIsInstalled()
{
if (!this.MetricsInstalled)
{
Assert.IsTrue(true);
return;
}
var mock = new Moq.Mock<IMetricsLogger>();
// Create a WorkflowInvoker and add the IBuildDetail Extension
var target = MetricsInvoker.Create(new List<string> { "*.dll" }, @"c:\binaries", "Metrics.exe", mock.Object);
Assert.IsNotNull(target);
mock.Verify(m => m.LogError(Moq.It.IsAny<string>()), Moq.Times.Never());
}
示例7: ShouldFailWhenMetricsNotInstalled
public void ShouldFailWhenMetricsNotInstalled()
{
if (this.MetricsInstalled)
{
Assert.IsTrue(true);
return;
}
var mock = new Moq.Mock<IMetricsLogger>();
// Create a WorkflowInvoker and add the IBuildDetail Extension
var target = MetricsInvoker.Create(new List<string> { "*.dll" }, @"c:\binaries", "Metrics.exe", mock.Object);
Assert.IsNull(target);
mock.Verify(m => m.LogError(Moq.It.Is<string>(s => s.Contains("Could not locate"))));
}
示例8: CountAdsByCities_CallAdRepository_ReturnResultOfRepo
public void CountAdsByCities_CallAdRepository_ReturnResultOfRepo()
{
// Given
IDictionary<City, int> result = new Dictionary<City, int>();
var adRepoMock = new Moq.Mock<IAdRepository>();
adRepoMock.Setup(r => r.CountAdsByCity()).Returns(result);
AdServices service = new AdServices(adRepoMock.Object, null, null);
// When
IDictionary<City, int> actual = service.CountAdsByCities();
// Then
Assert.AreEqual(result, actual);
adRepoMock.Verify();
}
示例9: Valid_Order_Goes_To_Submitter_And_Displays_Completed_View
public void Valid_Order_Goes_To_Submitter_And_Displays_Completed_View()
{
// Arrange
var mockSubmitter = new Moq.Mock<IOrderSubmitter>();
CartController controller = new CartController(null, mockSubmitter.Object);
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
var formData = new FormCollection {
{ "Name", "Steve" }, { "Line1", "123 My Street" },
{ "Line2", "MyArea" }, { "Line3", "" },
{ "City", "MyCity" }, { "State", "Some State" },
{ "Zip", "123ABCDEF" }, { "Country", "Far far away" },
{ "GiftWrap", bool.TrueString }
};
// Act
var result = controller.CheckOut(cart, formData);
// Assert
Assert.AreEqual("Completed", result.ViewName);
mockSubmitter.Verify(x => x.SubmitOrder(cart));
Assert.AreEqual(0, cart.Lines.Count);
}
示例10: It_should_be_possible_to_parse_and_eval_script_with_modules
public void It_should_be_possible_to_parse_and_eval_script_with_modules()
{
var scriptService = new Moq.Mock<IScriptService>();
scriptService.Setup(p => p.Parse("TestModule.Name", Moq.It.IsAny<ScriptParameterList>())).Returns(new Mocks.ScriptExpressionMock("TestModule.Name", typeof(string)));
TestModule testModule = new TestModule();
ModuleDefinitionList modules = new ModuleDefinitionList();
modules.Add(new ModuleDefinition("TestModule", TestModule.Definition));
PageParameterList parameters = new PageParameterList();
PageScriptService target = new PageScriptService(scriptService.Object);
XValue exp;
exp = target.Parse("@TestModule.Name", typeof(string), modules, parameters);
scriptService.Verify(p => p.Parse("TestModule.Name", Moq.It.IsAny<ScriptParameterList>()));
Dictionary<string, object> modulesInstance = new Dictionary<string, object>();
modulesInstance.Add("TestModule", testModule);
ContextParameterList parametersInstance = new ContextParameterList();
target.Eval(exp, modulesInstance, parametersInstance);
scriptService.Verify(p => p.Eval(Moq.It.IsAny<IScriptExpression>(), Moq.It.IsAny<ScriptParameterList>()));
}
示例11: SpamRequestAd_AdExists_SaveSpamRequest
public void SpamRequestAd_AdExists_SaveSpamRequest()
{
// Given
var adRepoMock = new Moq.Mock<IAdRepository>();
adRepoMock.Setup(x => x.CanDeleteAd(7)).Returns(true);
var repoMock = new Moq.Mock<IRepository>();
repoMock.Setup(x => x.Get<SpamAdType>(3)).Returns(new SpamAdType() { Id = 3 });
var hSMock = new Moq.Mock<IHelperService>();
hSMock.Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(2013, 05, 17, 6, 7, 22));
SpamAdRequestModel model = new SpamAdRequestModel();
model.AdId = 7;
model.Description = "description";
model.RequestorEmail = "[email protected]";
model.SelectedSpamAdTypeId = 3;
SpamAdServices service = new SpamAdServices(adRepoMock.Object, repoMock.Object, hSMock.Object);
// When
SpamAdRequestModel result = service.SpamRequestAd(model);
// Then
Assert.IsFalse(result.CanSignal);
Assert.AreEqual("Votre signalement a correctement été transmis. Merci de votre précieuse aide dans la chasse aux mauvaises annonces !", result.InfoMessage);
repoMock.Verify(x => x.Save(Moq.It.Is<SpamAdRequest>(b =>
b.Description == model.Description
&& b.RequestDate == new DateTime(2013, 05, 17, 6, 7, 22)
&& b.RequestorEmailAddress == model.RequestorEmail
&& b.SpamType.Id == 3)));
}