Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Disable template list when model class name typed in and does not mat…

…ch any classes.
  • Loading branch information...
commit fa5c79643664fa17e4055ae5afe6cdafbed5c792 1 parent 651a4d5
@mrward mrward authored
View
4 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectView.xaml
@@ -99,13 +99,13 @@
<Label
Grid.Row="5"
- IsEnabled="{Binding Path=IsStronglyTypedView}"
+ IsEnabled="{Binding Path=IsViewTemplateEnabled}"
Content="Template:"/>
<ComboBox
Grid.Row="5"
Grid.Column="1"
Margin="0, 2, 0, 0"
- IsEnabled="{Binding Path=IsStronglyTypedView}"
+ IsEnabled="{Binding Path=IsViewTemplateEnabled}"
ItemsSource="{Binding Path=ViewTemplates}"
ItemTemplate="{StaticResource ViewEngineTemplate}"
SelectedItem="{Binding Path=SelectedViewTemplate}"/>
View
37 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectViewModel.cs
@@ -27,6 +27,7 @@ public class AddMvcViewToProjectViewModel : ViewModelBase<AddMvcViewToProjectVie
List<MvcViewTextTemplate> viewTemplates;
MvcViewTextTemplate selectedViewTemplate;
MvcModelClassViewModelsForSelectedFolder modelClassesForSelectedFolder;
+ MvcModelClassViewModel selectedModelClass;
public AddMvcViewToProjectViewModel(ISelectedMvcFolder selectedViewFolder)
: this(
@@ -300,15 +301,47 @@ void AddMvcViewFileToProject()
OnPropertyChanged(viewModel => viewModel.ModelClasses);
}
OnPropertyChanged(viewModel => viewModel.IsStronglyTypedView);
+ OnPropertyChanged(viewModel => viewModel.IsViewTemplateEnabled);
}
}
+ public bool IsViewTemplateEnabled {
+ get { return IsStronglyTypedView && (SelectedModelClass != null); }
+ }
+
public IEnumerable<MvcModelClassViewModel> ModelClasses {
get { return modelClassesForSelectedFolder.ModelClasses; }
}
- public MvcModelClassViewModel SelectedModelClass { get; set; }
- public string ModelClassName { get; set; }
+ public MvcModelClassViewModel SelectedModelClass {
+ get { return selectedModelClass; }
+ set {
+ selectedModelClass = value;
+ OnPropertyChanged(viewModel => viewModel.SelectedModelClass);
+ OnPropertyChanged(viewModel => viewModel.IsViewTemplateEnabled);
+ }
+ }
+
+ string modelClassName;
+
+ public string ModelClassName {
+ get { return modelClassName; }
+ set {
+ modelClassName = value;
+ if (!ModelClassNameMatchesSelectedModelClassName()) {
+ SelectedModelClass = null;
+ }
+ }
+ }
+
+ bool ModelClassNameMatchesSelectedModelClassName()
+ {
+ if (selectedModelClass != null) {
+ return selectedModelClass.Name == modelClassName;
+ }
+ return false;
+ }
+
public string PrimaryContentPlaceHolderId { get; set; }
public string MasterPageFile {
View
120 src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/AddMvcViewToProjectViewModelTests.cs
@@ -1243,5 +1243,125 @@ public void IsPartialView_IsContentPageChangedFromTrueToFalse_IsContentPagePrope
Assert.IsTrue(fired);
}
+
+ [Test]
+ public void IsViewTemplateEnabled_ModelClassSelectedAndIsStronglyTypedViewIsNotSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ viewModel.IsStronglyTypedView = false;
+
+ bool enabled = viewModel.IsViewTemplateEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsViewTemplateEnabled_ModelClassSelectedAndIsStronglyTypedViewIsSelected_ReturnsTrue()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+
+ bool enabled = viewModel.IsViewTemplateEnabled;
+
+ Assert.IsTrue(enabled);
+ }
+
+ [Test]
+ public void IsViewTemplateEnabled_NoModelClassSelectedAndIsStronglyTypedViewIsSelected_ReturnsFalse()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = null;
+ viewModel.ModelClassName = "Test";
+
+ bool enabled = viewModel.IsViewTemplateEnabled;
+
+ Assert.IsFalse(enabled);
+ }
+
+ [Test]
+ public void IsStronglyTypedView_IsStronglyTypedViewIsChangedFromTrueToFalse_IsViewTemplateEnabledPropertyChangedEventFired()
+ {
+ CreateViewModel();
+ viewModel.IsStronglyTypedView = true;
+ MonitorPropertyChangedEvents();
+ viewModel.IsStronglyTypedView = false;
+
+ bool fired = propertyChangedEvents.Contains("IsViewTemplateEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void SelectedModelClass_SelectedModelClassChangedToNull_IsViewTemplateEnabledPropertyChangedEventFired()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject.MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ MonitorPropertyChangedEvents();
+ viewModel.SelectedModelClass = null;
+
+ bool fired = propertyChangedEvents.Contains("IsViewTemplateEnabled");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void ModelClassName_ModelClassNameTextChangedFromSelectedModelClass_SelectedModelClassChangedToNull()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ viewModel.ModelClassName = "Test";
+
+ MvcModelClassViewModel selectedModelClass = viewModel.SelectedModelClass;
+
+ Assert.IsNull(selectedModelClass);
+ }
+
+ [Test]
+ public void ModelClassName_ModelClassNameTextChangedFromSelectedModelClass_SelectedModelClassPropertyChangedEventFired()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+ viewModel.IsStronglyTypedView = true;
+ viewModel.SelectedModelClass = viewModel.ModelClasses.First();
+ MonitorPropertyChangedEvents();
+ viewModel.ModelClassName = "Test";
+
+ bool fired = propertyChangedEvents.Contains("SelectedModelClass");
+
+ Assert.IsTrue(fired);
+ }
+
+ [Test]
+ public void ModelClassName_ModelClassNameTextChangedToMatchSelectedModelClass_SelectedModelClassIsNotChangedToNull()
+ {
+ CreateViewModel();
+ CSharpProjectSelected();
+ AddModelClassToProject("ICSharpCode.MyProject", "MyModel");
+ viewModel.IsStronglyTypedView = true;
+ MvcModelClassViewModel expectedModelClass = viewModel.ModelClasses.First();
+ viewModel.SelectedModelClass = expectedModelClass;
+ viewModel.ModelClassName = "MyModel (ICSharpCode.MyProject)";
+
+ MvcModelClassViewModel selectedModelClass = viewModel.SelectedModelClass;
+
+ Assert.AreEqual(expectedModelClass, selectedModelClass);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.