• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Moq.Mock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Test_CtorWithAd

        public void Test_CtorWithAd()
        {
            // Given
            SailingBoatAd ad = new SailingBoatAd
            {
                Title = "title",
                SailingBoatType = new Bea.Domain.Reference.SailingBoatType { Label = "type" },
                HullType = new Bea.Domain.Reference.SailingBoatHullType { Label = "hull" },
                Year = 2012,
                Length = 15.75000,
                City = new City(),
                CreatedBy = new User()
            };

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(x => x.GetCulture()).Returns(new System.Globalization.CultureInfo("Fr"));

            // When
            SailingBoatAdDetailsModel actual = new SailingBoatAdDetailsModel(ad, helperMock.Object);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(ad.SailingBoatType.Label, actual.BoatType);
            Assert.AreEqual(ad.HullType.Label, actual.HullType);
            Assert.AreEqual(ad.Year, actual.Year);
            Assert.AreEqual("15,75 Mtr", actual.Length);
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:27,代码来源:SailingBoatAdDetailsModelTest.cs


示例2: tewwet

        public void tewwet()
        {
            var productRepository = new Moq.Mock<IProductRepository>();
            productRepository.Setup(x => x.Get())
                             .Returns(new[]
                                          {
                                              new Product()
                                                  {
                                                      ID = 1,
                                                      Title = "iPad",
                                                      Description = "Fruit based tablet",
                                                      UnitPrice = 450
                                                  },
                                              new Product()
                                                  {
                                                      ID = 2,
                                                      Title = "iPhone",
                                                      Description = "Fruit based phone",
                                                      UnitPrice = 500
                                                  }
                                          });

            var homeController = new HomeController(productRepository.Object);

            var result = homeController.Index() as ViewResult;

            Assert.NotNull(result.Model);
        }
开发者ID:jchannon,项目名称:EntityFrameworkMVC,代码行数:28,代码来源:HomeControllerTests.cs


示例3: Can_Remove_Product_From_Cart

        public void Can_Remove_Product_From_Cart()
        {
            // Arrange: Set up a mock repository with two products
            var mockProductsRepos = new Moq.Mock<IProductsRepository>();
            var products = new System.Collections.Generic.List<Product> {
            new Product { ProductID = 14, Name = "Much Ado About Nothing" },
            new Product { ProductID = 27, Name = "The Comedy of Errors" },
            };
            mockProductsRepos.Setup(x => x.Products)
                         .Returns(products.AsQueryable());
            var cart = new Cart();
            cart.AddItem(products[1], 2); // 2x Comedy of Errors
            cart.AddItem(products[0], 3); // 3x Much Ado
            var controller = new CartController(mockProductsRepos.Object, null);

            // Act: Try removing Much Ado
            RedirectToRouteResult result =
            controller.RemoveFromCart(cart, 14, "someReturnUrl");

            // Assert
            Assert.AreEqual(1, cart.Lines.Count);
            Assert.AreEqual("The Comedy of Errors", cart.Lines[0].Product.Name);
            Assert.AreEqual(2, cart.Lines[0].Quantity);

            // Check that the visitor was redirected to the cart display screen
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
        }
开发者ID:benjito,项目名称:Projects,代码行数:28,代码来源:CartControllerTests.cs


示例4: Initialize

            public static void Initialize()
            {
                IAccountRepository accRepo = new Moq.Mock<IAccountRepository>().Object;
                ISessionRepository sessionRepo = new Moq.Mock<ISessionRepository>().Object;
                IPOSSettingRepository posSettingRepo = new Moq.Mock<IPOSSettingRepository>().Object;
                Moq.Mock<IProductRepository> productRepo = new Moq.Mock<IProductRepository>();
                product_1 = new Product(Guid.NewGuid(), "Product ABC", "001", "001", 2000);
                productRepo.Setup(i => i.GetByBarcodeOrCode("001")).Returns(product_1);

                Moq.Mock<ICompanyProfileRepository> cpRepo = new Moq.Mock<ICompanyProfileRepository>();
                cpRepo.Setup(i => i.Get()).Returns(new CompanyProfile("[email protected]", "123", "Toko Dny", "Diamond Palace", null));

                AutoNumber autoNumber = new AutoNumber("[email protected]", "123", DateTime.Now);
                Moq.Mock<IAutoNumberRepository> autoNumberRepo = new Moq.Mock<IAutoNumberRepository>();
                autoNumberRepo.Setup(i => i.Get(DateTime.Now)).Returns(autoNumber);

                var sessionHolder = new SessionHolder();
                ObjectFactory.Initialize(i =>
                {
                    i.For<IAccountRepository>().Use(accRepo);
                    i.For<ISessionRepository>().Use(sessionRepo);
                    i.For<ICompanyProfileRepository>().Use(cpRepo.Object);
                    i.For<SessionService>().Use<SessionService>();
                    i.For<ShoppingCartService>().Use<ShoppingCartService>();
                    i.ForSingletonOf<SessionHolder>().Use<SessionHolder>();
                    i.For<IProductRepository>().Use(productRepo.Object);
                    i.For<IPOSSettingRepository>().Use(posSettingRepo);
                    i.ForSingletonOf<SessionHolder>().Use(sessionHolder);
                    i.ForSingletonOf<IShoppingCartSingleton>().Use(sessionHolder);
                    i.For<IAutoNumberRepository>().Use(autoNumberRepo.Object);
                    i.For<AutoNumberGenerator>().Use<AutoNumberGenerator>();
                });
            }
开发者ID:njmube,项目名称:SIQPOS,代码行数:33,代码来源:TestBase.cs


示例5: CreateCartController

        ShoppingCart.Web.Mvc.Controllers.CartController CreateCartController()
        {
            var mock = new Moq.Mock<ControllerContext>();

            var cartRepository = new Services.MockCartRepository();
            var cartService = new ShoppingCart.Web.Mvc.Services.CartService(cartRepository);

            var product = new Moq.Mock<Model.IProduct>();
            product.Setup(i => i.Code).Returns("xxx");
            product.Setup(i => i.Packaging).Returns(1);
            product.Setup(i => i.SaleUnitValue).Returns(1);
            product.Setup(i => i.Title).Returns("product 1");

            var catalogService = new Moq.Mock<Mvc.Services.ICatalogService>();
            catalogService.Setup(i => i.GetProductByCode("xxx")).Returns(product.Object);
            catalogService.Setup(i => i.GetPriceByProduct(product.Object)).Returns(new ShoppingCart.Web.Mvc.Model.Price(10.0, 0.196));

            var controller = new ShoppingCart.Web.Mvc.Controllers.CartController(
                cartService,
                catalogService.Object);

            controller.ControllerContext = mock.Object;

            return controller;
        }
开发者ID:adrianrm03,项目名称:openshoppingcart,代码行数:25,代码来源:CartControllerTests.cs


示例6: AddJob_Stores_the_Given_Job

        public void AddJob_Stores_the_Given_Job()
        {
            var job = new Moq.Mock<IJob>();
            _testObject.AddJob(job.Object);

            Assert.IsTrue(_testObject.GetJobs().Contains(job.Object));
        }
开发者ID:jmloeffler,项目名称:distRest,代码行数:7,代码来源:JobRepositoryTest.cs


示例7: SpamRequestAd_AdExists_SaveSpamRequest

        public void SpamRequestAd_AdExists_SaveSpamRequest()
        {
            // Given
            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(x => x.CanDeleteAd(7)).Returns(true);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<SpamAdType>(3)).Returns(new SpamAdType() { Id = 3 });

            var hSMock = new Moq.Mock<IHelperService>();
            hSMock.Setup(x => x.GetCurrentDateTime()).Returns(new DateTime(2013, 05, 17, 6, 7, 22));

            SpamAdRequestModel model = new SpamAdRequestModel();
            model.AdId = 7;
            model.Description = "description";
            model.RequestorEmail = "[email protected]";
            model.SelectedSpamAdTypeId = 3;

            SpamAdServices service = new SpamAdServices(adRepoMock.Object, repoMock.Object, hSMock.Object);

            // When
            SpamAdRequestModel result = service.SpamRequestAd(model);

            // Then
            Assert.IsFalse(result.CanSignal);
            Assert.AreEqual("Votre signalement a correctement été transmis. Merci de votre précieuse aide dans la chasse aux mauvaises annonces !", result.InfoMessage);

            repoMock.Verify(x => x.Save(Moq.It.Is<SpamAdRequest>(b =>
                b.Description == model.Description
                && b.RequestDate == new DateTime(2013, 05, 17, 6, 7, 22)
                && b.RequestorEmailAddress == model.RequestorEmail
                && b.SpamType.Id == 3)));
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:33,代码来源:SpamAdServicesTest.cs


示例8: AddColumn_Adds_New_Column_When_Cols_And_Rows_Do_Exist

        public void AddColumn_Adds_New_Column_When_Cols_And_Rows_Do_Exist(string colName, Type colType, string[] colNames, Type[] colTypes)
        {
            //Arrange
            int rowCount = 2;
            var mockNet = new Moq.Mock<INetwork>();
            var table = new DataAttributeTable<IEdge>();
            table.Network = mockNet.Object;
            for (int i = 0; i < colNames.Length; i++)
                table.Columns.Add(colNames[i], colTypes[i]);

            DataRow row = table.NewRow();
            table.Rows.Add(row);
            row = table.NewRow();
            table.Rows.Add(row);

            Assert.Equal(table.Columns.Count, colNames.Length);

            int index = colNames.Length;

            //Act
            table.AddColumn(colName, colType);

            //Assert
            Assert.Equal(table.Columns.Count, colNames.Length + 1);
            Assert.Equal(table.Columns[index].ColumnName, colName);
            Assert.Equal(table.Columns[index].DataType, colType);
            Assert.Equal(table.Rows.Count, rowCount);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:28,代码来源:DataAttributeTable_Of_IEdge_Fixture.cs


示例9: ConcreteFactLookup_GlobalFact

        public void ConcreteFactLookup_GlobalFact()
        {
            var facts = new List<ConcreteFact>();
            facts.Add(new ConcreteFact() { ProductId = 2, GeographyId = 2, SalesComponentId = 2, TimeId = 1, Value = 100 });
            facts.Add(new ConcreteFact() { ProductId = 3, GeographyId = 3, SalesComponentId = 3, TimeId = 1, Value = 100 });

            var products = new Moq.Mock<IHierarchy>();
            var geographies = new Moq.Mock<IHierarchy>();
            var causals = new Moq.Mock<IHierarchy>();
            var periods = new Moq.Mock<IHierarchy>();

            Expression<Func<IHierarchy, IEnumerable<short>>> anyInt = p => p.GetChildren(Moq.It.IsAny<short>());
            var result = new List<short> { 2, 3 };
            products.Setup(anyInt).Returns(result);
            geographies.Setup(anyInt).Returns(result);
            causals.Setup(anyInt).Returns(result);
            periods.Setup(anyInt).Returns(result);

            Expression<Func<IHierarchy, bool>> relation = h => h.RelationExists(Moq.It.IsAny<short>(), Moq.It.IsAny<short>());
            products.Setup(relation).Returns(true);
            geographies.Setup(relation).Returns(true);
            causals.Setup(relation).Returns(true);
            periods.Setup(relation).Returns(true);

            //, Hierarchy products, Hierarchy geographies, Hierarchy causals, Hierarchy periods

            var lookup = new ConcreteFactLookup(facts, products.Object, geographies.Object, causals.Object, periods.Object);

            Assert.AreEqual(200, lookup.SumChildren(1, 1, 1, 1));
        }
开发者ID:hfortegcmlp,项目名称:CalculatorTest,代码行数:30,代码来源:ConcreteFactLookup_Tests.cs


示例10: TestSimple_2

        public void TestSimple_2()
        {
            var facts = new List<NullableFact>();
            facts.Add(new NullableFact() { ProductId = null, GeographyId = null, SalesComponentId = null, TimeId = 1, Value = 100 });

            var products = new Moq.Mock<IHierarchy>();
            var geographies = new Moq.Mock<IHierarchy>();
            var causals = new Moq.Mock<IHierarchy>();
            var periods = new Moq.Mock<IHierarchy>();

            Expression<Func<IHierarchy, IEnumerable<short>>> anyInt = p => p.GetParents(Moq.It.IsAny<short>());
            var result = new List<short> { 1 };
            products.Setup(anyInt).Returns(result);
            geographies.Setup(anyInt).Returns(result);
            causals.Setup(anyInt).Returns(result);
            periods.Setup(anyInt).Returns(result);

            Expression<Func<IHierarchy, bool>> allRelationships = p => p.RelationExists(Moq.It.IsAny<short>(), Moq.It.IsAny<short>());
            products.Setup(allRelationships).Returns(true);
            geographies.Setup(allRelationships).Returns(true);
            causals.Setup(allRelationships).Returns(true);
            periods.Setup(allRelationships).Returns(true);

            //, Hierarchy products, Hierarchy geographies, Hierarchy causals, Hierarchy periods

            var lookup = new FactLookup(facts, products.Object, geographies.Object, causals.Object, periods.Object);

            Assert.AreEqual(100, lookup.GetParent(0, 0, 0, 1));
            Assert.AreEqual(100, lookup.GetParent(1, 1, 1, 1));
            Assert.AreEqual(100, lookup.GetParent(2, 2, 2, 1));
        }
开发者ID:hfortegcmlp,项目名称:CalculatorTest,代码行数:31,代码来源:FactLookup_ParentTests.cs


示例11: Produces_Home_Plus_NaLink_Object_For_Each_Distinct_Category

        public void Produces_Home_Plus_NaLink_Object_For_Each_Distinct_Category()
        {
            // Подготовка
            IQueryable<Product> products = new[] {
                new Product { Name="A", Category="Animal" },
                new Product { Name="B", Category="Vegetable" },
                new Product { Name="C", Category="Mineral" },
                new Product { Name="D", Category="Vegetable" },
                new Product { Name="E",Category="Animal" }
            }.AsQueryable();
            var mockProductRepository = new Moq.Mock<IProductsRepository>();
            mockProductRepository.Setup(x => x.Products).Returns(products);
            var controller = new NavController(mockProductRepository.Object);

            // Действие
            ViewResult result = controller.Menu(null);

            var links = ((IEnumerable<NavLink>)result.ViewData.Model).ToList();
            Assert.AreEqual(4, links.Count);
            Assert.AreEqual("All", links[0].Text);
            Assert.AreEqual("Animal", links[1].Text);
            Assert.AreEqual("Mineral", links[2].Text);
            Assert.AreEqual("Vegetable", links[3].Text);
            foreach(var link in links)
            {
                Assert.AreEqual("Products", link.RouteValues["controller"]);
                Assert.AreEqual("List", link.RouteValues["action"]);
                Assert.AreEqual(1, link.RouteValues["page"]);
                if (links.IndexOf(link) == 0)
                    Assert.IsNull(link.RouteValues["category"]);
                else
                    Assert.AreEqual(link.Text, link.RouteValues["category"]);
            }
        }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:34,代码来源:NavControllerTests.cs


示例12: GetAdPicturesFromModel_2Pictures_FetchThemFromRepoAndSetFirstAsMainImage

        public void GetAdPicturesFromModel_2Pictures_FetchThemFromRepoAndSetFirstAsMainImage()
        {
            // Given
            BaseAd ad = new Ad();
            String images = "b9da8b1e-aa77-401b-84e0-a1290130b7b7;b9da8b1e-aa77-401b-84e0-a1290130b999;";

            AdImage img1 = new AdImage() { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7") };
            AdImage img2 = new AdImage() { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b999") };

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<AdImage>(Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7"))).Returns(img1);
            repoMock.Setup(x => x.Get<AdImage>(Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b999"))).Returns(img2);

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

            // When
            BaseAd result = service.GetAdPicturesFromModel(ad, images);

            // Then
            Assert.AreEqual(ad, result);
            Assert.AreEqual(2, ad.Images.Count);
            Assert.AreEqual("b9da8b1e-aa77-401b-84e0-a1290130b7b7", ad.Images[0].Id.ToString());
            Assert.AreEqual(ad, ad.Images[0].BaseAd);
            Assert.IsTrue(ad.Images[0].IsPrimary);
            Assert.AreEqual("b9da8b1e-aa77-401b-84e0-a1290130b999", ad.Images[1].Id.ToString());
            Assert.AreEqual(ad, ad.Images[1].BaseAd);
            Assert.IsFalse(ad.Images[1].IsPrimary);
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:28,代码来源:AdServicesTest.cs


示例13: GetAdDetails_AdExists_GetAdFromRepoAndReturnAdModel

        public void GetAdDetails_AdExists_GetAdFromRepoAndReturnAdModel()
        {
            // Given
            Ad ad = new Ad() { Id = 17 };
            ad.CreationDate = new DateTime(2012, 02, 18);
            ad.CreatedBy = new User { Firstname = "Michel" };
            ad.City = new City { Label = "Ville" };

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

            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(r => r.GetAdType(17)).Returns(AdTypeEnum.Ad);
            adRepoMock.Setup(r => r.GetAdById<Ad>(17)).Returns(ad);

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(s => s.GetCurrentDateTime()).Returns(new DateTime(2012, 02, 20));

            AdDetailsServices service = new AdDetailsServices(adRepoMock.Object, helperMock.Object);

            // When
            AdDetailsModel actual = service.GetAdDetails(17);

            // Then
            Assert.AreEqual(17, actual.AdId);
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:26,代码来源:AdDetailsServicesTest.cs


示例14: Setup

		public void Setup()
		{
			var library = new Moq.Mock<CollectionSettings>();
			library.SetupGet(x => x.IsSourceCollection).Returns(false);
			library.SetupGet(x => x.Language2Iso639Code).Returns("en");
			library.SetupGet(x => x.Language1Iso639Code).Returns("xyz");
			library.SetupGet(x => x.XMatterPackName).Returns("Factory");

			ErrorReport.IsOkToInteractWithUser = false;
			_fileLocator = new FileLocator(new string[]
											{
												//FileLocator.GetDirectoryDistributedWithApplication( "factoryCollections"),
												BloomFileLocator.GetFactoryBookTemplateDirectory("Basic Book"),
												BloomFileLocator.GetFactoryBookTemplateDirectory("Wall Calendar"),
												FileLocator.GetDirectoryDistributedWithApplication( BloomFileLocator.BrowserRoot),
												BloomFileLocator.GetBrowserDirectory("bookLayout"),
												BloomFileLocator.GetBrowserDirectory("bookEdit","css"),
												BloomFileLocator.GetInstalledXMatterDirectory()
											});

			var projectFolder = new TemporaryFolder("BookStarterTests_ProjectCollection");
			var collectionSettings = new CollectionSettings(Path.Combine(projectFolder.Path, "test.bloomCollection"));

			_starter = new BookStarter(_fileLocator, dir => new BookStorage(dir, _fileLocator, new BookRenamedEvent(), collectionSettings), library.Object);
			_shellCollectionFolder = new TemporaryFolder("BookStarterTests_ShellCollection");
			_libraryFolder = new TemporaryFolder("BookStarterTests_LibraryCollection");
		}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:27,代码来源:ConfiguratorTest.cs


示例15: Can_Remove_Product_From_Cart

        public void Can_Remove_Product_From_Cart()
        {
            // Подготовка
            var mockProductsRepository = new Moq.Mock<IProductsRepository>();
            var products = new List<Product>()
            {
                new Product {ProductID=14, Name="Much Ado About Nothing" },
                new Product {ProductID=27, Name="The Comedy of Errors" }
            };
            mockProductsRepository.Setup(x => x.Products)
                                  .Returns(products.AsQueryable());
            var cart = new Cart();
            var controller = new CartController(mockProductsRepository.Object, null);
            controller.AddToCart(cart, 14, "someReturnUrl");
            controller.AddToCart(cart, 27, "someReturnUrl");
            Assert.AreEqual(2, cart.Lines.Count);
            // Действие
            RedirectToRouteResult result =
                controller.RemoveFromCart(cart, 14, "someReturnUrl");
            // Утверждение
            Assert.AreEqual(1, cart.Lines.Count);
            Assert.AreEqual(27, cart.Lines[0].Product.ProductID);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
        }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:26,代码来源:CartControllerTests.cs


示例16: MakeMockRuleProvider

 private static IRulesProvider MakeMockRuleProvider(Type forModelType, params string[] rulePropertyNames)
 {
     var ruleset = new RuleSet(rulePropertyNames.ToLookup(x => x, x => (Rule)new RequiredRule()));
     var mockProvider = new Moq.Mock<IRulesProvider>();
     mockProvider.Expect(x => x.GetRulesFromType(forModelType)).Returns(ruleset);
     return mockProvider.Object;
 }
开发者ID:chakrit,项目名称:xVal-mirror,代码行数:7,代码来源:ActiveRuleProvidersTests.cs


示例17: TestRoute

        private void TestRoute(string url, object expectedValues)
        {
            // Arrange: Prepare the route collection and a mock request context
            RouteCollection routes = new RouteCollection();
            MvcApplication.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockRequest.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns(url);

            // Act: Get the mapped route
            RouteData routeData = routes.GetRouteData(mockHttpContext.Object);

            // Assert: Test the route values against expectations
            Assert.IsNotNull(routeData);
            var expectedDict = new RouteValueDictionary(expectedValues);
            foreach (var expectedVal in expectedDict)
            {
                if (expectedVal.Value == null)
                    Assert.IsNull(routeData.Values[expectedVal.Key]);
                else
                    Assert.AreEqual(expectedVal.Value.ToString(),
                                    routeData.Values[expectedVal.Key].ToString());
            }
        }
开发者ID:benjito,项目名称:Projects,代码行数:25,代码来源:InboundRoutingTests.cs


示例18: TestRoute

        private void TestRoute(string url, object expectedValues)
        {
            // Подготовка
            RouteCollection routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockRequest.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns(url);

            // Действие
            RouteData routeData = routes.GetRouteData(mockHttpContext.Object);

            // Утверждение
            Assert.IsNotNull(routeData);
            var expectedDist = new RouteValueDictionary(expectedValues);
            foreach (var expectedVal in expectedDist)
            {
                if (expectedVal.Value == null)
                    Assert.IsNull(routeData.Values[expectedVal.Key]);
                else
                    Assert.AreEqual(expectedVal.Value.ToString(),
                                    routeData.Values[expectedVal.Key].ToString());
            }
        }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:25,代码来源:InboundRoutingTests.cs


示例19: Setup_the_SUT

        void Setup_the_SUT()
        {
            DomainEventPublisherMock = new Moq.Mock<IPublishDomainEvents>(Moq.MockBehavior.Loose);

            State = new ProductState(DomainEventPublisherMock.Object);

            SUT = new Product(State);
        }
开发者ID:rmoorman,项目名称:SaasOvation,代码行数:8,代码来源:Manipulating_an_issue.cs


示例20: SetBuildValidationServiceSomethingElseTest

        public void SetBuildValidationServiceSomethingElseTest()
        {
            Moq.Mock<IValidationService> mockService = new Moq.Mock<IValidationService>();

            Factories.BuildValidationService = () => mockService.Object;
            var actual = Factories.BuildValidationService();
            Assert.AreEqual(mockService.Object, actual);
        }
开发者ID:flobacher,项目名称:unobtrusive-angular-validation,代码行数:8,代码来源:FactoriesTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MosaMethod类代码示例发布时间:2022-05-24
下一篇:
C# MoonSharp类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap