Browse Source

Support selecting ASP.NET master page for a new MVC view from a list of available master pages in the project.

pull/18/head
Matt Ward 15 years ago
parent
commit
7b516633f9
  1. 3
      src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj
  2. 338
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectView.xaml
  3. 71
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectViewModel.cs
  4. 21
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/BooleanToVisibilityConverter.cs
  5. 2
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/IMvcProject.cs
  6. 85
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcMasterPageFileName.cs
  7. 10
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcProject.cs
  8. 39
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcVirtualPath.cs
  9. 126
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/SlideBehaviour.cs
  10. 3
      src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj
  11. 12
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/FakeMvcProject.cs
  12. 28
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/MvcMasterPageFileNameAssert.cs
  13. 32
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/MvcMasterPageFileNameCollectionAssert.cs
  14. 8
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/TestableProject.cs
  15. 184
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/AddMvcViewToProjectViewModelTests.cs
  16. 40
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/BooleanToVisibilityConverterTests.cs
  17. 86
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/MvcMasterPageFileNameTests.cs
  18. 91
      src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/MvcProjectTests.cs

3
src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj

@ -79,6 +79,7 @@ @@ -79,6 +79,7 @@
<Compile Include="Src\IsMvcFolderSelectedConditionEvaluator.cs" />
<Compile Include="Src\IsMvcViewFolderSelectedConditionEvaluator.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\MvcMasterPageFileName.cs" />
<Compile Include="Src\MvcModelClassLocator.cs" />
<Compile Include="Src\MvcAddViewTextTemplateFolder.cs" />
<Compile Include="Src\MvcClass.cs" />
@ -111,10 +112,12 @@ @@ -111,10 +112,12 @@
<Compile Include="Src\MvcViewFileGenerator.cs" />
<Compile Include="Src\MvcViewTextTemplateFileName.cs" />
<Compile Include="Src\MvcViewTypeViewModel.cs" />
<Compile Include="Src\MvcVirtualPath.cs" />
<Compile Include="Src\SelectedFolderNodeInProjectsView.cs" />
<Compile Include="Src\SelectedMvcControllerFolder.cs" />
<Compile Include="Src\SelectedMvcFolder.cs" />
<Compile Include="Src\SelectedMvcViewFolder.cs" />
<Compile Include="Src\SlideBehaviour.cs" />
<Compile Include="Src\ViewModelBase.cs" />
</ItemGroup>
<ItemGroup>

