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


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

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


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

示例1: ActivateAd_ActivationTokenDoesNotWork_ReturnModelIsActivatedFalse

        public void ActivateAd_ActivationTokenDoesNotWork_ReturnModelIsActivatedFalse()
        {
            // Given
            BaseAd ad = new Ad()
            {
                IsActivated = false,
                ActivationToken = "AAA"
            };
            long adId = 78;

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<BaseAd>(adId)).Returns(ad);

            AdActivationServices service = new AdActivationServices(repoMock.Object, null, null, null);

            // When
            AdActivationResultModel model = service.ActivateAd(adId, "BBB");

            // Then
            Assert.IsFalse(model.IsActivated);
            Assert.AreEqual(78, model.AdId);
            Assert.AreEqual("Vous ne pouvez pas activer cette annonce.", model.InfoMessage);

            repoMock.Verify(x => x.Save(ad), Moq.Times.Never());
            repoMock.Verify(x => x.Save(Moq.It.IsAny<SearchAdCache>()), Moq.Times.Never());
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:26,代码来源:AdActivationServicesTest.cs

示例2: shouldHaveSynchronizeWithGoogleFunction

		public void shouldHaveSynchronizeWithGoogleFunction() {
			var avegaContactServiceMock = new Moq.Mock<IAvegaContactService>();
			avegaContactServiceMock.Setup(x => x.SynchronizeWithGoogleContact(It.IsAny<AvegaContact>()))
				.Returns(new SynchronizationStatus(true, false, false));

			var avetaContactService = avegaContactServiceMock.Object;
			avetaContactService.SynchronizeWithGoogleContact(new AvegaContact("MyContact"));

			avegaContactServiceMock.Verify();
		}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:10,代码来源:IAvegaContactServiceTest.cs

示例3: IObjectStateAsObjectReference

        public void IObjectStateAsObjectReference()
        {
            IObjectState o = null;
            Assert.That(o.AsObjectReference(), Is.Null);

            var m = new Moq.Mock<IObjectState>(MockBehavior.Strict);
            m.Setup(x => x.ObjectId).Returns(1);
            m.Setup(x => x.Name).Returns("X");

            var objRef = m.Object.AsObjectReference();
            Assert.IsNotNull(objRef);
            Assert.That(objRef.Value.Id, Is.EqualTo(1));
            Assert.That(objRef.Value.Name, Is.EqualTo("X"));
        }
开发者ID:andy-uq,项目名称:Echo,代码行数:14,代码来源:ObjectReferenceTests.cs

