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


C# Mock.SetupProperty方法代码示例

本文整理汇总了C#中Mock.SetupProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetupProperty方法的具体用法?C# Mock.SetupProperty怎么用?C# Mock.SetupProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.SetupProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Bounds_Should_Be_Set_After_Layout_Pass

        public void Bounds_Should_Be_Set_After_Layout_Pass()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();
                Locator.CurrentMutable.RegisterConstant(new LayoutManager(), typeof(ILayoutManager));

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupProperty(x => x.ClientSize);
                impl.SetupProperty(x => x.Resized);

                var target = new TestTopLevel(impl.Object)
                {
                    Template = new ControlTemplate<TestTopLevel>(x =>
                        new ContentPresenter
                        {
                            [~ContentPresenter.ContentProperty] = x[~TestTopLevel.ContentProperty],
                        }),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
            }
        }
开发者ID:Scellow,项目名称:Perspex,代码行数:30,代码来源:TopLevelTests.cs

示例2: ItShouldBeAbleToSetQueryParameter

        public void ItShouldBeAbleToSetQueryParameter()
        {
            // Arrange
            var dataProviderMock = new Mock<IDataObjectsFactory>();
            var dataCommandMock = new Mock<IDbCommand>();
            var dataParameterMock = new Mock<IDbDataParameter>();

            var databaseContext = Database.ForProvider(dataProviderMock.Object);
            
            dataProviderMock.Setup(c => c.CreateCommand())
                            .Returns(dataCommandMock.Object);

            dataProviderMock.Setup(c => c.CreateParameter())
                            .Returns(dataParameterMock.Object);

            dataParameterMock.SetupProperty(c => c.Value);
            dataParameterMock.SetupProperty(c => c.ParameterName);
            
            // Act
            var databaseCommand = databaseContext.Execute("SELECT * FROM Table")
                                                 .Where("Id", p => p.Is(1));

            // Assert
            Assert.That(dataParameterMock.Object.ParameterName, Is.EqualTo("@Id"));
            Assert.That(dataParameterMock.Object.Value, Is.EqualTo(1));
        }
开发者ID:ldiego08,项目名称:Flunt.NET,代码行数:26,代码来源:WhenCreatingDatabaseQueries.cs

示例3: Example

        public void Example()
        {
            var mock = new Mock<IFoo>();

            mock.Setup(foo => foo.Name).Returns("bar");

            // auto-mocking hierarchies (a.k.a. recursive mocks)
            mock.Setup(foo => foo.Bar.Baz.Name).Returns("baz");

            // expects an invocation to set the value to "foo"
            mock.SetupSet(foo => foo.Name = "foo");

            // or verify the setter directly
            mock.VerifySet(foo => foo.Name = "foo");

            //Setup a property so that it will automatically start tracking its value (also known as Stub):
            // start "tracking" sets/gets to this property
            mock.SetupProperty(f => f.Name);

            // alternatively, provide a default value for the stubbed property
            mock.SetupProperty(f => f.Name, "foo");

            // Now you can do:
            IFoo ifoo = mock.Object;
            // Initial value was stored
            Assert.AreEqual("foo", ifoo.Name);

            // New value set which changes the initial value
            ifoo.Name = "bar";
            Assert.AreEqual("bar", ifoo.Name);
        }
开发者ID:ServiceManagementGroup,项目名称:IntegrationTestTraining,代码行数:31,代码来源:MOQ_Properties_Stubs.cs

示例4: HandleTest

        public void HandleTest()
        {
            string pageName = "search";
            byte[] content = Encoding.UTF8.GetBytes("<html><body>Search me</body></html>");

            MockResourceRepository resourceRepository = new MockResourceRepository();
            resourceRepository.LoadResource(pageName, content);

            HtmlPage target = new HtmlPage();

            var request = new Mock<IServiceRequest>();
            request.SetupGet(x => x.ResourceName).Returns(pageName);
            request.SetupGet(x => x.Extension).Returns("");
            request.SetupGet(x => x.Query).Returns("");

            var response = new Mock<IServiceResponse>();
            response.SetupProperty(x => x.ContentType);
            response.SetupProperty(x => x.StatusCode);

            MemoryStream contentStream = new MemoryStream();
            response.SetupGet(x => x.ContentStream).Returns(contentStream);

            target.Handle(request.Object, response.Object, resourceRepository);

            Assert.AreEqual("text/html", response.Object.ContentType);
            Assert.AreEqual(200, response.Object.StatusCode);

            byte[] actualContent = contentStream.ToArray();
            Assert.AreEqual(content.Length, actualContent.Length);
            for (int i = 0; i < content.Length; i++)
            {
                Assert.AreEqual(content[i], actualContent[i]);
            }
        }