338
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectView.xaml

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Window
<Window
x:Class="ICSharpCode.AspNet.Mvc.AddMvcViewToProjectView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:aspnetmvcaddin="clr-namespace:ICSharpCode.AspNet.Mvc"
@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
WindowStartupLocation="CenterOwner"
FocusManager.FocusedElement="{Binding ElementName=ViewNameTextBox}"
Height="400"
Width="400">
Width="500">
<Window.Resources>
<Style TargetType="Button" BasedOn="{x:Static core:GlobalStyles.ButtonStyle}"/>
@ -23,137 +23,211 @@ @@ -23,137 +23,211 @@
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid
x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label
Margin="0, 2, 0, 0"
Content="View Name:"/>
<TextBox
x:Name="ViewNameTextBox"
Margin="0, 2, 0, 0"
Grid.Column="1"
Text="{Binding Path=ViewName, UpdateSourceTrigger=PropertyChanged}"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label
Margin="0, 2, 0, 0"
Content="View Name:"/>
<TextBox
x:Name="ViewNameTextBox"
Margin="0, 2, 0, 0"
Grid.Column="1"
Text="{Binding Path=ViewName, UpdateSourceTrigger=PropertyChanged}"/>
<Label
Grid.Row="1"
Content="View Engine:"/>
<ComboBox
Grid.Row="1"
Grid.Column="1"
Margin="0, 2, 0, 0"
ItemsSource="{Binding Path=ViewEngines}"
ItemTemplate="{StaticResource ViewEngineTemplate}"
SelectedItem="{Binding Path=SelectedViewEngine}"/>
<Label
Grid.Row="2"
Content="Partial View:"/>
<CheckBox
Grid.Column="1"
Grid.Row="2"
Margin="0, 6, 0, 0"
IsChecked="{Binding Path=IsPartialView}"/>
<Label
Grid.Row="3"
Margin="0, 20, 0, 0"
Content="Strongly Typed:"/>
<CheckBox
Grid.Column="1"
Grid.Row="3"
Margin="0, 28, 0, 0"
IsChecked="{Binding Path=IsStronglyTypedView}"/>
<Label
Grid.Row="4"
IsEnabled="{Binding Path=IsStronglyTypedView}"
Content="Model:"/>
<ComboBox
Grid.Row="4"
Grid.Column="1"
Margin="0, 2, 0, 0"
IsEditable="True"
IsEnabled="{Binding Path=IsStronglyTypedView}"
ItemsSource="{Binding Path=ModelClasses}"
Text="{Binding Path=ModelClassName, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding Path=SelectedModelClass}"/>
<Label
Grid.Row="6"
Margin="0, 20, 0, 0"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Content="Use Master Page:"/>
<Label
Grid.Row="6"
Margin="0, 20, 0, 0"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Content="Use Layout:"/>
<CheckBox
Grid.Column="1"
Grid.Row="6"
Margin="0, 28, 0, 0"
IsChecked="{Binding Path=IsContentPage}"/>
<Label
Grid.Row="7"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Content="Master Page:"/>
<Label
Grid.Row="7"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Content="Layout:"/>
<TextBox
Grid.Row="7"
Grid.Column="1"
IsEnabled="{Binding Path=IsContentPage}"
Text="{Binding Path=MasterPageFile}"/>
<Label
Grid.Row="8"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Content="Main Content ID:"/>
<TextBox
Grid.Row="8"
Grid.Column="1"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Text="{Binding Path=PrimaryContentPlaceHolderId}"/>
<Label
Grid.Row="1"
Content="View Engine:"/>
<ComboBox
Grid.Row="1"
Grid.Column="1"
Margin="0, 2, 0, 0"
ItemsSource="{Binding Path=ViewEngines}"
ItemTemplate="{StaticResource ViewEngineTemplate}"
SelectedItem="{Binding Path=SelectedViewEngine}"/>
<Label
Grid.Row="2"
Content="Partial View:"/>
<CheckBox
Grid.Column="1"
Grid.Row="2"
Margin="0, 6, 0, 0"
IsChecked="{Binding Path=IsPartialView}"/>
<Label
Grid.Row="3"
Margin="0, 20, 0, 0"
Content="Strongly Typed:"/>
<CheckBox
Grid.Column="1"
Grid.Row="3"
Margin="0, 28, 0, 0"
IsChecked="{Binding Path=IsStronglyTypedView}"/>
<Label
Grid.Row="4"
IsEnabled="{Binding Path=IsStronglyTypedView}"
Content="Model:"/>
<ComboBox
Grid.Row="4"
Grid.Column="1"
Margin="0, 2, 0, 0"
IsEditable="True"
IsEnabled="{Binding Path=IsStronglyTypedView}"
ItemsSource="{Binding Path=ModelClasses}"
Text="{Binding Path=ModelClassName, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding Path=SelectedModelClass}"/>
<Label
Grid.Row="6"
Margin="0, 20, 0, 0"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Content="Use Master Page:"/>
<Label
Grid.Row="6"
Margin="0, 20, 0, 0"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Content="Use Layout:"/>
<CheckBox
Grid.Column="1"
Grid.Row="6"
Margin="0, 28, 0, 0"
IsChecked="{Binding Path=IsContentPage}"/>
<Label
Grid.Row="7"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Content="Master Page:"/>
<Label
Grid.Row="7"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Content="Layout:"/>
<Grid
Grid.Row="7"
Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox
IsEnabled="{Binding Path=IsContentPage}"
Text="{Binding Path=MasterPageFile}"/>
<StackPanel
Grid.Column="2"
Orientation="Horizontal">
<Button
Padding="9, 0, 9, 0"
Style="{x:Null}"
IsEnabled="{Binding Path=IsContentPage}"
Content="..."
Command="{Binding Path=OpenSelectMasterPageViewCommand}"/>
</StackPanel>
</Grid>
<Label
Grid.Row="8"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Content="Main Content ID:"/>
<TextBox
Grid.Row="8"
Grid.Column="1"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=IsContentPage}"
Text="{Binding Path=PrimaryContentPlaceHolderId}"/>
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="4"
Grid.ColumnSpan="2"
Grid.Row="10">
<Button
Margin="2, 0"
Content="_Add"
IsDefault="True"
Command="{Binding Path=AddMvcViewCommand}"/>
<Button
Margin="2, 0"
Content="_Cancel"
IsCancel="True"/>
</StackPanel>
</Grid>
<Grid
x:Name="SelectMasterPageGrid"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
mvc:SlideBehaviour.IsDisplayed="{Binding Path=IsSelectMasterPageViewOpen}"
mvc:SlideBehaviour.FrameworkElementHiddenBySlide="{Binding ElementName=MainGrid}"
Visibility="Collapsed">
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="4"
Grid.ColumnSpan="2"
Grid.Row="10">
<Button
Margin="2, 0"
Content="_Add"
IsDefault="True"
Command="{Binding Path=AddMvcViewCommand}"/>
<Button
Margin="2, 0"
Content="_Cancel"
IsCancel="True"/>
</StackPanel>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock
Margin="4"
Visibility="{Binding Path=IsAspxViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Text="Select a Master Page"/>
<TextBlock
Margin="4"
Visibility="{Binding Path=IsRazorViewEngineSelected, Converter={StaticResource BoolToVisibility}}"
Text="Select a Layout Page"/>
<ListView
Grid.Row="1"
ItemsSource="{Binding Path=MasterPages}"
SelectedItem="{Binding Path=SelectedMasterPage}">
<ListView.View>
<GridView>
<GridViewColumn
Header="File"
DisplayMemberBinding="{Binding Path=FileName}"
Width="Auto"/>
<GridViewColumn
Header="Project Folder"
DisplayMemberBinding="{Binding Path=FolderRelativeToProject}"
Width="Auto"/>
</GridView>
</ListView.View>
</ListView>
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="4"
Grid.Row="2">
<Button
Margin="2, 0"
Content="_Back"
Command="{Binding Path=CloseSelectMasterPageViewCommand}"/>
<Button
Margin="2, 0"
Content="_Select"
Command="{Binding Path=SelectMasterPageCommand}"/>
</StackPanel>
</Grid>
</Grid>
</Window>

71
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectViewModel.cs

