public MvcViewFileGenerator(
			IMvcTextTemplateHostFactory hostFactory,
			MvcTextTemplateRepository textTemplateRepository,
			IMvcTextTemplateHostAppDomainFactory appDomainFactory)
			: base(hostFactory, appDomainFactory)
		{
			this.textTemplateRepository = textTemplateRepository;
			
			ModelClassName = String.Empty;
			ModelClassAssemblyLocation = String.Empty;
			MasterPageFile = String.Empty;
			PrimaryContentPlaceHolderId = String.Empty;
			Template = new MvcViewTextTemplate();
		}
		public void GetMvcViewTextTemplates_CSharpRazorTemplatesRequestedAndTwoViewTemplatesInFolder_ReturnsTwoViewTextTemplates()
		{
			CreateRepositoryWithAspNetMvcAddInDirectory(@"C:\SD\AddIns\AspNet.Mvc");
			string templateFolder = 
				@"C:\SD\AddIns\AspNet.Mvc\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML";
			string[] templateFileNames = new string[] {
				@"C:\SD\AddIns\AspNet.Mvc\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\B.tt",
				@"C:\SD\AddIns\AspNet.Mvc\ItemTemplates\CSharp\CodeTemplates\AddView\CSHTML\A.tt"
			};
			AddTextTemplatesToFolder(templateFolder, templateFileNames);
			
			var templateCriteria = new MvcTextTemplateCriteria() {
				TemplateLanguage = MvcTextTemplateLanguage.CSharp,
				TemplateType = MvcTextTemplateType.Razor
			};
			
			List<MvcViewTextTemplate> templates = repository.GetMvcViewTextTemplates(templateCriteria).ToList();
			
			var expectedTemplate1 = new MvcViewTextTemplate() {
				Name = "B",
				FileName = templateFileNames[0]
			};
			var expectedTemplate2 = new MvcViewTextTemplate() {
				Name = "A",
				FileName = templateFileNames[1]
			};
			var expectedTemplates = new MvcViewTextTemplate[] {
				expectedTemplate1,
				expectedTemplate2
			};
			
			MvcViewTextTemplateCollectionAssert.AreEqual(expectedTemplates, templates);
		}
		public void GetMvcViewTextTemplates_CSharpAspxTemplatesRequestedAndOneViewTemplateInFolder_ReturnsOneViewTextTemplate()
		{
			CreateRepositoryWithAspNetMvcAddInDirectory(@"C:\SD\AddIns\AspNet.Mvc");
			string templateFolder = 
				@"C:\SD\AddIns\AspNet.Mvc\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp";
			string existingTemplateFileName = 
				@"C:\SD\AddIns\AspNet.Mvc\ItemTemplates\CSharp\CodeTemplates\AddView\AspxCSharp\Empty.tt";
			AddTextTemplatesToFolder(templateFolder, existingTemplateFileName);
			
			var templateCriteria = new MvcTextTemplateCriteria() {
				TemplateLanguage = MvcTextTemplateLanguage.CSharp,
				TemplateType = MvcTextTemplateType.Aspx
			};
			
			List<MvcViewTextTemplate> templates = repository.GetMvcViewTextTemplates(templateCriteria).ToList();
			
			var expectedTemplate = new MvcViewTextTemplate() {
				Name = "Empty",
				FileName = existingTemplateFileName
			};
			var expectedTemplates = new MvcViewTextTemplate[] {
				expectedTemplate
			};
			
			MvcViewTextTemplateCollectionAssert.AreEqual(expectedTemplates, templates);
		}
		static string ConvertToString(MvcViewTextTemplate template)
		{
			return String.Format(
				"Name: {0}, FileName: {1}",
				template.Name, template.FileName);
		}
		public void ViewTemplates_CSharpProjectAndOneTemplateInRepository_ReturnsOneViewTemplate()
		{
			fakeTextTemplateRepository = new FakeMvcTextTemplateRepository();
			var expectedTemplate = new MvcViewTextTemplate(@"d:\templates\Empty.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(expectedTemplate);
			CreateViewModelWithViewFolderPath(@"d:\myproject\views", fakeTextTemplateRepository);
			
			IEnumerable<MvcViewTextTemplate> templates = viewModel.ViewTemplates;
			
			var expectedTemplates = new MvcViewTextTemplate[] {
				expectedTemplate
			};
			
			MvcViewTextTemplateCollectionAssert.AreEqual(expectedTemplates, templates);
		}
		public void AddMvcView_SelectedViewTemplateIsSet_ViewTemplateUsedToGenerateMvcViewFile()
		{
			CreateViewModel();
			fakeSelectedMvcViewFolder.TemplateLanguage = MvcTextTemplateLanguage.VisualBasic;
			SelectRazorViewEngine();
			MvcViewTextTemplate expectedTemplate = new MvcViewTextTemplate();
			viewModel.SelectedViewTemplate = expectedTemplate;
			viewModel.AddMvcView();
			
			MvcViewTextTemplate template = fakeViewGenerator.Template;
			
			Assert.AreEqual(expectedTemplate, template);
		}
		public void ViewTemplates_NonEmptyViewTemplateSelectedWhenUserTypesInModelClassName_EmptyViewTemplateSelected()
		{
			fakeTextTemplateRepository = new FakeMvcTextTemplateRepository();
			
			var templateB = new MvcViewTextTemplate(@"d:\templates\B.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateB);
			
			var emptyTemplate = new MvcViewTextTemplate(@"d:\templates\Empty.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(emptyTemplate);
			
			CreateViewModelWithViewFolderPath(@"d:\myproject\views", fakeTextTemplateRepository);
			AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
			
			viewModel.IsStronglyTypedView = true;
			MvcModelClassViewModel expectedModelClass = viewModel.ModelClasses.First();
			viewModel.SelectedModelClass = expectedModelClass;
			viewModel.SelectedViewTemplate = templateB;
			viewModel.ModelClassName = "test";
			
			MvcViewTextTemplate template = viewModel.SelectedViewTemplate;
			
			Assert.AreEqual(emptyTemplate, template);
		}
		public void SelectedViewTemplate_RazorViewEngineSelectedAndNoEmptyTemplate_FirstTemplateSelectedByDefault()
		{
			CreateViewModel();
			var templateA = new MvcViewTextTemplate(@"d:\razor\A.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateA);
			SelectRazorViewEngine();
			
			MvcViewTextTemplate selectedTemplate = viewModel.SelectedViewTemplate;
			
			Assert.AreEqual(templateA, selectedTemplate);
		}
		public void SelectedViewTemplate_RazorViewEngineSelectedWhenTemplateNameIsInUpperCase_EmptyTemplateSelectedByDefault()
		{
			CreateViewModel();
			var templateA = new MvcViewTextTemplate(@"d:\razor\A.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateA);
			var emptyTemplate = new MvcViewTextTemplate(@"d:\razor\EMPTY.TT");
			fakeTextTemplateRepository.ViewTextTemplates.Add(emptyTemplate);
			SelectRazorViewEngine();
			
			MvcViewTextTemplate selectedTemplate = viewModel.SelectedViewTemplate;
			
			Assert.AreEqual(emptyTemplate, selectedTemplate);
		}
		public void SelectedViewTemplate_RazorViewEngineSelectedWhenThreeRazorViewTemplatesExist_EmptyTemplateSelectedByDefault()
		{
			CreateViewModel();
			var templateA = new MvcViewTextTemplate(@"d:\razor\A.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateA);
			var emptyTemplate = new MvcViewTextTemplate(@"d:\razor\Empty.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(emptyTemplate);
			var templateZ = new MvcViewTextTemplate(@"d:\razor\Z.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateZ);
			SelectRazorViewEngine();
			
			MvcViewTextTemplate selectedTemplate = viewModel.SelectedViewTemplate;
			
			Assert.AreEqual(emptyTemplate, selectedTemplate);
		}
		public void ViewTemplates_CSharpProjectAndRazorViewEngineSelected_ViewTemplatesUpdatedFromRepository()
		{
			CreateViewModel();
			List<MvcViewTextTemplate> templates = viewModel.ViewTemplates.ToList();
			
			var expectedTemplate = new MvcViewTextTemplate(@"d:\templates\Empty.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(expectedTemplate);
			
			SelectRazorViewEngine();
			
			templates = viewModel.ViewTemplates.ToList();
			
			var expectedTemplates = new MvcViewTextTemplate[] {
				expectedTemplate
			};
			
			MvcViewTextTemplateCollectionAssert.AreEqual(expectedTemplates, templates);
		}
		public void ViewTemplates_CSharpProjectAndTwoTemplatesInRepository_ReturnsTwoViewTemplatesSortedByName()
		{
			fakeTextTemplateRepository = new FakeMvcTextTemplateRepository();
			
			var templateB = new MvcViewTextTemplate(@"d:\templates\B.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateB);
			
			var templateA = new MvcViewTextTemplate(@"d:\templates\A.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(templateA);
			
			CreateViewModelWithViewFolderPath(@"d:\myproject\views", fakeTextTemplateRepository);
			
			IEnumerable<MvcViewTextTemplate> templates = viewModel.ViewTemplates;
			
			var expectedTemplates = new MvcViewTextTemplate[] {
				templateA,
				templateB
			};
			
			MvcViewTextTemplateCollectionAssert.AreEqual(expectedTemplates, templates);
		}
		public void ViewTemplates_VisualBasicProject_VisualBasicTemplatesRetrievedFromTemplateRepository()
		{
			fakeTextTemplateRepository = new FakeMvcTextTemplateRepository();
			var expectedTemplate = new MvcViewTextTemplate(@"d:\templates\Empty.tt");
			fakeTextTemplateRepository.ViewTextTemplates.Add(expectedTemplate);
			CreateViewModelWithViewFolderPath(
				@"d:\myproject\views",
				fakeTextTemplateRepository,
				MvcTextTemplateLanguage.VisualBasic);
			
			IEnumerable<MvcViewTextTemplate> templates = viewModel.ViewTemplates;
			MvcTextTemplateCriteria templateCriteria = fakeTextTemplateRepository.TemplateCriteriaPassedToGetMvcViewTextTemplates;
			
			Assert.AreEqual(MvcTextTemplateLanguage.VisualBasic, templateCriteria.TemplateLanguage);
		}