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


C# ViewEngineCollection.Add方法代码示例

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


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

示例1: FindPartialViewAggregatesAllSearchedLocationsIfAllEnginesFail

        public void FindPartialViewAggregatesAllSearchedLocationsIfAllEnginesFail()
        {
            // Arrange
            ControllerContext context = new Mock<ControllerContext>().Object;
            ViewEngineCollection viewEngineCollection = new ViewEngineCollection();
            Mock<IViewEngine> engine1 = new Mock<IViewEngine>();
            ViewEngineResult engine1Result = new ViewEngineResult(new[] { "location1", "location2" });
            engine1.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine1Result);
            Mock<IViewEngine> engine2 = new Mock<IViewEngine>();
            ViewEngineResult engine2Result = new ViewEngineResult(new[] { "location3", "location4" });
            engine2.Setup(e => e.FindPartialView(context, "partial", It.IsAny<bool>())).Returns(engine2Result);
            viewEngineCollection.Add(engine1.Object);
            viewEngineCollection.Add(engine2.Object);

            // Act
            ViewEngineResult result = viewEngineCollection.FindPartialView(context, "partial");

            // Assert
            Assert.Null(result.View);
            Assert.Equal(4, result.SearchedLocations.Count());
            Assert.True(result.SearchedLocations.Contains("location1"));
            Assert.True(result.SearchedLocations.Contains("location2"));
            Assert.True(result.SearchedLocations.Contains("location3"));
            Assert.True(result.SearchedLocations.Contains("location4"));
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:25,代码来源:ViewEngineCollectionTest.cs

示例2: ViewEngines

 static ViewEngines()
 {
     ViewEngineCollection engineCollection = new ViewEngineCollection();
       engineCollection.Add((IViewEngine) new WebFormViewEngine());
       engineCollection.Add((IViewEngine) new RazorViewEngine());
       ViewEngines._engines = engineCollection;
 }
开发者ID:jarrettmeyer,项目名称:resharper-settings,代码行数:7,代码来源:ViewEngines.cs

