当前位置: 首页>>代码示例>>C#>>正文


C# Mock.VerifySet方法代码示例

本文整理汇总了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);
        }
开发者ID:arvydas,项目名称:tweetz-desktop,代码行数:26,代码来源:TestTimelineController.cs

示例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());
        }
开发者ID:rodel-rdi,项目名称:Simpler,代码行数:26,代码来源:BuildParametersUsingTest.cs

示例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")));
        }
开发者ID:petarrepac,项目名称:playing-with-moq,代码行数:32,代码来源:When_an_order_is_to_be_written_to_disk.cs

示例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));
        }
开发者ID:taeatonDev,项目名称:UnitTestTraining,代码行数:26,代码来源:MOQ_Verification.cs

示例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>());
        }
开发者ID:ConnorChristie,项目名称:Twitch-Plays-Minesweeper,代码行数:11,代码来源:MinesweeperGenerate.cs

示例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);
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:11,代码来源:DbConfigurationTests.cs

示例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");
        }
开发者ID:Ciashop,项目名称:API-Client,代码行数:13,代码来源:APIAuthorizerTest.cs

示例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());
        }
开发者ID:frenzypeng,项目名称:securityswitch,代码行数:15,代码来源:LocationRedirectorTests.cs

示例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"));
        }
开发者ID:tdbrian,项目名称:Platibus,代码行数:34,代码来源:TopicControllerTests.cs

示例12: DefinitionSetsLexerToIgnoreWhitespace

        public void DefinitionSetsLexerToIgnoreWhitespace()
        {
            var mockedLexer = new Mock<ILexer>();
            _htmlDefinitions.SetupLexer(mockedLexer.Object);

            mockedLexer.VerifySet(x => x.IgnoreWhitespace = true);
        }
开发者ID:KallDrexx,项目名称:cs262,代码行数:7,代码来源:HtmlTokenTests.cs

示例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));
        }
开发者ID:e82eric,项目名称:Prompts,代码行数:29,代码来源:CasscadingSearchShoppingCartBuilderTest.cs

示例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());
        }
开发者ID:pvandervelde,项目名称:Apollo,代码行数:26,代码来源:NotificationPresenterTest.cs

示例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());
        }
开发者ID:pvandervelde,项目名称:Apollo,代码行数:35,代码来源:ProjectDescriptionPresenterTest.cs


注:本文中的Mock.VerifySet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。