@ -19,6 +19,9 @@ namespace ICSharpCode.AspNet.Mvc @@ -19,6 +19,9 @@ namespace ICSharpCode.AspNet.Mvc
MvcViewEngineViewModel selectedViewEngine;
bool isStronglyTypedView;
bool isContentPage;
bool isSelectMasterPageViewOpen;
MvcMasterPageFileName selectedMasterPage;
string masterPageFile = String.Empty;
MvcModelClassViewModelsForSelectedFolder modelClassesForSelectedFolder;
@ -38,6 +41,7 @@ namespace ICSharpCode.AspNet.Mvc @@ -38,6 +41,7 @@ namespace ICSharpCode.AspNet.Mvc
this.viewFileName.Folder = selectedViewFolder.Path;
this.ModelClassName = String.Empty;
this.PrimaryContentPlaceHolderId = "Main";
this.MasterPages = new ObservableCollection<MvcMasterPageFileName>();
CreateModelClassesForSelectedFolder();
CreateCommands();
@ -53,9 +57,15 @@ namespace ICSharpCode.AspNet.Mvc @@ -53,9 +57,15 @@ namespace ICSharpCode.AspNet.Mvc
void CreateCommands()
{
AddMvcViewCommand = new DelegateCommand(param => AddMvcView(), param => CanAddMvcView());
OpenSelectMasterPageViewCommand = new DelegateCommand(param => OpenSelectMasterPageView());
CloseSelectMasterPageViewCommand = new DelegateCommand(param => CloseSelectMasterPageView());
SelectMasterPageCommand = new DelegateCommand(param => SelectMasterPage(), param => CanSelectMasterPage());
}
public ICommand AddMvcViewCommand { get; private set; }
public ICommand OpenSelectMasterPageViewCommand { get; private set; }
public ICommand CloseSelectMasterPageViewCommand { get; private set; }
public ICommand SelectMasterPageCommand { get; private set; }
public string ViewName {
get { return viewFileName.ViewName; }
@ -236,8 +246,67 @@ namespace ICSharpCode.AspNet.Mvc @@ -236,8 +246,67 @@ namespace ICSharpCode.AspNet.Mvc
public MvcModelClassViewModel SelectedModelClass { get; set; }
public string ModelClassName { get; set; }
public string MasterPageFile { get; set; }
public string PrimaryContentPlaceHolderId { get; set; }
public string MasterPageFile {
get { return masterPageFile; }
set {
masterPageFile = value;
OnPropertyChanged(viewModel => viewModel.MasterPageFile);
}
}
public bool IsSelectMasterPageViewOpen {
get { return isSelectMasterPageViewOpen; }
set {
isSelectMasterPageViewOpen = value;
OnPropertyChanged(viewModel => viewModel.IsSelectMasterPageViewOpen);
}
}
public void OpenSelectMasterPageView()
{
UpdateMasterPages();
IsSelectMasterPageViewOpen = true;
}
void UpdateMasterPages()
{
MasterPages.Clear();
foreach (MvcMasterPageFileName fileName in GetAspxMasterPageFileNames()) {
MasterPages.Add(fileName);
}
}
IEnumerable<MvcMasterPageFileName> GetAspxMasterPageFileNames()
{
return selectedViewFolder.Project.GetAspxMasterPageFileNames();
}
public void CloseSelectMasterPageView()
{
IsSelectMasterPageViewOpen = false;
}
public ObservableCollection<MvcMasterPageFileName> MasterPages { get; private set; }
public MvcMasterPageFileName SelectedMasterPage {
get { return selectedMasterPage; }
set { selectedMasterPage = value; }
}
public void SelectMasterPage()
{
if (selectedMasterPage != null) {
MasterPageFile = selectedMasterPage.VirtualPath;
}
IsSelectMasterPageViewOpen = false;
}
public bool CanSelectMasterPage()
{
return selectedMasterPage != null;
}
}
}

21
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/BooleanToVisibilityConverter.cs

@ -11,10 +11,12 @@ namespace ICSharpCode.AspNet.Mvc @@ -11,10 +11,12 @@ namespace ICSharpCode.AspNet.Mvc
public class BooleanToVisibilityConverter : IValueConverter
{
public bool Hidden { get; set; }
public bool IsReversed { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value) {
bool visible = IsVisible((bool)value);
if (visible) {
return Visibility.Visible;
} else if (Hidden) {
return Visibility.Hidden;
@ -22,10 +24,23 @@ namespace ICSharpCode.AspNet.Mvc @@ -22,10 +24,23 @@ namespace ICSharpCode.AspNet.Mvc
return Visibility.Collapsed;
}
bool IsVisible(bool value)
{
if (IsReversed) {
return !value;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
Visibility visibility = (Visibility)value;
return visibility == Visibility.Visible;
return IsVisible((Visibility)value);
}
bool IsVisible(Visibility visibility)
{
bool visible = visibility == Visibility.Visible;
return IsVisible(visible);
}
}
}

2
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/IMvcProject.cs

@ -16,5 +16,7 @@ namespace ICSharpCode.AspNet.Mvc @@ -16,5 +16,7 @@ namespace ICSharpCode.AspNet.Mvc
void Save();
MvcTextTemplateLanguage GetTemplateLanguage();
IEnumerable<IMvcClass> GetModelClasses();
IEnumerable<MvcMasterPageFileName> GetAspxMasterPageFileNames();
}
}

85
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcMasterPageFileName.cs