示例4: An_invalid_server_path_is_treated_as_a_script_and_arguments_ignored_if_local_path_that_cannot_be_found

        public void An_invalid_server_path_is_treated_as_a_script_and_arguments_ignored_if_local_path_that_cannot_be_found()
        {
            // Arrange
            var fakeTfsProvider = new Moq.Mock<IUtilitiesForPowerShellActivity>();
            fakeTfsProvider.Setup(f => f.IsServerItem(It.IsAny<string>())).Returns(false);
            fakeTfsProvider.Setup(f => f.FileExists(It.IsAny<string>())).Returns(false);

            var activity = new InvokePowerShellCommand(fakeTfsProvider.Object);

            // Act
            var actual = activity.ResolveScript(null, @"some powershell commands", "-myarg");

            // assert
            Assert.AreEqual(@"some powershell commands", actual);
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:15,代码来源:ResolvePowerShellScriptTests.cs

示例5: An_invalid_server_path_is_treated_as_a_filesystem_script_file_and_arguments_appended

        public void An_invalid_server_path_is_treated_as_a_filesystem_script_file_and_arguments_appended()
        {
            // Arrange
            var fakeTfsProvider = new Moq.Mock<IUtilitiesForPowerShellActivity>();
            fakeTfsProvider.Setup(f => f.IsServerItem(It.IsAny<string>())).Returns(false);
            fakeTfsProvider.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            var activity = new InvokePowerShellCommand(fakeTfsProvider.Object);

            // Act
            var actual = activity.ResolveScript(null, @"c:\localscript.ps1", "-myarg");

            // assert
            Assert.AreEqual(@"& 'c:\localscript.ps1' -myarg", actual);
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:15,代码来源:ResolvePowerShellScriptTests.cs

示例6: ContextMocks

        public ContextMocks(Controller controller)
        {
            //define context objects
            HttpContext = new Moq.Mock<HttpContextBase>();
            Request = new Mock<HttpRequestBase>();
            User = new Mock<IPrincipal>();

            HttpContext.Setup(x => x.Request).Returns(Request.Object);
            HttpContext.Setup(x => x.User).Returns(User.Object);
            //you would setup Response, Session, etc similarly with either mocks or fakes

            //apply context to controller
            RequestContext rc = new RequestContext(HttpContext.Object, new RouteData());
            controller.ControllerContext = new ControllerContext(rc, controller);
        }
开发者ID:sartracks,项目名称:SARTracks,代码行数:15,代码来源:ContextMocks.cs

示例7: Test_NormalViewModel

        public void Test_NormalViewModel()
        {
            ClearAll();

            IMvxViewModel outViewModel = new Test2ViewModel();

            var mockLocator = new Mock<IMvxViewModelLocator>();
            mockLocator.Setup(
                m => m.Load(It.IsAny<Type>(), It.IsAny<IMvxBundle>(), It.IsAny<IMvxBundle>()))
                       .Returns(() => outViewModel);

            var mockCollection = new Moq.Mock<IMvxViewModelLocatorCollection>();
            mockCollection.Setup(m => m.FindViewModelLocator(It.IsAny<MvxViewModelRequest>()))
                          .Returns(() => mockLocator.Object);

            Ioc.RegisterSingleton(mockCollection.Object);

            var parameters = new Dictionary<string, string> { { "foo", "bar" } };
            var request = new MvxViewModelRequest<Test2ViewModel>(new MvxBundle(parameters), null,
                                                                  MvxRequestedBy.UserAction);
            var state = new MvxBundle();
            var loader = new MvxViewModelLoader();
            var viewModel = loader.LoadViewModel(request, state);

            Assert.AreSame(outViewModel, viewModel);
            Assert.AreEqual(MvxRequestedBy.UserAction, viewModel.RequestedBy);
        }
开发者ID:talisqualis,项目名称:MvvmCross-Build,代码行数:27,代码来源:MvxViewModelLoaderTest.cs

示例8: AsteroidHasDifficulty

        public void AsteroidHasDifficulty()
        {
            var veldnium = new ItemInfo(ItemCode.Veldnium);
            var itemFactory = new Moq.Mock<IItemFactory>(MockBehavior.Strict);
            itemFactory.Setup(x => x.Build(ItemCode.Veldnium, It.IsAny<uint>()))
                .Returns<ItemCode, uint>((item, quantity) => new Item(veldnium, quantity));

            var mining = new MiningTask(itemFactory.Object) { };
            mining.SetParameters(new MineAsteroidParameters(_ship, _difficultAsteroid));

            var result = mining.Mine();
            Assert.That(result.Success, Is.True);
            Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.Pending));
            Assert.That(_difficultAsteroid.AmountRemaining, Is.EqualTo(1000));
            Assert.That(_ship.Tasks, Contains.Item(mining));

            result = mining.Mine();

            Assert.That(result.Success, Is.True);
            Assert.That(result.StatusCode, Is.EqualTo(ShipTask.StatusCode.Success));

            Assert.That(result.Ore.Quantity, Is.EqualTo(2));
            Assert.That(_difficultAsteroid.AmountRemaining, Is.EqualTo(998));
            _ship.Tasks.ShouldNotContain(mining);
        }
开发者ID:andy-uq,项目名称:Echo,代码行数:25,代码来源:MiningTests.cs

