My controller has a method that returns attribute data from the current executing assembly in a partial view.
In this example, I just occupy the name, but I need to do more with it.
Controller:
var title = "";
var asm = Assembly.GetExecutingAssembly();
var attrs = asm.GetCustomAttributes(typeof(AssemblyTitleAttribute));
var titleAttr = (AssemblyTitleAttribute)attributes[0];
title = titleAttr.Title;
return PartialView("_Build", title);
When writing unit test in Moq, I need to find a way to insert Assembly attributes into the layout so that I can make sure that the correct attributes are generated when the controller test runs, and then do x or y with my statements.
UnitTest:
var controller = GetController();
var result = controller.MyMethod() as PartialViewResult;
var title = result.Model;
Assert.AreEqual("Title", title);
I know this is a very simple set of code, but I just need proof of concept at the moment.
Is there a good way to create a fake Assembly? Do I need to use System.Reflection.Emit?
user4618785