PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/AddIns/Misc/PackageManagement/Test/Src/DependentFileNameTests.cs

https://github.com/ajadex/SharpDevelop
C# | 186 lines | 133 code | 36 blank | 17 comment | 0 complexity | e57137c0682c09d6021383915c6df98f MD5 | raw file
  1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2// 
  3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4// software and associated documentation files (the "Software"), to deal in the Software
  5// without restriction, including without limitation the rights to use, copy, modify, merge,
  6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7// to whom the Software is furnished to do so, subject to the following conditions:
  8// 
  9// The above copyright notice and this permission notice shall be included in all copies or
 10// substantial portions of the Software.
 11// 
 12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 17// DEALINGS IN THE SOFTWARE.
 18
 19using System;
 20using ICSharpCode.Core;
 21using ICSharpCode.PackageManagement;
 22using ICSharpCode.SharpDevelop;
 23using ICSharpCode.SharpDevelop.Project;
 24using NUnit.Framework;
 25using PackageManagement.Tests.Helpers;
 26
 27namespace PackageManagement.Tests
 28{
 29	[TestFixture]
 30	public class DependentFileTests
 31	{
 32		TestableProject project;
 33		DependentFile dependentFile;
 34		
 35		void CreateCSharpProject(string projectFileName)
 36		{
 37			project = ProjectHelper.CreateTestProject();
 38			project.FileName = new FileName(projectFileName);
 39		}
 40		
 41		FileProjectItem AddFileToProject(string include)
 42		{
 43			return project.AddFile(include);
 44		}
 45		
 46		void CreateDependentFile()
 47		{
 48			dependentFile = new DependentFile(project);
 49		}
 50		
 51		[SetUp]
 52		public void Init()
 53		{
 54			SD.InitializeForUnitTests();
 55		}
 56		
 57		[Test]
 58		public void GetParentFileProjectItem_ResxFileNameAndCSharpParentFileExistsInProject_ReturnsParentFileProjectItem()
 59		{
 60			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
 61			FileProjectItem expectedProjectItem = AddFileToProject("test.cs");
 62			CreateDependentFile();
 63			string fileName = @"d:\projects\MyProject\test.resx";
 64			
 65			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
 66			
 67			Assert.AreEqual(expectedProjectItem, projectItem);
 68		}
 69		
 70		[Test]
 71		public void GetParentFileProjectItem_ResxFileNameAndProjectHasNoFiles_ReturnsNull()
 72		{
 73			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
 74			CreateDependentFile();
 75			string fileName = @"d:\projects\MyProject\test.resx";
 76			
 77			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
 78			
 79			Assert.IsNull(projectItem);
 80		}
 81		
 82		[Test]
 83		public void GetParentFileProjectItem_ResxFileNameAndProjectHasOneCSharpFileWithDifferentFileNameToResxFile_ReturnsNull()
 84		{
 85			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
 86			AddFileToProject(@"d:\projects\MyProject\program.cs");
 87			CreateDependentFile();
 88			string fileName = @"d:\projects\MyProject\test.resx";
 89			
 90			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
 91			
 92			Assert.IsNull(projectItem);
 93		}
 94		
 95		[Test]
 96		public void GetParentFileProjectItem_ResxFileNameAndVisualBasicParentFileExistsInProject_ReturnsParentFileProjectItem()
 97		{
 98			CreateCSharpProject(@"d:\projects\MyProject\MyProject.vbproj");
 99			FileProjectItem expectedProjectItem = AddFileToProject("test.vb");
100			CreateDependentFile();
101			string fileName = @"d:\projects\MyProject\test.resx";
102			
103			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
104			
105			Assert.AreEqual(expectedProjectItem, projectItem);
106		}
107		
108		[Test]
109		public void GetParentFileProjectItem_ResxFileNameAndVisualBasicParentFileExistsInProjectWhenProjectFileExtensionIsInUpperCase_ReturnsParentFileProjectItem()
110		{
111			CreateCSharpProject(@"d:\projects\MyProject\MyProject.VBPROJ");
112			FileProjectItem expectedProjectItem = AddFileToProject("test.vb");
113			CreateDependentFile();
114			string fileName = @"d:\projects\MyProject\test.resx";
115			
116			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
117			
118			Assert.AreEqual(expectedProjectItem, projectItem);
119		}
120		
121		[Test]
122		public void GetParentFileProjectItem_DesignerFileNameAndCSharpParentFileExistsInProject_ReturnsParentFileProjectItem()
123		{
124			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
125			FileProjectItem expectedProjectItem = AddFileToProject("test.cs");
126			CreateDependentFile();
127			string fileName = @"d:\projects\MyProject\test.Designer.cs";
128			
129			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
130			
131			Assert.AreEqual(expectedProjectItem, projectItem);
132		}
133		
134		[Test]
135		public void GetParentFileProjectItem_DesignerFileNameInLowerCaseAndCSharpParentFileExistsInProject_ReturnsParentFileProjectItem()
136		{
137			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
138			FileProjectItem expectedProjectItem = AddFileToProject("test.cs");
139			CreateDependentFile();
140			string fileName = @"d:\projects\MyProject\test.designer.cs";
141			
142			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
143			
144			Assert.AreEqual(expectedProjectItem, projectItem);
145		}
146		
147		[Test]
148		public void GetParentFileProjectItem_DesignerInFileNameButMissingDot_ReturnsNull()
149		{
150			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
151			AddFileToProject("abc.cs");
152			CreateDependentFile();
153			string fileName = @"d:\projects\MyProject\abc2Designer.cs";
154			
155			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
156			
157			Assert.IsNull(projectItem);
158		}
159		
160		[Test]
161		public void GetParentFileProjectItem_DesignerInFolderName_ReturnsNull()
162		{
163			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
164			AddFileToProject("abc.cs");
165			CreateDependentFile();
166			string fileName = @"d:\projects\MyProject\abc.Designer\foo.cs";
167			
168			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
169			
170			Assert.IsNull(projectItem);
171		}
172		
173		[Test]
174		public void GetParentFileProjectItem_DesignerInFolderNameAndInFileName_ReturnsMatchingParentProjectItem()
175		{
176			CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj");
177			FileProjectItem expectedProjectItem = AddFileToProject(@"Form.Designer\abc.cs");
178			CreateDependentFile();
179			string fileName = @"d:\projects\MyProject\Form.Designer\abc.Designer.cs";
180			
181			FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName);
182			
183			Assert.AreEqual(expectedProjectItem, projectItem);
184		}
185	}
186}