@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.AspNet.Mvc
{
public class MvcMasterPageFileName
{
public MvcMasterPageFileName(FileProjectItem fileProjectItem)
{
UpdateFileName(fileProjectItem);
}
void UpdateFileName(FileProjectItem fileProjectItem)
{
FullPath = fileProjectItem.FileName;
FileName = Path.GetFileName(FullPath);
FolderRelativeToProject = GetFolderRelativeToProject(fileProjectItem);
VirtualPath = GetVirtualPath();
}
string GetFolderRelativeToProject(FileProjectItem fileProjectItem)
{
return Path.GetDirectoryName(fileProjectItem.Include);
}
string GetVirtualPath()
{
var virtualPath = new MvcVirtualPath(FolderRelativeToProject, FileName);
return virtualPath.VirtualPath;
}
public MvcMasterPageFileName()
{
FullPath = String.Empty;
FileName = String.Empty;
FolderRelativeToProject = String.Empty;
VirtualPath = String.Empty;
}
public string FullPath { get; set; }
public string FileName { get; set; }
public string FolderRelativeToProject { get; set; }
public string VirtualPath { get; set; }
public override string ToString()
{
return FullPath;
}
public static MvcMasterPageFileName CreateMvcMasterPageFileName(ProjectItem projectItem)
{
var fileProjectItem = projectItem as FileProjectItem;
if (fileProjectItem != null) {
return CreateMvcMasterPageFileName(fileProjectItem);
}
return null;
}
public static MvcMasterPageFileName CreateMvcMasterPageFileName(FileProjectItem fileProjectItem)
{
if (IsMasterPageFileName(fileProjectItem.FileName)) {
return new MvcMasterPageFileName(fileProjectItem);
}
return null;
}
public static bool IsMasterPageFileName(string fileName)
{
string extension = GetLowerCaseFileExtension(fileName);
return extension == ".master";
}
static string GetLowerCaseFileExtension(string fileName)
{
if (fileName != null) {
return Path.GetExtension(fileName).ToLowerInvariant();
}
return String.Empty;
}
}
}

10
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcProject.cs

@ -43,5 +43,15 @@ namespace ICSharpCode.AspNet.Mvc @@ -43,5 +43,15 @@ namespace ICSharpCode.AspNet.Mvc
{
return modelClassLocator.GetModelClasses(this);
}
public IEnumerable<MvcMasterPageFileName> GetAspxMasterPageFileNames()
{
foreach (ProjectItem projectItem in Project.Items) {
MvcMasterPageFileName fileName = MvcMasterPageFileName.CreateMvcMasterPageFileName(projectItem);
if (fileName != null) {
yield return fileName;
}
}
}
}
}

39
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/MvcVirtualPath.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.AspNet.Mvc
{
public class MvcVirtualPath
{
public MvcVirtualPath(string folderRelativeToProject, string fileName)
{
VirtualPath = GetVirtualPath(folderRelativeToProject, fileName);
}
public string VirtualPath { get; private set; }
string GetVirtualPath(string folderRelativeToProject, string fileName)
{
return String.Format(
"~/{0}{1}",
GetFolderRelativeToProjectAsVirtualPath(folderRelativeToProject),
fileName);
}
string GetFolderRelativeToProjectAsVirtualPath(string folderRelativeToProject)
{
string virtualFolder = folderRelativeToProject.Replace('\\', '/');
return AppendForwardSlashIfVirtualFolderIsNotEmptyString(virtualFolder);
}
string AppendForwardSlashIfVirtualFolderIsNotEmptyString(string virtualFolder)
{
if (String.IsNullOrEmpty(virtualFolder)) {
return String.Empty;
}
return virtualFolder + "/";
}
}
}

126
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/SlideBehaviour.cs

