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


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

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: content_type

        public void content_type(string extension, string mimeType)
        {
            var fileInfo = new Moq.Mock<IFileInfo>();
            fileInfo.Setup(x => x.Extension).Returns(extension);
            fileInfo.Setup(x => x.OpenRead()).Returns(StreamWith("<this doesn't matter>"));
            ResponseFile = fileInfo.Object;

            WithResponseFrom("http://localhost:8080", response => {
                Verify.That(() => response.ContentType == mimeType);
            });
        }
开发者ID:drunkcod,项目名称:Concoct,代码行数:11,代码来源:FileHttpHandlerSpec.cs

示例7: EmptyImageReturnsEmptyPalette

            public void EmptyImageReturnsEmptyPalette()
            {
                var image = new Moq.Mock<IImage>();
                image.Setup(x => x.Height).Returns(0);
                image.Setup(x => x.Width).Returns(0);

                var p = new PercentagePaletteInventory
                    {
                        Image = image.Object
                    };
                Assert.AreEqual(0,p.Items.Count);
            }
开发者ID:hvalidi,项目名称:ColorMine,代码行数:12,代码来源:PercentagePaletteInventoryTest.cs

示例8: Init

        public void Init()
        {
            var lstValid = SearchResultGenerator();
            var lstReports = ReportListGenerator();
            var lstUsers = UserListGenerator();

            var y = new Moq.Mock<IReportHubDataRepository>();
            y.Setup(x => x.Search("validsearch")).Returns(lstValid);
            y.Setup(x => x.TopReports(5)).Returns(lstReports.AsEnumerable());
            y.Setup(x => x.TopUsers(5)).Returns(lstUsers.AsEnumerable());
            rhs = new ReportHubService(y.Object);
        }
开发者ID:SirPhobos,项目名称:RMM,代码行数:12,代码来源:ReportHubServiceTests.cs

示例9: Rename

 /// <summary>
 /// renaming helper method for mocking IMatrixData
 /// </summary>
 /// <param name="colnames"></param>
 /// <param name="pattern"></param>
 /// <param name="replacement"></param>
 private static void Rename(List<string> colnames, string pattern, string replacement)
 {
     var renamer = new RenameColumnsRegexp();
     var matrix = new Moq.Mock<IMatrixData>();
     matrix.Setup(m => m.ColumnCount).Returns(colnames.Count);
     matrix.Setup(m => m.ColumnNames).Returns(colnames);
     string err = "";
     var param = renamer.GetParameters(matrix.Object, ref err);
     param.GetParam<Tuple<Regex, string>>("Regex").Value = Tuple.Create(new Regex(pattern), replacement);
     IMatrixData[] supplTables = null;
     IDocumentData[] documents = null;
     renamer.ProcessData(matrix.Object, param, ref supplTables, ref documents, null);
 }
开发者ID:JurgenCox,项目名称:perseus-plugins,代码行数:19,代码来源:RenameColumnsRegexpTest.cs

示例10: ShouldGetAllLogFiles

        public void ShouldGetAllLogFiles()
        {
            var fileSystem = new Moq.Mock<IFileSystem>();
            var logFiles = new[] { @"C:\Path\backup-1234567890.csv" };
            var nonLogFiles = new[] { @"C:\Path\no-match.csv" };
            fileSystem.Setup(x => x.GetCommonApplicationDataPath()).Returns(@"C:\Path");
            fileSystem.Setup(x => x.GetFiles(@"C:\Path\cache\logs")).Returns(logFiles.Union(nonLogFiles));
            var target = new JungleDiskLogFilesProvider(fileSystem.Object, new AutomaticLogFilePath(fileSystem.Object));

            var result = target.GetAllLogFiles();

            result.Should().Have.SameSequenceAs(logFiles);
        }
开发者ID:MatteS75,项目名称:Qupla,代码行数:13,代码来源:JungleDiskLogFilesProviderSpec.cs

示例11: GetOutboundUrl

        private string GetOutboundUrl(object routeValues)
        {
            RouteCollection routes = new RouteCollection();
            RouteConfig.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("/");

            var ctx = new RequestContext(mockHttpContext.Object, new RouteData());
            return routes.GetVirtualPath(ctx, new RouteValueDictionary(routeValues)).VirtualPath;
        }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:14,代码来源:OutboundRoutingTests.cs

示例12: content_matches

        public void content_matches()
        {
            var message = "Hello World!";
            var fileInfo = new Moq.Mock<IFileInfo>();
            fileInfo.Setup(x => x.Extension).Returns(".bin");
            fileInfo.Setup(x => x.OpenRead()).Returns(StreamWith(message));
            ResponseFile = fileInfo.Object;

            WithResponseFrom("http://localhost:8080", response => {
                Verify.That(() => response.ContentLength == message.Length);
                using(var reader = new StreamReader(response.GetResponseStream()))
                    Verify.That(() => reader.ReadToEnd() == message);
            });
        }
开发者ID:drunkcod,项目名称:Concoct,代码行数:14,代码来源:FileHttpHandlerSpec.cs

示例13: RedImageReturnsRedPalette

            public void RedImageReturnsRedPalette()
            {
                var image = new Moq.Mock<IImage>();
                image.Setup(x => x.Width).Returns(1);
                image.Setup(x => x.Height).Returns(1);
                image.Setup(x => x.GetPixel(0,0)).Returns(Color.Red);

                var p = new PercentagePaletteInventory
                {
                    Image = image.Object
                };

                Assert.IsTrue(Math.Abs(p.Items[Color.Red] - 1) < Epsilon);
            }
开发者ID:hvalidi,项目名称:ColorMine,代码行数:14,代码来源:PercentagePaletteInventoryTest.cs

示例14: ContextMocks

 public ContextMocks(Controller onController)
 {
     HttpContext = new Moq.Mock<HttpContextBase>();
     Request = new Moq.Mock<HttpRequestBase>();
     Response = new Moq.Mock<HttpResponseBase>();
     HttpContext.Setup(x => x.Request).Returns(Request.Object);
     HttpContext.Setup(x => x.Response).Returns(Response.Object);
     HttpContext.Setup(x => x.Session).Returns(new FakeSessionState());
     Request.Setup(x => x.Cookies).Returns(new HttpCookieCollection());
     Response.Setup(x => x.Cookies).Returns(new HttpCookieCollection());
     Request.Setup(x => x.QueryString).Returns(new NameValueCollection());
     Request.Setup(x => x.Form).Returns(new NameValueCollection());
     RequestContext requestContext = new RequestContext(HttpContext.Object, new RouteData());
     onController.ControllerContext = new ControllerContext(requestContext, onController);
 }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:15,代码来源:ContextMocks.cs

示例15: 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


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