本文整理汇总了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"));
}
示例2: ViewEngines
static ViewEngines()
{
ViewEngineCollection engineCollection = new ViewEngineCollection();
engineCollection.Add((IViewEngine) new WebFormViewEngine());
engineCollection.Add((IViewEngine) new RazorViewEngine());
ViewEngines._engines = engineCollection;
}
示例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);
}
示例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());
}
示例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;
}
示例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.
}
示例7: RegisterViewEngines
public static void RegisterViewEngines(ViewEngineCollection viewEngines)
{
viewEngines.Clear();
var lightweightRazorViewEngine = new LightweightRazorViewEngine();
viewEngines.Add(lightweightRazorViewEngine);
}
示例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);
}
}
示例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));
}
示例10: RegisterViewEngines
public static void RegisterViewEngines(ViewEngineCollection viewEngines)
{
// 清除所有 View Engine
viewEngines.Clear();
// 重新註冊 RazorViewEngine,如果你使用的是 WebForm ViewEngine 則是加入 WebFormViewEngine
viewEngines.Add(new RazorViewEngine());
}
示例11: RegisterViewEngines
public void RegisterViewEngines(ViewEngineCollection engines)
{
var sparkViewFactory = new SubFolderSupportedSparkViewFactory();
sparkViewFactory.AddSubDirectoryViewLocation("PartialViews");
engines.Add(sparkViewFactory);
}
示例12: RegisterEngines
public static void RegisterEngines(ViewEngineCollection viewEngines)
{
// Removes WebForms view engine - optimization
viewEngines.Clear();
// viewEngines.Add(new CustomViewLocationRazorViewEngine());
viewEngines.Add(new RazorViewEngine());
}
示例13: RegisterViewEngine
public static void RegisterViewEngine(ViewEngineCollection viewEngines)
{
viewEngines.Clear();
var PMIViewEngine = new PMIViewEngine();
viewEngines.Add(PMIViewEngine);
}
示例14: AddNullViewEngineThrows
public void AddNullViewEngineThrows()
{
// Arrange
ViewEngineCollection collection = new ViewEngineCollection();
// Act & Assert
Assert.ThrowsArgumentNull(
delegate { collection.Add(null); },
"item");
}
示例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));
}