@ -0,0 +1,126 @@ @@ -0,0 +1,126 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows;
using System.Windows.Media.Animation;
namespace ICSharpCode.AspNet.Mvc
{
public static class SlideBehaviour
{
public static readonly DependencyProperty FrameworkElementHiddenBySlideProperty =
DependencyProperty.RegisterAttached(
"FrameworkElementHiddenBySlide",
typeof(FrameworkElement),
typeof(SlideBehaviour),
new UIPropertyMetadata(null));
public static FrameworkElement GetFrameworkElementHiddenBySlide(FrameworkElement frameworkElement)
{
return frameworkElement.GetValue(FrameworkElementHiddenBySlideProperty) as FrameworkElement;
}
public static void SetFrameworkElementHiddenBySlide(FrameworkElement frameworkElement, FrameworkElement hiddenFrameworkElement)
{
frameworkElement.SetValue(FrameworkElementHiddenBySlideProperty, hiddenFrameworkElement);
}
public static readonly DependencyProperty IsDisplayedProperty =
DependencyProperty.RegisterAttached(
"IsDisplayed",
typeof(bool),
typeof(SlideBehaviour),
new UIPropertyMetadata(false, OnIsDisplayedChanged));
public static bool GetIsDisplayed(FrameworkElement frameworkElement)
{
return (bool)frameworkElement.GetValue(IsDisplayedProperty);
}
public static void SetIsDisplayed(FrameworkElement frameworkElement, bool value)
{
frameworkElement.SetValue(IsDisplayedProperty, value);
}
static void OnIsDisplayedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var frameworkElement = dependencyObject as FrameworkElement;
if (frameworkElement == null) {
return;
}
if (e.NewValue is bool) {
if ((bool)e.NewValue) {
SlideIn(frameworkElement);
} else {
SlideOut(frameworkElement);
}
}
}
static void SlideIn(FrameworkElement frameworkElement)
{
AnimationTimeline marginAnimation = CreateSlideInAnimation(frameworkElement);
frameworkElement.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
frameworkElement.Visibility = Visibility.Visible;
DisableHiddenFrameworkElement(frameworkElement);
}
static AnimationTimeline CreateSlideInAnimation(FrameworkElement frameworkElement)
{
var parent = frameworkElement.Parent as FrameworkElement;
var marginAnimation = new ThicknessAnimation();
marginAnimation.From = new Thickness(parent.ActualWidth, 0, 0, 0);
marginAnimation.To = new Thickness(0);
marginAnimation.Duration = duration;
return marginAnimation;
}
static readonly Duration duration = new Duration(new TimeSpan(TimeSpan.TicksPerMillisecond * 100));
static void DisableHiddenFrameworkElement(FrameworkElement frameworkElement)
{
EnableHiddenFrameworkElement(frameworkElement, enabled: false);
}
static void EnableHiddenFrameworkElement(FrameworkElement frameworkElement, bool enabled)
{
FrameworkElement hiddenFrameworkElement = GetFrameworkElementHiddenBySlide(frameworkElement);
if (hiddenFrameworkElement != null) {
hiddenFrameworkElement.IsEnabled = enabled;
}
}
static void SlideOut(FrameworkElement frameworkElement)
{
AnimationTimeline marginAnimation = CreateSlideOutAnimation(frameworkElement);
frameworkElement.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
}
static AnimationTimeline CreateSlideOutAnimation(FrameworkElement frameworkElement)
{
var parent = frameworkElement.Parent as FrameworkElement;
var marginAnimation = new ThicknessAnimation();
marginAnimation.From = new Thickness(0);
marginAnimation.To = new Thickness(parent.ActualWidth, 0, 0, 0);
marginAnimation.Duration = duration;
marginAnimation.Completed += (sender, e) => OnSlideOutCompleted(frameworkElement);
return marginAnimation;
}
static void OnSlideOutCompleted(FrameworkElement frameworkElement)
{
frameworkElement.Visibility = Visibility.Collapsed;
EnableHiddenFrameworkElement(frameworkElement);
}
static void EnableHiddenFrameworkElement(FrameworkElement frameworkElement)
{
EnableHiddenFrameworkElement(frameworkElement, true);
}
}
}

3
src/AddIns/BackendBindings/AspNet.Mvc/Test/AspNet.Mvc.Tests.csproj

@ -66,6 +66,8 @@ @@ -66,6 +66,8 @@
<Compile Include="Helpers\FakeMvcViewFileGenerator.cs" />
<Compile Include="Helpers\FakeSelectedFolderNodeInProjectsView.cs" />
<Compile Include="Helpers\FakeSelectedMvcFolder.cs" />
<Compile Include="Helpers\MvcMasterPageFileNameAssert.cs" />
<Compile Include="Helpers\MvcMasterPageFileNameCollectionAssert.cs" />
<Compile Include="Helpers\TestableAddMvcControllerToProjectCommand.cs" />
<Compile Include="Helpers\TestableAddMvcViewToProjectCommand.cs" />
<Compile Include="Helpers\TestableProject.cs" />
@ -79,6 +81,7 @@ @@ -79,6 +81,7 @@
<Compile Include="Src\IsMvcViewFolderSelectedConditionEvaluatorTests.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\MvcClassTests.cs" />
<Compile Include="Src\MvcMasterPageFileNameTests.cs" />
<Compile Include="Src\MvcModelClassLocatorTests.cs" />
<Compile Include="Src\MvcControllerFileGeneratorTests.cs" />
<Compile Include="Src\MvcControllerFileNameTests.cs" />

12
src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/FakeMvcProject.cs

@ -63,5 +63,17 @@ namespace AspNet.Mvc.Tests.Helpers @@ -63,5 +63,17 @@ namespace AspNet.Mvc.Tests.Helpers
GetModelClassesCallCount++;
return ModelClasses;
}
public List<MvcMasterPageFileName> MasterPageFileNames = new List<MvcMasterPageFileName>();
public void AddMasterPageFile(MvcMasterPageFileName fileName)
{
MasterPageFileNames.Add(fileName);
}
public IEnumerable<MvcMasterPageFileName> GetAspxMasterPageFileNames()
{
return MasterPageFileNames;
}
}
}

28
src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/MvcMasterPageFileNameAssert.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.AspNet.Mvc;
using NUnit.Framework;
namespace AspNet.Mvc.Tests.Helpers
{
public static class MvcMasterPageFileNameAssert
{
public static void AreEqual(MvcMasterPageFileName expected, MvcMasterPageFileName actual)
{
string expectedAsString = GetMvcMasterPageFileNameAsString(expected);
string actualAsString = GetMvcMasterPageFileNameAsString(actual);
Assert.AreEqual(expectedAsString, actualAsString);
}
public static string GetMvcMasterPageFileNameAsString(MvcMasterPageFileName fileName)
{
return String.Format(
"FileName: {0}\r\nFolder: {1}\r\n, FullPath: {2}",
fileName.FileName,
fileName.FolderRelativeToProject,
fileName.FullPath);
}
}
}