示例9: If_a_valid_server_path_that_cannot_be_found_locally_throws_exception

        public void If_a_valid_server_path_that_cannot_be_found_locally_throws_exception()
        {
            // Arrange
            var fakeTfsProvider = new Moq.Mock<IUtilitiesForPowerShellActivity>();
            fakeTfsProvider.Setup(f => f.IsServerItem(It.IsAny<string>())).Returns(true);
            fakeTfsProvider.Setup(f => f.GetLocalFilePathFromWorkspace(null, It.IsAny<string>())).Returns(@"c:\serverfile\script.ps1");
            fakeTfsProvider.Setup(f => f.FileExists(It.IsAny<string>())).Returns(false);

            var activity = new InvokePowerShellCommand(fakeTfsProvider.Object);

            // Act
            var actual = activity.ResolveScript(null, "$/Test Path/Not A Real Path", "-myarg");

            // assert
            // checked with attribute
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:16,代码来源:ResolvePowerShellScriptTests.cs

示例10: A_valid_server_path_generates_a_cmd_with_arguments

        public void A_valid_server_path_generates_a_cmd_with_arguments()
        {
            // Arrange
            var fakeTfsProvider = new Moq.Mock<IUtilitiesForPowerShellActivity>();
            fakeTfsProvider.Setup(f => f.IsServerItem(It.IsAny<string>())).Returns(true);
            fakeTfsProvider.Setup(f => f.GetLocalFilePathFromWorkspace(null, It.IsAny<string>())).Returns(@"c:\serverfile\script.ps1");
            fakeTfsProvider.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);

            var activity = new InvokePowerShellCommand(fakeTfsProvider.Object);

            // Act
            var actual = activity.ResolveScript(null, "$/Test Path/Not A Real Path", "-myarg");

            // assert
            Assert.AreEqual(@"& 'c:\serverfile\script.ps1' -myarg", actual);
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:16,代码来源:ResolvePowerShellScriptTests.cs

示例11: GetDataServiceMock

        private static IDataService GetDataServiceMock(List<Product> products)
        {
            var dataServiceMock = new Moq.Mock<IDataService>(MockBehavior.Strict);
            dataServiceMock.Setup(s => s.GetProductsByProductCode(It.IsAny<int>())).Returns(products);

            return dataServiceMock.Object;
        }
开发者ID:halcwb,项目名称:GenImport,代码行数:7,代码来源:WcfServiceShould.cs

示例12: AdvancedSearchAds_SearchThroughAds_CallSearchRepoOnAds

        public void AdvancedSearchAds_SearchThroughAds_CallSearchRepoOnAds()
        {
            // Given
            Category cat = new Category { Id = 1, LabelUrlPart = "cat-url-label", Label = "Label", Type = AdTypeEnum.Ad };

            AdSearchModel model = new AdSearchModel();
            model.CategorySelectedId = 1;
            model.SearchString = "toto";
            model.CitySelectedId = 12;

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "ship",
                City = new City() { Label = "the city" },
                Category = cat
            });

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var searchRepoMock = new Moq.Mock<ISearchRepository>();
            searchRepoMock.Setup(r => r.SearchAds(It.Is<String[]>(x => x[0] == "toto"), 12, It.Is<int[]>(x => x[0] == 1))).Returns(searchResult);

            SearchServices service = new SearchServices(repoMock.Object, null, searchRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.LightSearchAds(model);

            // Then
            Assert.AreEqual(1, result.SearchResultTotalCount);
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:32,代码来源:SearchServicesTest.cs

示例13: SetUp

        public void SetUp()
        {
            var mock = new Moq.Mock<ILocationServices>();
            mock.Setup(x => x.GetExitPosition(It.IsAny<ILocation>())).Returns<ILocation>(l => l.Position.LocalCoordinates);

            _task = new JumpShipTask(mock.Object);
        }
开发者ID:andy-uq,项目名称:Echo,代码行数:7,代码来源:JumpShipTaskTests.cs

示例14: ActivateAd_ActivationTokenWorks_ReturnModelIsActivatedTrueAndActivatesAd

        public void ActivateAd_ActivationTokenWorks_ReturnModelIsActivatedTrueAndActivatesAd()
        {
            // Given
            BaseAd ad = new Ad()
            {
                IsActivated = false,
                ActivationToken = "AAA",
                City = new City(),
                Category = new Category()
            };
            long adId = 78;

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<BaseAd>(adId)).Returns(ad);

            AdActivationServices service = new AdActivationServices(repoMock.Object, null, null, null);

            // When
            AdActivationResultModel model = service.ActivateAd(78, "AAA");

            // Then
            Assert.IsTrue(model.IsActivated);
            Assert.AreEqual(78, model.AdId);
            Assert.AreEqual("Merci d'avoir activé votre annonce.", model.InfoMessage);

            repoMock.Verify(x => x.Save(ad), Moq.Times.Once());
            repoMock.Verify(x => x.Save(Moq.It.IsAny<SearchAdCache>()), Moq.Times.Once());
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:28,代码来源:AdActivationServicesTest.cs

示例15: GetOutboundUrl

        string GetOutboundUrl(object routeValues)
        {
            // Get route configuration and mock request context
            RouteCollection routes = new RouteCollection();
            MvcApplication.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            var fakeResponse = new FakeResponse();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockHttpContext.Setup(x => x.Response).Returns(fakeResponse);
            mockRequest.Setup(x => x.ApplicationPath).Returns("/");

            // Generate the outbound URL
            var ctx = new RequestContext(mockHttpContext.Object, new RouteData());
            return routes.GetVirtualPath(ctx, new RouteValueDictionary(routeValues))
                .VirtualPath;
        }
开发者ID:benjito,项目名称:Projects,代码行数:17,代码来源:OutboundRoutingTests.cs


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