开发者ID:adambird,项目名称:eaep,代码行数:34,代码来源:HtmlPageTest.cs

示例5: ShouldFillComboInfoWhenLoading

        public void ShouldFillComboInfoWhenLoading()
        {
            //Arrange
            Mock<IPermittingView> view = new  Mock<IPermittingView>();

            EquipmentComboVO equipment = new EquipmentComboVO()
            {
                EquipmentId = 1,
                IsPrimary = true,
                DivisionNumber = "084",
                UnitNumber = "01",
                Descriptor = "Dozer"
            };

            view.SetupProperty(v => v.EquipmentInfoItem, equipment);
            view.SetupProperty(v => v.IsPrimaryObjectSelected, false);
            view.SetupProperty(v => v.DivisionSelected, string.Empty);
            view.SetupProperty(v => v.UnitNumberSelected, string.Empty);
            view.SetupProperty(v => v.DescriptorSelected, string.Empty);
            //Act
            PermittingPresenter presenter = new PermittingPresenter(view.Object);
            presenter.LoadShoppingCartRow();

            //Assert
            Assert.IsTrue(view.Object.IsPrimaryObjectSelected);
            Assert.AreEqual<string>(view.Object.DivisionSelected, "084");
            Assert.AreEqual<string>(view.Object.UnitNumberSelected, "01");
            Assert.AreEqual<string>(view.Object.DescriptorSelected, "Dozer");
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:29,代码来源:PermittingPresenterTest.cs

示例6: ShouldFillDataSourceComboInShoppingCart

        public void ShouldFillDataSourceComboInShoppingCart()
        {
            //Arrange
            Mock<IPermittingView> view = new Mock<IPermittingView>();
            view.SetupProperty(v => v.EquipmentComboId, 1);
            view.SetupProperty(v => v.ComboName, string.Empty);
            view.SetupProperty(v => v.ComboType, string.Empty);
            view.SetupProperty(v => v.EquipmentInfoShoppingCartDataSource, null);

            Mock<EquipmentModel> model = new Mock<EquipmentModel>();
            model.Setup(m => m.GetCombo(1)).Returns(new CS_EquipmentCombo() { Name = "comboName", ComboType = "comboType" });
            model.Setup(m => m.ListEquipmentsOfACombo(1)).Returns(
                new List<EquipmentComboVO>() {
                    new EquipmentComboVO() { Descriptor = null, DivisionNumber = "Division", EquipmentId = 1, IsPrimary = true, UnitNumber = "1" },
                    new EquipmentComboVO() { Descriptor = null, DivisionNumber = "Division", EquipmentId = 2, IsPrimary = false, UnitNumber = "2" }
                });

            PermittingPresenter presenter = new PermittingPresenter(view.Object, model.Object);

            //Act
            presenter.LoadCombo();

            //Assert
            Assert.AreEqual("comboName", view.Object.ComboName, "Failed in ComboName Property");
            Assert.AreEqual("comboType", view.Object.ComboType, "Failed in ComboType Property");
            Assert.IsNotNull(view.Object.EquipmentInfoShoppingCartDataSource, "Failed in DataSource Property (NULL)");
            Assert.AreEqual(2, view.Object.EquipmentInfoShoppingCartDataSource.Count, "Failed in DataSource Property (COUNT)");
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:28,代码来源:PermittingPresenterTest.cs

示例7: MinHourDifferenceIsAtLeastAnHour

        public void MinHourDifferenceIsAtLeastAnHour()
        {
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var endTimeProperty = new Mock<IPropertyInfo>();
            endTimeProperty.Setup(s => s.Name).Returns("endTime");
            endTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));


            var wsMock = new Mock<IWorkSchedule>();
            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014, 4, 1, 10, 0, 0));
            wsMock.SetupProperty<DateTime>(ws => ws.EndTime, new DateTime(2014, 4, 1, 10, 30, 0));

            var newRule = new MinHourDifferenceRule(startTimeProperty.Object, endTimeProperty.Object);
            var ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime }, { endTimeProperty.Object, wsMock.Object.EndTime } });
            var ruleInterface = (IBusinessRule)newRule;

            ruleInterface.Execute(ruleContext);


            Assert.IsTrue(ruleContext.Results.Count > 0);

            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014, 4, 1, 8, 0, 0));
            wsMock.SetupProperty<DateTime>(ws => ws.EndTime, new DateTime(2014, 4, 1, 9, 30, 0));
            ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime }, { endTimeProperty.Object, wsMock.Object.EndTime } });
            ruleInterface = (IBusinessRule)newRule;

            ruleInterface.Execute(ruleContext);
            Assert.IsTrue(ruleContext.Results.Count == 0);
        }