32
src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/MvcMasterPageFileNameCollectionAssert.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.AspNet.Mvc;
using ICSharpCode.SharpDevelop;
using NUnit.Framework;
namespace AspNet.Mvc.Tests.Helpers
{
public static class MvcMasterPageFileNameCollectionAssert
{
public static void AreEqual(IEnumerable<MvcMasterPageFileName> expected, IEnumerable<MvcMasterPageFileName> actual)
{
List<string> expectedAsStrings = GetMvcMasterPageFileNamesAsStrings(expected);
List<string> actualAsStrings = GetMvcMasterPageFileNamesAsStrings(actual);
CollectionAssert.AreEqual(expectedAsStrings, actualAsStrings);
}
static List<string> GetMvcMasterPageFileNamesAsStrings(IEnumerable<MvcMasterPageFileName> fileNames)
{
var convertedFileNames = new List<string>();
foreach (MvcMasterPageFileName fileName in fileNames) {
string fileNameAsString = MvcMasterPageFileNameAssert.GetMvcMasterPageFileNameAsString(fileName);
convertedFileNames.Add(fileNameAsString);
}
return convertedFileNames;
}
}
}

8
src/AddIns/BackendBindings/AspNet.Mvc/Test/Helpers/TestableProject.cs

@ -55,5 +55,13 @@ namespace AspNet.Mvc.Tests.Helpers @@ -55,5 +55,13 @@ namespace AspNet.Mvc.Tests.Helpers
public override bool ReadOnly {
get { return false; }
}
public FileProjectItem AddFileToProject(string fileName)
{
var projectItem = new FileProjectItem(this, ItemType.Compile);
projectItem.FileName = fileName;
ProjectService.AddProjectItem(this, projectItem);
return projectItem;
}
}
}

184
src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/AddMvcViewToProjectViewModelTests.cs

@ -207,7 +207,7 @@ namespace AspNet.Mvc.Tests @@ -207,7 +207,7 @@ namespace AspNet.Mvc.Tests
}
[Test]
public void AddMvcViewCommand_ViewNameIsNotEmptyString_CommandIsEnable()
public void AddMvcViewCommand_ViewNameIsNotEmptyString_CommandIsEnabled()
{
CreateViewModel();
viewModel.ViewName = "MyView";
@ -730,5 +730,187 @@ namespace AspNet.Mvc.Tests @@ -730,5 +730,187 @@ namespace AspNet.Mvc.Tests
Assert.AreEqual(String.Empty, id);
}
[Test]
public void OpenSelectMasterPageViewCommand_Executed_SelectMasterPageViewModelIsOpened()
{
CreateViewModel();
viewModel.OpenSelectMasterPageViewCommand.Execute(null);
bool open = viewModel.IsSelectMasterPageViewOpen;
Assert.IsTrue(open);
}
[Test]
public void OpenSelectMasterPageViewCommand_Executed_IsSelectMasterPageViewOpenPropertyChanged()
{
CreateViewModel();
MonitorPropertyChangedEvents();
viewModel.OpenSelectMasterPageViewCommand.Execute(null);
bool contains = propertyChangedEvents.Contains("IsSelectMasterPageViewOpen");
Assert.IsTrue(contains);
}
[Test]
public void IsSelectMasterPageViewOpen_NotExecuted_SelectMasterPageViewModelIsNotOpened()
{
CreateViewModel();
bool open = viewModel.IsSelectMasterPageViewOpen;
Assert.IsFalse(open);
}
[Test]
public void CloseSelectMasterPageViewCommand_Executed_SelectMasterPageViewModelIsClosed()
{
CreateViewModel();
viewModel.OpenSelectMasterPageView();
viewModel.CloseSelectMasterPageViewCommand.Execute(null);
bool open = viewModel.IsSelectMasterPageViewOpen;
Assert.IsFalse(open);
}
[Test]
public void CloseSelectMasterPageViewCommand_Executed_IsSelectMasterPageViewOpenPropertyChanged()
{
CreateViewModel();
MonitorPropertyChangedEvents();
viewModel.CloseSelectMasterPageViewCommand.Execute(null);
bool contains = propertyChangedEvents.Contains("IsSelectMasterPageViewOpen");
Assert.IsTrue(contains);
}
[Test]
public void MasterPages_ProjectContainsOneAspxMasterPage_ReturnsOneAspxMasterPage()
{
CreateViewModel();
SelectAspxViewEngine();
var masterPageFile = new MvcMasterPageFileName() {
FullPath = @"d:\projects\MyProject\Views\Shared\Site.Master",
FileName = "Site.Master",
FolderRelativeToProject = @"Views\Shared"
};
fakeProject.AddMasterPageFile(masterPageFile);
viewModel.OpenSelectMasterPageView();
var expectedFileNames = new MvcMasterPageFileName[] {
masterPageFile
};
ObservableCollection<MvcMasterPageFileName> fileNames = viewModel.MasterPages;
Assert.AreEqual(expectedFileNames, fileNames);
}
[Test]
public void MasterPages_CloseAndReOpenSelectMasterPageViewWhenProjectContainsOneAspxMasterPage_ReturnsOneAspxMasterPage()
{
CreateViewModel();
SelectAspxViewEngine();
var masterPageFile = new MvcMasterPageFileName();
fakeProject.AddMasterPageFile(masterPageFile);
viewModel.OpenSelectMasterPageView();
viewModel.CloseSelectMasterPageView();
viewModel.OpenSelectMasterPageView();
var expectedFileNames = new MvcMasterPageFileName[] {
masterPageFile
};
ObservableCollection<MvcMasterPageFileName> fileNames = viewModel.MasterPages;
Assert.AreEqual(expectedFileNames, fileNames);
}
[Test]
public void SelectMasterPageCommand_MasterPageNotSelected_CommandIsDisabled()
{
CreateViewModel();
viewModel.SelectedMasterPage = null;
bool canExecute = viewModel.SelectMasterPageCommand.CanExecute(null);
Assert.IsFalse(canExecute);
}
[Test]
public void SelectMasterPageCommand_MasterPageIsSelected_CommandIsEnabled()
{
CreateViewModel();
viewModel.SelectedMasterPage = new MvcMasterPageFileName();
bool canExecute = viewModel.SelectMasterPageCommand.CanExecute(null);
Assert.IsTrue(canExecute);
}
[Test]
public void SelectMasterPageCommand_Executed_SelectMasterPageViewModelIsClosed()
{
CreateViewModel();
viewModel.OpenSelectMasterPageView();
viewModel.SelectMasterPageCommand.Execute(null);
bool open = viewModel.IsSelectMasterPageViewOpen;
Assert.IsFalse(open);
}
[Test]
public void SelectMasterPageCommand_Executed_IsSelectMasterPageViewOpenPropertyChanged()
{
CreateViewModel();
viewModel.OpenSelectMasterPageView();
MonitorPropertyChangedEvents();
viewModel.SelectMasterPageCommand.Execute(null);
bool contains = propertyChangedEvents.Contains("IsSelectMasterPageViewOpen");
Assert.IsTrue(contains);
}
[Test]
public void SelectMasterPage_MasterPageSelected_MasterPageFileNameUpdated()
{
CreateViewModel();
viewModel.MasterPageFile = "test.master";
viewModel.OpenSelectMasterPageView();
var masterPageFileName = new MvcMasterPageFileName() {
FullPath = @"d:\projects\MyProject\Views\Shared\site.master",
FileName = "site.master",
FolderRelativeToProject = @"Views\Shared",
VirtualPath = "~/Views/Shared/site.master"
};
viewModel.SelectedMasterPage = masterPageFileName;
viewModel.SelectMasterPage();
string updatedMasterPageFile = viewModel.MasterPageFile;
Assert.AreEqual("~/Views/Shared/site.master", updatedMasterPageFile);
}
[Test]
public void SelectMasterPage_MasterPageSelected_MasterPageFilePropertyChangedEventFired()
{
CreateViewModel();
viewModel.OpenSelectMasterPageView();
var masterPageFileName = new MvcMasterPageFileName();
viewModel.SelectedMasterPage = masterPageFileName;
MonitorPropertyChangedEvents();
viewModel.SelectMasterPage();
bool fired = propertyChangedEvents.Contains("MasterPageFile");
Assert.IsTrue(fired);
}
}
}

