當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。