开发者ID:rbocobo,项目名称:MagenicMasters.Csla,代码行数:32,代码来源:MinHourDifferenceRuleTest.cs

示例8: GetMockRequestContext

 public static RequestContext GetMockRequestContext(this HttpContextBase httpContextBase)
 {
     var requestContext = new Mock<RequestContext>();
     requestContext.SetupProperty(r => r.HttpContext, httpContextBase);
     requestContext.SetupProperty(r => r.RouteData, new RouteData());
     return requestContext.Object;
 }
开发者ID:rinckd,项目名称:sblog.net,代码行数:7,代码来源:MockFactory.cs

示例9: Bounds_Should_Be_Set_After_Layout_Pass

        public void Bounds_Should_Be_Set_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();
                PerspexLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(new LayoutManager());

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupProperty(x => x.ClientSize);
                impl.SetupProperty(x => x.Resized);

                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
            }
        }
开发者ID:randydotnet,项目名称:Perspex,代码行数:26,代码来源:TopLevelTests.cs

示例10: Call_with_HttpMethod_Post_must_write_content_on_request_body

        public void Call_with_HttpMethod_Post_must_write_content_on_request_body()
        {
            var content =   "{" +
                                "\"id\": \"1\"," +
                                "\"name\": \"Department\"" +
                            "}";

            string writedString = string.Empty;
            var mockMS = new Mock<MemoryStream>();
            mockMS.Setup(m => m.CanWrite).Returns(true);
            mockMS.Setup(m => m.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>())).Callback(
                (byte[] b, int i1, int i2) =>
                {
                    writedString = new System.Text.ASCIIEncoding().GetString(b, i1, i2);
                });

            var mock = new Mock<HttpHelper>("https://www.mystore.com/api/v1");
            mock.SetupProperty(m => m.HttpWebRequest.Method);
            mock.SetupProperty(m => m.HttpWebRequest.ContentType);
            mock.SetupProperty(m => m.HttpWebRequest.Headers, new WebHeaderCollection());
            mock.Setup(m => m.HttpWebRequest.GetRequestStream()).Returns(mockMS.Object);
            mock.Setup(m => m.HttpWebRequest.GetResponse().GetResponseStream()).Returns(new MemoryStream());

            APIClient target = new APIClient(new AuthState
            {
                AccessToken = "token",
                ApiUrl = "https://www.mystore.com/api/v1"
            });

            target.Call(HttpMethods.POST, "departments", content, mock.Object);

            mock.VerifySet(h => h.HttpWebRequest.Method = "POST");
            Assert.AreEqual(content, writedString);
        }
开发者ID:Ciashop,项目名称:API-Client,代码行数:34,代码来源:APIClientTest.cs

