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


C# Moq.Mock.SetupGet方法代码示例

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


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

示例1: Content

		public static Mock<IPublishedContent> Content(string name, IEnumerable<IPublishedContent> children)
		{
			var mockedItem = new Moq.Mock<IPublishedContent>();
			mockedItem.SetupGet(m => m.Id).Returns(1);
			mockedItem.SetupGet(m => m.Name).Returns(name);
			mockedItem.SetupGet(m => m.Children).Returns(children);

			return mockedItem;
		}
开发者ID:joosthollander,项目名称:Macaw.Umbraco.Foundation,代码行数:9,代码来源:Arrange.cs

示例2: Setup

        public void Setup()
        {
            var httpContextBaseMock = new Moq.Mock<HttpContextBase>();

            var httpRequestBase = new Moq.Mock<HttpRequestBase>();
            httpRequestBase.SetupGet(r => r.ApplicationPath).Returns(@"\");
            httpContextBaseMock.SetupGet(c => c.Items).Returns(new Dictionary<string, object>());
            httpRequestBase.SetupGet(r => r.Cookies).Returns(new HttpCookieCollection());
            httpRequestBase.Object.Cookies.Add(new HttpCookie(GlimpseConstants.CookieModeKey, "On"));

            httpContextBaseMock.SetupGet(c => c.Request).Returns(httpRequestBase.Object);
            httpContext = httpContextBaseMock.Object;
        }
开发者ID:nagor,项目名称:Glimpse,代码行数:13,代码来源:GlimpseResponseFilterTest.cs

示例3: TickTaskWithRemainingTime

        public void TickTaskWithRemainingTime()
        {
            var result = new Moq.Mock<ITaskResult>(MockBehavior.Strict);
            var mock = new Moq.Mock<ITask>(MockBehavior.Strict);

            mock.Setup(x => x.Execute()).Returns(result.Object);
            result.SetupGet(f => f.TimeRemaining).Returns(1);

            var queue = new TaskQueue();
            queue.Add(mock.Object);

            var count = queue.Tick();
            Assert.That(count, Is.EqualTo(0));
            Assert.That(queue.Count, Is.EqualTo(1));
        }
开发者ID:andy-uq,项目名称:Echo,代码行数:15,代码来源:TaskQueueTests.cs

示例4: ReadsCorrectly

        public void ReadsCorrectly()
        {
            // arrange
            var converter = new EnumConverter();
            var reader1 = new Moq.Mock<JsonReader>();
            reader1.SetupGet(x => x.Value).Returns(null);
            var reader2 = new Moq.Mock<JsonReader>();
            reader2.SetupGet(x => x.Value).Returns("0");
            var reader3 = new Moq.Mock<JsonReader>();
            reader3.SetupGet(x => x.Value).Returns("1");

            // act
            var object1 = converter.ReadJson(reader1.Object, typeof(System.ConsoleColor), null, null);
            var object2 = converter.ReadJson(reader1.Object, typeof(System.ConsoleColor?), null, null);
            var object3 = converter.ReadJson(reader2.Object, typeof(System.ConsoleColor), null, null);
            var object4 = converter.ReadJson(reader3.Object, typeof(System.ConsoleColor), null, null);

            // assert
            Assert.IsNull(object1);
            Assert.IsNull(object2);
            Assert.AreEqual(System.ConsoleColor.Black, (System.ConsoleColor)object3);
            Assert.AreEqual(System.ConsoleColor.DarkBlue, (System.ConsoleColor)object4);
        }
开发者ID:rangab,项目名称:Magento-RestApi,代码行数:23,代码来源:EnumConverterTests.cs

示例5: ReadsCorrectly

        public void ReadsCorrectly()
        {
            // arrange
            var converter = new BoolConverter();
            var reader1 = new Moq.Mock<JsonReader>();
            reader1.SetupGet(x => x.Value).Returns(null);
            var reader2 = new Moq.Mock<JsonReader>();
            reader2.SetupGet(x => x.Value).Returns("0");
            var reader3 = new Moq.Mock<JsonReader>();
            reader3.SetupGet(x => x.Value).Returns("1");

            // act
            var object1 = converter.ReadJson(reader1.Object, typeof(bool), null, null);
            var object2 = converter.ReadJson(reader1.Object, typeof(bool?), null, null);
            var object3 = converter.ReadJson(reader2.Object, typeof(bool), null, null);
            var object4 = converter.ReadJson(reader3.Object, typeof(bool), null, null);

            // assert
            Assert.IsAssignableFrom<bool>(object1);
            Assert.IsFalse((bool)object1);
            Assert.IsNull(object2);
            Assert.IsFalse((bool)object3);
            Assert.IsTrue((bool)object4);
        }
开发者ID:ricvs,项目名称:Magento-RestApi,代码行数:24,代码来源:BoolConverterTests.cs

示例6: ProcessLimitsTest

        public void ProcessLimitsTest(
      string configurationName,
      SLimits limits, 
      bool logStatistic, 
      int apiUsageThreshold, 
      int dataStorageThreshold,
      Times[] result)
        {
            var mockedApiDailyRequestsLoger = new Moq.Mock<ILimitLoger>();
              if (limits != null)
              {
            var apiDailyRequestsLoger = new ApiDailyRequestsLoger(configurationName, limits.DailyApiRequests);
            mockedApiDailyRequestsLoger.SetupGet(p => p.UsedAmount).Returns(apiDailyRequestsLoger.UsedAmount);
            mockedApiDailyRequestsLoger.SetupGet(p => p.UsedPercents).Returns(apiDailyRequestsLoger.UsedPercents);
              }

              mockedApiDailyRequestsLoger.Setup(m => m.LogPointWarning()).Verifiable();
              mockedApiDailyRequestsLoger.Setup(m => m.LogHasReachedError()).Verifiable();

              var mockedDataStorageLoger = new Moq.Mock<ILimitLoger>();
              if (limits != null)
              {
            var dataStorageLoger = new ApiDailyRequestsLoger(configurationName, limits.DataStorageMb);
            mockedDataStorageLoger.SetupGet(p => p.UsedAmount).Returns(dataStorageLoger.UsedAmount);
            mockedDataStorageLoger.SetupGet(p => p.UsedPercents).Returns(dataStorageLoger.UsedPercents);
              }

              mockedDataStorageLoger.Setup(m => m.LogPointWarning()).Verifiable();
              mockedDataStorageLoger.Setup(m => m.LogHasReachedError()).Verifiable();

              var mockedLoger = new Moq.Mock<ILimitsLoger>();
              mockedLoger.SetupGet(p => p.ApiDailyRequestsLoger).Returns(mockedApiDailyRequestsLoger.Object);
              mockedLoger.SetupGet(p => p.DataStorageLoger).Returns(mockedDataStorageLoger.Object);
              mockedLoger.Setup(m => m.LogStatisticInfo()).Verifiable();
              mockedLoger.Setup(m => m.LogInformationAreNotAvailableWarning()).Verifiable();

              var agent = new LimitsAgent();
              agent.LogStatistic = logStatistic;
              agent.ApiUsageThreshold = apiUsageThreshold;
              agent.DataStorageThreshold = dataStorageThreshold;
              var logerField = typeof(LimitsAgent).GetField("loger", BindingFlags.Instance | BindingFlags.NonPublic);
              if (logerField != null)
              {
            logerField.SetValue(agent, mockedLoger.Object);
              }

              agent.ProcessLimits(limits);

              mockedLoger.Verify(m => m.LogStatisticInfo(), result[0]);
              mockedLoger.Verify(m => m.LogInformationAreNotAvailableWarning(), result[1]);
              mockedApiDailyRequestsLoger.Verify(m => m.LogPointWarning(), result[2]);
              mockedApiDailyRequestsLoger.Verify(m => m.LogHasReachedError(), result[3]);
              mockedDataStorageLoger.Verify(m => m.LogPointWarning(), result[4]);
              mockedDataStorageLoger.Verify(m => m.LogHasReachedError(), result[5]);
        }
开发者ID:clone278,项目名称:sitecore-salesforce-connect,代码行数:55,代码来源:LimitsAgentTests.cs

示例7: WithUserLogged

            public EventControllerBuilder WithUserLogged()
            {
                var httpContext = new Mock<HttpContext>();

                var controllerContext = new Mock<ControllerContext>();
                var principal = new Moq.Mock<ClaimsPrincipal>();


                principal.Setup(p => p.IsInRole("Administrator")).Returns(true);
                principal.SetupGet(x => x.Identity.Name).Returns("userName");

                httpContext.Setup(x => x.User).Returns(principal.Object);
                controllerContext.Object.HttpContext = httpContext.Object;
                _controllerContext = controllerContext.Object;

                return this;
            }
开发者ID:gftrader,项目名称:allReady,代码行数:17,代码来源:EventControllerTests.cs

示例8: SetupHttpAbstractionMocking

        internal MockResults SetupHttpAbstractionMocking()
        {
            var results = new MockResults();
            // Locate the test manager so we can override the lower layer.
            var manager = ServiceLocator.Instance.Locate<IServiceLocationIndividualTestManager>();

            // Create a Mock of the HTTP layer response.
            var moqResponse = new Moq.Mock<IHttpResponseMessageAbstraction>(MockBehavior.Loose);
            // Always return 200 OK
            moqResponse.SetupGet(res => res.StatusCode)
                       .Returns(HttpStatusCode.OK);

            // Create a mock of the Request client.
            var moqClient = new Moq.Mock<IHttpClientAbstraction>(MockBehavior.Loose);

            // Mock the return to set the request headers.
            moqClient.SetupGet(client => client.RequestHeaders)
                     .Returns(() => results.Headers);

            // Mock the return to set the request uri.
            moqClient.SetupGet(client => client.RequestUri)
                     .Returns(() => results.RequestUri);

            // Mock the return to set the request uri.
            moqClient.SetupSet(abstraction => abstraction.RequestUri = It.IsAny<Uri>()).Callback<Uri>(uri => results.RequestUri = uri);

            // Mock the return to set the http method.
            moqClient.SetupGet(client => client.Method)
                     .Returns(() => results.Method);

            // Mock the return to set the http method.
            moqClient.SetupSet(abstraction => abstraction.Method = It.IsAny<HttpMethod>()).Callback<HttpMethod>(method => results.Method = method);

            // Mock the return to set the content.
            moqClient.SetupGet(client => client.Content)
                     .Returns(() => results.Content);

            moqClient.SetupSet(abstraction => abstraction.Content = It.IsAny<HttpContent>()).Callback<HttpContent>(content => results.Content = content);

            // Mock the SendAsync method (to just return the response object previously created).
            moqClient.Setup(c => c.SendAsync())
                     .Returns(() => Task.Run(() =>
                     {
                         results.SendAsyncCalled = true;
                         return moqResponse.Object;
                     }));

            // Mock the factory to return our mock client.
            var moqFactory = new Moq.Mock<IHttpClientAbstractionFactory>();

            // Overload both create methods.
            moqFactory.Setup(fac => fac.Create(It.IsAny<X509Certificate2>(), It.IsAny<HDInsight.IAbstractionContext>(), false))
                      .Returns(() => moqClient.Object);
            moqFactory.Setup(fac => fac.Create(It.IsAny<HDInsight.IAbstractionContext>(), false))
                      .Returns(() => moqClient.Object);

            // Override the factory in the Service Locator (for this test only).
            manager.Override<IHttpClientAbstractionFactory>(moqFactory.Object);
           
            return results;
        }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:61,代码来源:RemoteHadoopRestLayer.cs


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