40
src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/BooleanToVisibilityConverterTests.cs

@ -84,5 +84,45 @@ namespace AspNet.Mvc.Tests @@ -84,5 +84,45 @@ namespace AspNet.Mvc.Tests
Assert.IsFalse(value);
}
[Test]
public void Convert_FalseWithIsReversedSetToTrue_ReturnsVisible()
{
CreateConverter();
converter.IsReversed = true;
Visibility visibility = Convert(false);
Assert.AreEqual(Visibility.Visible, visibility);
}
[Test]
public void Convert_TrueWithIsReversedSetToTrue_ReturnsCollapsed()
{
CreateConverter();
converter.IsReversed = true;
Visibility visibility = Convert(true);
Assert.AreEqual(Visibility.Collapsed, visibility);
}
[Test]
public void ConvertBack_VisibleWithIsReversedSetToTrue_ReturnsFalse()
{
CreateConverter();
converter.IsReversed = true;
bool value = ConvertBack(Visibility.Visible);
Assert.IsFalse(value);
}
[Test]
public void ConvertBack_CollapsedWithIsReversedSetToTrue_ReturnsTrue()
{
CreateConverter();
converter.IsReversed = true;
bool value = ConvertBack(Visibility.Collapsed);
Assert.IsTrue(value);
}
}
}

86
src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/MvcMasterPageFileNameTests.cs

@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
namespace AspNet.Mvc.Tests
{
[TestFixture]
public class MvcMasterPageFileNameTests
{
TestableProject project;
MvcMasterPageFileName masterPageFileName;
void CreateProject(string fileName)
{
project = TestableProject.CreateProject(fileName, "MyProject");
}
void CreateMasterPageFileName(string fullPath)
{
var projectItem = new FileProjectItem(project, ItemType.Compile);
projectItem.FileName = fullPath;
masterPageFileName = new MvcMasterPageFileName(projectItem);
}
[Test]
public void FullPath_CreatedFromFileProjectItem_ReturnsFullFileNameIncludingFolder()
{
CreateProject(@"d:\projects\MyProject\MyProject.csproj");
string expectedFullPath = @"d:\projects\MyProject\Views\Shared\Site.Master";
CreateMasterPageFileName(expectedFullPath);
string fullPath = masterPageFileName.FullPath;
Assert.AreEqual(expectedFullPath, fullPath);
}
[Test]
public void FileName_CreatedFromFileProjectItem_ReturnsFileNameWithoutFolder()
{
CreateProject(@"d:\projects\MyProject\MyProject.csproj");
CreateMasterPageFileName(@"d:\projects\MyProject\Views\Shared\Site.Master");
string fileName = masterPageFileName.FileName;
Assert.AreEqual("Site.Master", fileName);
}
[Test]
public void FolderRelativeToProject_CreatedFromFileProjectItem_ReturnsFileNameWithoutFolder()
{
CreateProject(@"d:\projects\MyProject\MyProject.csproj");
CreateMasterPageFileName(@"d:\projects\MyProject\Views\Shared\Site.Master");
string folder = masterPageFileName.FolderRelativeToProject;
Assert.AreEqual(@"Views\Shared", folder);
}
[Test]
public void VirtualPath_CreatedFromFileProjectItem_ReturnsAspNetVirtualPathForFileName()
{
CreateProject(@"d:\projects\MyProject\MyProject.csproj");
CreateMasterPageFileName(@"d:\projects\MyProject\Views\Shared\Site.Master");
string virtualPath = masterPageFileName.VirtualPath;
Assert.AreEqual("~/Views/Shared/Site.Master", virtualPath);
}
[Test]
public void VirtualPath_FileInProjectRootDirectory_ReturnsAspNetVirtualPathForFileName()
{
CreateProject(@"d:\projects\MyProject\MyProject.csproj");
CreateMasterPageFileName(@"d:\projects\MyProject\Site.Master");
string virtualPath = masterPageFileName.VirtualPath;
Assert.AreEqual("~/Site.Master", virtualPath);
}
}
}