示例11: FilteredEquipmentsRowDataBound

        public void FilteredEquipmentsRowDataBound()
        {
            //Arrange
            IList<CS_FirstAlertVehicle> firstAlertVehicleList = new List<CS_FirstAlertVehicle>();

            firstAlertVehicleList.Add(new CS_FirstAlertVehicle()
            {
                Active = true,
                EquipmentID = 1,
                Damage = "TL",
                EstimatedCost = 100,
            });

            Mock<IFirstAlertView> mock = new Mock<IFirstAlertView>();
            mock.SetupProperty(c => c.FirstAlertVehicleList, firstAlertVehicleList);
            mock.SetupProperty(c => c.FilteredEquipmentsEquipmentID, 1);
            mock.SetupProperty(c => c.FilteredEquipmentsDamage, "");
            mock.SetupProperty(c => c.FilteredEquipmentsEstCost, "");
            mock.SetupProperty(c => c.FilteredEquipmentsSelect, false);

            //Act
            FirstAlertViewModel viewModel = new FirstAlertViewModel(mock.Object);

            viewModel.FilteredEquipmentsRowDataBound();

            // Assert
            Assert.AreEqual("TL", mock.Object.FilteredEquipmentsDamage, "Failed in FilteredEquipmentsDamage");
            Assert.AreEqual(string.Format("{0:0.00}", 100), mock.Object.FilteredEquipmentsEstCost, "Failed in FilteredEquipmentsEstCost");
            Assert.AreEqual(true, mock.Object.FilteredEquipmentsSelect, "Failed in FilteredEquipmentsSelect");
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:30,代码来源:FirstAlertViewModelTest.cs

示例12: PassesWhen_StartTimeIsBeforeEndTime

        public void PassesWhen_StartTimeIsBeforeEndTime()
        {
            //arrange
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var endTimeProperty = new Mock<IPropertyInfo>();
            endTimeProperty.Setup(s => s.Name).Returns("EndTime");
            endTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));


            var wsMock = new Mock<IWorkSchedule>();
            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014,4,1,10,0,0));
            wsMock.SetupProperty<DateTime>(ws => ws.EndTime, new DateTime(2014, 4, 1, 11, 0, 0));

            var innerRule1 = new TopOfTheHourRule(startTimeProperty.Object);
            var innerRule2 = new TopOfTheHourRule(endTimeProperty.Object);
            var newRule = new TimeRangeRule(startTimeProperty.Object, endTimeProperty.Object, innerRule1, innerRule2);
            var ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime }, {endTimeProperty.Object, wsMock.Object.EndTime} });
            var ruleInterface = (IBusinessRule)newRule;

            //act
            ruleInterface.Execute(ruleContext);

            //assert

            Assert.IsNull(ruleContext.Results.SingleOrDefault(_ => _.Description == ValidationMessages.InvalidTimeRange));

           
        }
开发者ID:rbocobo,项目名称:MagenicMasters.Csla,代码行数:31,代码来源:TimeRangeRuleTest.cs

示例13: SetupMock

 Role SetupMock()
 {
    Mock<Role> moq = new Mock<Role>();
    moq.SetupProperty(_ => _.Id, id);
    moq.SetupProperty(_ => _.Name, NAME);
    moq.SetupProperty(_ => _.Description, DESCRIPTION);
    return moq.Object;
 }
开发者ID:AleksMorozova,项目名称:prizm,代码行数:8,代码来源:RoleObjectTest.cs

示例14: SetUp

        public void SetUp()
        {
            _navigationServiceBuilder = new NavigationServiceBuilder(false);
            _navigationServiceMock = new Mock<INavigationService>();
            _navigationServiceMock.SetupProperty(service => service.PrimaryNavigatorManager);
            _navigationServiceMock.SetupProperty(service => service.SupportedNavigatorManagers);

            _service = _navigationServiceMock.Object;
        }
开发者ID:VasiliBaranov,项目名称:navigation-assistant,代码行数:9,代码来源:NavigationServiceBuilderTests.cs

示例15: SetupMock

      PlateManufacturer SetupMock()
      {
         Mock<PlateManufacturer> moq = new Mock<PlateManufacturer>();
         moq.SetupProperty(_ => _.Id, id);
         moq.SetupProperty(_ => _.Name, NAME);
         moq.SetupProperty(_ => _.IsActive, true);

         return moq.Object;
      }
开发者ID:AleksMorozova,项目名称:prizm,代码行数:9,代码来源:PlateManufacturerObjectTest.cs


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