本文整理汇总了C#中Mock.VerifySet方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.VerifySet方法的具体用法?C# Mock.VerifySet怎么用?C# Mock.VerifySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.VerifySet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructingControllerStartsTimelines
public void ConstructingControllerStartsTimelines()
{
var checkTimelines = new Mock<ITimer>();
var updateTimelines = new Mock<ITimer>();
var queue = new Queue<ITimer>();
queue.Enqueue(checkTimelines.Object);
queue.Enqueue(updateTimelines.Object);
SysTimer.Override = queue.Dequeue;
var timelines = new Mock<ITimelines>();
var controller = new TimelineController(timelines.Object);
controller.StartTimelines();
checkTimelines.Raise(c => c.Elapsed += null, EventArgs.Empty);
updateTimelines.Raise(u => u.Elapsed += null, EventArgs.Empty);
checkTimelines.VerifySet(c => c.Interval = 100);
checkTimelines.VerifySet(c => c.Interval = 60000);
checkTimelines.Verify(c => c.Start());
timelines.Verify(t => t.HomeTimeline());
timelines.Verify(t => t.MentionsTimeline());
updateTimelines.VerifySet(u => u.Interval = 30000);
updateTimelines.Verify(u => u.Start());
timelines.Verify(t => t.UpdateTimeStamps());
Assert.That(controller, Is.Not.Null);
}
示例2: should_create_parameters_for_any_parameters_found_in_the_command_text_with_matching_properties_in_the_object
public void should_create_parameters_for_any_parameters_found_in_the_command_text_with_matching_properties_in_the_object()
{
// Arrange
var task = TaskFactory<BuildParametersUsing<MockObject>>.Create();
var mockDbCommand = new Mock<IDbCommand> { DefaultValue = DefaultValue.Mock };
var mockDbDataParameter = new Mock<IDbDataParameter>();
mockDbCommand.Setup(dbCommand => dbCommand.CreateParameter()).Returns(mockDbDataParameter.Object);
mockDbCommand.Setup(dbCommand => dbCommand.CommandText).Returns("select blah");
task.CommandWithParameters = mockDbCommand.Object;
var mockObject = new MockObject { Name = "John Doe", Age = 21 };
task.ObjectWithValues = mockObject;
var mockFindParameters = new Mock<FindParametersInCommandText>();
mockFindParameters.Setup(findParams => findParams.ParameterNames).Returns(new string[] { "@Age" });
task.FindParametersInCommandText = mockFindParameters.Object;
// Act
task.Execute();
// Assert
mockDbDataParameter.VerifySet(param => param.ParameterName = "@Age");
mockDbDataParameter.VerifySet(param => param.Value = 21);
mockDbCommand.Verify(dbCommand => dbCommand.Parameters.Add(mockDbDataParameter.Object), Times.Once());
}
示例3: it_should_pass_data_to_file_writer
public void it_should_pass_data_to_file_writer()
{
// arrange
var order = new Order {OrderId = 1001, OrderTotal = 10.53M};
var mockFileWriter = new Mock<IFileWriter>();
var orderWriter = new OrderWriter(mockFileWriter.Object);
// act
orderWriter.WriteOrder(order);
// assert
mockFileWriter.Verify(fw => fw.WriteLine("1001,10.53"), Times.Exactly(1));
// method is not executed, expression tree is veryfied
mockFileWriter.Verify(fw => fw.WriteLine(It.IsAny<string>()), Times.Once());
// use regex
mockFileWriter.Verify(fw => fw.WriteLine(It.IsRegex("^1001")), Times.Once());
// use predicate
mockFileWriter.Verify(fw => fw.WriteLine(It.Is<string>(s => s.Length > 3)), Times.Once());
mockFileWriter.Verify(fw => fw.WriteLine(It.Is<string>(s => s.StartsWith("1001,10.53"))), Times.Once());
// can use local variable
string expectedValue = "1001,10.53";
mockFileWriter.Verify(fw => fw.WriteLine(It.Is<string>(s => s.StartsWith(expectedValue))), Times.Once());
// verify property
mockFileWriter.VerifySet(fw => fw.FileName = It.IsAny<string>());
mockFileWriter.VerifySet(fw => fw.FileName = "1001.txt");
mockFileWriter.VerifySet(fw => fw.FileName = It.Is<string>(s => s.StartsWith("1001")));
}
示例4: Example
private void Example()
{
var mock = new Mock<IFoo>();
mock.Verify(foo => foo.Execute("ping"));
// Verify with custom error message for failure
mock.Verify(foo => foo.Execute("ping"), "When doing operation X, the service should be pinged always");
// Method should never be called
mock.Verify(foo => foo.Execute("ping"), Times.Never());
// Called at least once
mock.Verify(foo => foo.Execute("ping"), Times.AtLeastOnce());
mock.VerifyGet(foo => foo.Name);
// Verify setter invocation, regardless of value.
mock.VerifySet(foo => foo.Name);
// Verify setter called with specific value
mock.VerifySet(foo => foo.Name = "foo");
// Verify setter with an argument matcher
mock.VerifySet(foo => foo.Value = It.IsInRange(1, 5, Range.Inclusive));
}
示例5: GenerateBoard
public void GenerateBoard()
{
Mock<Grid> grid = new Mock<Grid>();
grid.SetupAllProperties();
MainGame game = new MainGame(grid.Object, 200);
grid.VerifySet(x => x.Width = It.IsAny<double>());
grid.VerifySet(x => x.Height = It.IsAny<double>());
}
示例6: ForProduction_Should_dissallow_upsert_of_schemas_and_synchronization
public void ForProduction_Should_dissallow_upsert_of_schemas_and_synchronization()
{
var settingsFake = new Mock<IDbSettings>();
var dbFake = new Mock<ISisoDatabase>();
dbFake.SetupGet(f => f.Settings).Returns(settingsFake.Object);
dbFake.Object.Configure().ForProduction();
settingsFake.VerifySet(f => f.AllowUpsertsOfSchemas = false);
settingsFake.VerifySet(f => f.SynchronizeSchemaChanges = false);
}
示例7: AuthorizationState_must_define_post_method_and_content_type
public void AuthorizationState_must_define_post_method_and_content_type()
{
var mock = new Mock<HttpHelper>("https://www.mystore.com/manager")
.SetupProperty(m => m.HttpWebRequest.Method);
mock.Setup(m => m.HttpWebRequest.GetRequestStream()).Returns(new MemoryStream());
mock.Setup(m => m.HttpWebRequest.GetResponse().GetResponseStream()).Returns(new MemoryStream());
var target = new APIAuthorizer("client", "key", new Uri("https://www.mystore.com/manager"));
target.AuthorizationState("code", mock.Object);
mock.VerifySet(h => h.HttpWebRequest.Method = "POST");
mock.VerifySet(h => h.HttpWebRequest.ContentType = "application/x-www-form-urlencoded");
}
示例8: Apply_SetsSqlServerConnectionStringWithIntegratedSecurityParameterValuesOnInterface
public void Apply_SetsSqlServerConnectionStringWithIntegratedSecurityParameterValuesOnInterface()
{
// arrage
var information = new Mock<IConnectToDatabaseConnectionInformation>();
var cn = "Server=myServerAddress;Database=myDataBase;Integrated Security=SSPI;";
// act
ConnectionStringHelper.Apply(information.Object, cn);
// assert
information.VerifySet(x => x.Server = "myServerAddress");
information.VerifySet(x => x.Database = "myDataBase");
information.VerifySet(x => x.UseIntegratedSecurity = true);
}
开发者ID:sheryever,项目名称:elmah-log-analyzer-with-custom-data,代码行数:14,代码来源:ConnectionStringHelperTests.cs
示例9: RedirectWithoutBypassingSecurityWarningIssuesPermanentRedirect
public void RedirectWithoutBypassingSecurityWarningIssuesPermanentRedirect()
{
// Arrange.
const string RedirectUrl = "https://www.somewebsite.com/admin/protected-content/";
var mockResponse = new Mock<HttpResponseBase>();
var redirector = new LocationRedirector();
// Act.
redirector.Redirect(mockResponse.Object, RedirectUrl, false);
// Assert.
mockResponse.VerifySet(resp => resp.StatusCode = 301);
mockResponse.VerifySet(resp => resp.RedirectLocation = RedirectUrl);
mockResponse.Verify(resp => resp.End());
}
示例10: Apply_SetsSqlServerConnectionStringWithUsernameAndPasswordParameterValuesOnInterface
public void Apply_SetsSqlServerConnectionStringWithUsernameAndPasswordParameterValuesOnInterface()
{
// arrage
var information = new Mock<IConnectToDatabaseConnectionInformation>();
var cn = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;";
// act
ConnectionStringHelper.Apply(information.Object, cn);
// assert
information.VerifySet(x => x.Server = "myServerAddress");
information.VerifySet(x => x.Database = "myDataBase");
information.VerifySet(x => x.Username = "myUsername");
information.VerifySet(x => x.Password = "myPassword");
}
开发者ID:sheryever,项目名称:elmah-log-analyzer-with-custom-data,代码行数:15,代码来源:ConnectionStringHelperTests.cs
示例11: Given_No_Topic_When_Getting_Then_Topic_List_Returned
public async Task Given_No_Topic_When_Getting_Then_Topic_List_Returned()
{
var mockSubscriptionTrackingService = new Mock<ISubscriptionTrackingService>();
var topics = new TopicName[] {"topic-1", "topic-2", "topic-3"};
var controller = new TopicController(mockSubscriptionTrackingService.Object, topics);
var mockRequest = new Mock<IHttpResourceRequest>();
var requestUri = new UriBuilder
{
Scheme = "http",
Host = "localhost",
Path = "/platibus/topic/"
}.Uri;
mockRequest.Setup(r => r.HttpMethod).Returns("GET");
mockRequest.Setup(r => r.Url).Returns(requestUri);
var mockResponse = new Mock<IHttpResourceResponse>();
var responseOutputStream = new MemoryStream();
var responseEncoding = Encoding.UTF8;
mockResponse.Setup(r => r.ContentEncoding).Returns(responseEncoding);
mockResponse.Setup(r => r.OutputStream).Returns(responseOutputStream);
await controller.Process(mockRequest.Object, mockResponse.Object, Enumerable.Empty<string>());
mockResponse.VerifySet(r => r.StatusCode = 200);
var responseContent = responseEncoding.GetString(responseOutputStream.GetBuffer());
var topicsFromResponse = new NewtonsoftJsonSerializer().Deserialize<string[]>(responseContent);
Assert.That(topicsFromResponse.Length, Is.EqualTo(3));
Assert.That(topicsFromResponse, Contains.Item("topic-1"));
Assert.That(topicsFromResponse, Contains.Item("topic-2"));
Assert.That(topicsFromResponse, Contains.Item("topic-3"));
}
示例12: DefinitionSetsLexerToIgnoreWhitespace
public void DefinitionSetsLexerToIgnoreWhitespace()
{
var mockedLexer = new Mock<ILexer>();
_htmlDefinitions.SetupLexer(mockedLexer.Object);
mockedLexer.VerifySet(x => x.IgnoreWhitespace = true);
}
示例13: ItDoesNotSetTheSearchStringIfThereIsNotADefaultValue
public void ItDoesNotSetTheSearchStringIfThereIsNotADefaultValue()
{
var promptItems = A.ObservableCollection(Mock.Of<ISearchablePromptItem>(), Mock.Of<ISearchablePromptItem>());
var promptInfo = A.PromptInfo()
.WithDefaultValues(new ObservableCollection<ValidValue>())
.Build();
_promptItemCollectionProvider
.Setup(
b => b.Get(
promptInfo.Name,
promptInfo.PromptLevelInfo.ParameterName,
promptInfo.DefaultValues))
.Returns(promptItems);
var promptToReturn = new Mock<IMultiSelectPrompt>();
_casscadingSearchProvider
.Setup(p => p.Get(
promptInfo.Label, promptInfo.Name,
promptInfo.PromptLevelInfo.ParameterName,
promptItems,
promptItems))
.Returns(promptToReturn.Object);
_builder.BuildFrom(promptInfo);
promptToReturn.VerifySet(p => p.SearchString = It.IsAny<string>(), Times.Exactly(0));
}
示例14: Initialize
public void Initialize()
{
var context = new Mock<IContextAware>();
var view = new Mock<INotificationView>();
{
view.SetupSet(v => v.Model = It.IsAny<NotificationModel>())
.Verifiable();
}
var parameter = new NotificationParameter(context.Object);
var container = new Mock<IDependencyInjectionProxy>();
{
container.Setup(c => c.Resolve<IContextAware>())
.Returns(context.Object);
container.Setup(c => c.Resolve<ICollectNotifications>())
.Returns(new Mock<ICollectNotifications>().Object);
}
var presenter = new NotificationPresenter(container.Object);
((IPresenter)presenter).Initialize(view.Object, parameter);
Assert.AreSame(view.Object, presenter.View);
Assert.AreSame(parameter, presenter.Parameter);
view.VerifySet(v => v.Model = It.IsAny<NotificationModel>(), Times.Once());
}
示例15: Initialize
public void Initialize()
{
var context = new Mock<IContextAware>();
var view = new Mock<IProjectDescriptionView>();
{
view.SetupSet(v => v.Model = It.IsAny<ProjectDescriptionModel>())
.Verifiable();
}
var parameter = new ProjectDescriptionParameter(context.Object);
var project = new Mock<IProject>();
var facade = new ProjectFacade(project.Object);
var projectLink = new Mock<ILinkToProjects>();
{
projectLink.Setup(p => p.ActiveProject())
.Returns(facade);
}
var container = new Mock<IDependencyInjectionProxy>();
{
container.Setup(c => c.Resolve<IContextAware>())
.Returns(context.Object);
container.Setup(c => c.Resolve<ILinkToProjects>())
.Returns(projectLink.Object);
}
var presenter = new ProjectDescriptionPresenter(container.Object);
((IPresenter)presenter).Initialize(view.Object, parameter);
Assert.AreSame(view.Object, presenter.View);
Assert.AreSame(parameter, presenter.Parameter);
view.VerifySet(v => v.Model = It.IsAny<ProjectDescriptionModel>(), Times.Once());
}