示例3: AsksEachViewEngineInTheOrderItWasCalled

        public void AsksEachViewEngineInTheOrderItWasCalled()
        {
            var redEngine = new Mock<IViewEngine>();
            var redResult = new ViewEngineResult(false, new[] { "Whatever"});
            redEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(redResult);

            var orangeEngine = new Mock<IViewEngine>();
            orangeEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns((ViewEngineResult)null);

            var blueEngine = new Mock<IViewEngine>();
            var blueResult = new ViewEngineResult(true, new string[0]);
            blueEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(blueResult);

            var greenEngine = new Mock<IViewEngine>();
            var greenResult = new ViewEngineResult(true, new string[0]);
            greenEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(greenResult);

            var collection = new ViewEngineCollection();
            collection.Add(redEngine.Object);
            collection.Add(orangeEngine.Object);
            collection.Add(blueEngine.Object);
            collection.Add(greenEngine.Object);
            var result = collection.FindView(RequestBuilder.CreateRequest().BuildControllerContext(), new ViewResultOptions(), "Foo");
            Assert.AreEqual(blueResult, result);
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:25,代码来源:ViewEngineCollectionTests.cs

示例4: RegisterViewEngines

 public static void RegisterViewEngines(ViewEngineCollection viewEngines)
 {
     viewEngines.Clear();
     viewEngines.Add(new RazorViewEngine());
     viewEngines.Add(new LoggingViewEngine.LoggingViewEngine());
     viewEngines.Add(new PdfViewEngine.PdfViewEngine());
     viewEngines.Add(new MailerViewEngine.MailerViewEngine());
 }
开发者ID:GroM,项目名称:Shaver,代码行数:8,代码来源:Global.asax.cs

示例5: CreateDefaults

        /// <summary>
        /// Creates the default view engines.
        /// </summary>
        /// <param name="viewActivator">The view activator.</param>
        /// <returns></returns>
        public static ViewEngineCollection CreateDefaults(IViewActivator viewActivator)
        {
            viewActivator = viewActivator ?? new DefaultViewActivator();

            var engines = new ViewEngineCollection();
            engines.Add(new PageViewEngine(viewActivator));
            engines.Add(new ChildWindowViewEngine(viewActivator));
            return engines;
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:14,代码来源:ViewEngines.cs

示例6: Send

        public void Send(string content)
        {
            _smtpClient = new SmtpClient(Address, Port);
            _smtpClient.Credentials = new NetworkCredential(Account, Password);
            _smtpClient.EnableSsl = false;
            MailMessage mailMessage = new MailMessage();
            mailMessage.BodyEncoding = Encoding.UTF8;
            mailMessage.From = new MailAddress(From, SenderName, Encoding.UTF8);
            mailMessage.To.Add(To);
            mailMessage.Body = content;
            mailMessage.Subject = Subject;
            _smtpClient.Send(mailMessage);


            dynamic email = new Email("Example");
            email.To = "[email protected]";
            email.Send();


            var viewsPath = Path.GetFullPath(@"..\..\Views");

            var engines = new ViewEngineCollection();
            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var service = new EmailService(engines);
            dynamic email = new Email("Test");

            // Will look for Test.cshtml or Test.vbhtml in Views directory.
            email.Message = "Hello, non-asp.net world!";
            service.Send(email);
           // RESTORE DATABASE is terminating abnormally.
        }
开发者ID:ilkerhalil,项目名称:ZiylanEtl,代码行数:32,代码来源:Mailer.cs

示例7: RegisterViewEngines

        public static void RegisterViewEngines(ViewEngineCollection viewEngines)
        {
            viewEngines.Clear();

            var lightweightRazorViewEngine = new LightweightRazorViewEngine();
            viewEngines.Add(lightweightRazorViewEngine);
        }
开发者ID:vassildinev,项目名称:Smart-Connect,代码行数:7,代码来源:ViewEnginesConfig.cs

示例8: NotifyNewComment

        public static void NotifyNewComment(int commentId)
        {
            var currentCultureName = Thread.CurrentThread.CurrentCulture.Name;
            if (currentCultureName != "es-ES")
            {
                throw new InvalidOperationException(String.Format("Current culture is {0}", currentCultureName));
            }

            // Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines = new ViewEngineCollection();
            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var emailService = new EmailService(engines);

            // Get comment and send a notification.
            using (var db = new MailerDbContext())
            {
                var comment = db.Comments.Find(commentId);

                var email = new NewCommentEmail
                {
                    To = "[email protected]",
                    UserName = comment.UserName,
                    Comment = comment.Text
                };

                emailService.Send(email);
            }
        }
开发者ID:TSalaam,项目名称:Hangfire.Mailer,代码行数:30,代码来源:HomeController.cs

示例9: RegisterViewEngine

        public static void RegisterViewEngine(ViewEngineCollection engines)
        {
            var sparkSettings = new SparkSettings();

            sparkSettings
                .AddNamespace("System")
                .AddNamespace("System.Collections.Generic")
                .AddNamespace("System.Linq")
                .AddNamespace("System.Web.Mvc")
                .AddNamespace("System.Web.Mvc.Html");

            sparkSettings
                .AddAssembly("Spark.Web.Mvc")
                .AddAssembly("System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35")
                .AddAssembly("System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            var builder = new DefaultDescriptorBuilder();
            builder.Filters.Add(new AreaDescriptorFilter());

            var container = SparkEngineStarter.CreateContainer(sparkSettings);
            container.SetServiceBuilder<Spark.Web.Mvc.IDescriptorBuilder>(c => builder);
            SparkEngineStarter.RegisterViewEngine(container);

            engines.Add(new SparkViewFactory(sparkSettings));
        }
开发者ID:sllabres,项目名称:WebGlPlayGround,代码行数:25,代码来源:Global.asax.cs

示例10: RegisterViewEngines

 public static void RegisterViewEngines(ViewEngineCollection viewEngines)
 {
     // 清除所有 View Engine
     viewEngines.Clear();
     // 重新註冊 RazorViewEngine,如果你使用的是 WebForm ViewEngine 則是加入 WebFormViewEngine
     viewEngines.Add(new RazorViewEngine());
 }
开发者ID:ian90911,项目名称:MVCClass_HW_20150704_CustomerMaintain,代码行数:7,代码来源:ViewEngineConfig.cs

示例11: RegisterViewEngines

        public void RegisterViewEngines(ViewEngineCollection engines)
        {
            var sparkViewFactory = new SubFolderSupportedSparkViewFactory();
            sparkViewFactory.AddSubDirectoryViewLocation("PartialViews");

            engines.Add(sparkViewFactory);
        }
开发者ID:BenHall,项目名称:SparkViewsInSubDirectories,代码行数:7,代码来源:Application.cs

示例12: RegisterEngines

        public static void RegisterEngines(ViewEngineCollection viewEngines)
        {
            // Removes WebForms view engine - optimization
            viewEngines.Clear();

            // viewEngines.Add(new CustomViewLocationRazorViewEngine());
            viewEngines.Add(new RazorViewEngine());
        }
开发者ID:mpenchev86,项目名称:ASP.NET-MVC-FinalProject,代码行数:8,代码来源:ViewEnginesConfig.cs

示例13: RegisterViewEngine

        public static void RegisterViewEngine(ViewEngineCollection viewEngines)
        {
            viewEngines.Clear();

            var PMIViewEngine = new PMIViewEngine();

            viewEngines.Add(PMIViewEngine);
        }
开发者ID:fekaputra,项目名称:pmi,代码行数:8,代码来源:Global.asax.cs

示例14: AddNullViewEngineThrows

        public void AddNullViewEngineThrows()
        {
            // Arrange
            ViewEngineCollection collection = new ViewEngineCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { collection.Add(null); },
                "item");
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:10,代码来源:ViewEngineCollectionTest.cs

示例15: CombinesAllErrorsWhenResultIsNotFound

        public void CombinesAllErrorsWhenResultIsNotFound()
        {
            var redEngine = new Mock<IViewEngine>();
            var redResult = new ViewEngineResult(false, new[] { "red whatever" });
            redEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(redResult);

            var blueEngine = new Mock<IViewEngine>();
            var blueResult = new ViewEngineResult(false, new[] { "blue whatever" });
            blueEngine.Setup(x => x.FindView(It.IsAny<ControllerContext>(), It.IsAny<ViewResultOptions>(), It.IsAny<string>())).Returns(blueResult);

            var collection = new ViewEngineCollection();
            collection.Add(redEngine.Object);
            collection.Add(blueEngine.Object);
            var result = collection.FindView(RequestBuilder.CreateRequest().BuildControllerContext(), new ViewResultOptions(), "Foo");
            Assert.IsFalse(result.Success);
            Assert.AreEqual(2, result.SearchLocations.Count());
            Assert.AreEqual("red whatever", result.SearchLocations.ElementAt(0));
            Assert.AreEqual("blue whatever", result.SearchLocations.ElementAt(1));
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:19,代码来源:ViewEngineCollectionTests.cs


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