91
src/AddIns/BackendBindings/AspNet.Mvc/Test/Src/MvcProjectTests.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using AspNet.Mvc.Tests.Helpers;
using ICSharpCode.AspNet.Mvc;
@ -19,11 +20,28 @@ namespace AspNet.Mvc.Tests @@ -19,11 +20,28 @@ namespace AspNet.Mvc.Tests
void CreateProject()
{
testableProject = TestableProject.CreateProject();
CreateProject(@"d:\projects\MyProject\MyProject.csproj");
}
void CreateProject(string fileName)
{
testableProject = TestableProject.CreateProject(fileName, "MyProject");
fakeModelClassLocator = new FakeMvcModelClassLocator();
project = new MvcProject(testableProject, fakeModelClassLocator);
}
void AddFileToProject(string fileName)
{
testableProject.AddFileToProject(fileName);
}
List<MvcMasterPageFileName> GetAspxMasterPageFileNames()
{
return new List<MvcMasterPageFileName>(
project.GetAspxMasterPageFileNames()
);
}
[Test]
public void Project_ProjectPassedToConstructor_ReturnsProjectPassedToConstructor()
{
@ -105,5 +123,76 @@ namespace AspNet.Mvc.Tests @@ -105,5 +123,76 @@ namespace AspNet.Mvc.Tests
Assert.AreEqual(project, fakeModelClassLocator.ProjectPassedToGetModelClasses);
}
[Test]
public void GetAspxMasterPageFileNames_OneMasterPageInProject_ReturnsOneFileName()
{
CreateProject(@"d:\projects\AspNetMvcProject\MyProject.csproj");
AddFileToProject(@"d:\projects\AspNetMvcProject\Views\Shared\Site.Master");
List<MvcMasterPageFileName> fileNames = GetAspxMasterPageFileNames();
Assert.AreEqual(1, fileNames.Count);
}
[Test]
public void GetAspxMasterPageFileNames_OneMasterPageInProject_ReturnsOneMasterPageWithExpectedFileName()
{
CreateProject(@"d:\projects\AspNetMvcProject\MyProject.csproj");
AddFileToProject(@"d:\projects\AspNetMvcProject\Views\Shared\Site.Master");
MvcMasterPageFileName fileName = GetAspxMasterPageFileNames().First();
var expectedFileName = new MvcMasterPageFileName() {
FullPath = @"d:\projects\AspNetMvcProject\Views\Shared\Site.Master",
FileName = "Site.Master",
FolderRelativeToProject = @"Views\Shared"
};
MvcMasterPageFileNameAssert.AreEqual(expectedFileName, fileName);
}
[Test]
public void GetAspxMasterPageFileNames_OneHtmlFileAndOneMasterPageInProject_ReturnsOneMasterPageWithExpectedFileName()
{
CreateProject(@"d:\projects\AspNetMvcProject\MyProject.csproj");
AddFileToProject(@"d:\projects\AspNetMvcProject\Views\Shared\test.html");
AddFileToProject(@"d:\projects\AspNetMvcProject\Views\Shared\Site.Master");
List<MvcMasterPageFileName> fileNames = GetAspxMasterPageFileNames();
var expectedFileName = new MvcMasterPageFileName() {
FullPath = @"d:\projects\AspNetMvcProject\Views\Shared\Site.Master",
FileName = "Site.Master",
FolderRelativeToProject = @"Views\Shared"
};
var expectedFileNames = new MvcMasterPageFileName[] {
expectedFileName
};
MvcMasterPageFileNameCollectionAssert.AreEqual(expectedFileNames, fileNames);
}
[Test]
public void GetAspxMasterPageFileNames_OneMasterPageWithFileExtensionInUpperCaseInProject_ReturnsOneMasterPageWithExpectedFileName()
{
CreateProject(@"d:\projects\AspNetMvcProject\MyProject.csproj");
AddFileToProject(@"d:\projects\AspNetMvcProject\Views\Shared\TEST.MASTER");
MvcMasterPageFileName fileName = GetAspxMasterPageFileNames().First();
var expectedFileName = new MvcMasterPageFileName() {
FullPath = @"d:\projects\AspNetMvcProject\Views\Shared\TEST.MASTER",
FileName = "TEST.MASTER",
FolderRelativeToProject = @"Views\Shared"
};
MvcMasterPageFileNameAssert.AreEqual(expectedFileName, fileName);
}
[Test]
public void IsMvcMasterPage_NullFileNamePassed_ReturnsFalse()
{
bool result = MvcMasterPageFileName.IsMasterPageFileName(null);
Assert.IsFalse(result);
}
}
}

Loading…
Cancel
Save