Permalink
Browse files

Move code to determine service reference folder into separate Service…

…ReferenceFileName class.
  • Loading branch information...
1 parent a0801f5 commit 8a968a390ec2d1df0fa3e8132ad5661f0e0adc7b @mrward mrward committed Dec 23, 2011
@@ -277,6 +277,7 @@
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ProjectWithServiceReferences.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceCodeDomBuilder.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceCodeDomProvider.cs" />
+ <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileName.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileSystem.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceProxyGenerator.cs" />
@@ -10,8 +10,8 @@ public interface IProjectWithServiceReferences
string ServiceReferencesFolder { get; }
ICodeDomProvider CodeDomProvider { get; }
- string GetServiceReferenceFileName(string serviceReferenceName);
- void AddServiceReferenceProxyFile(string fileName);
+ ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName);
+ void AddServiceReferenceProxyFile(ServiceReferenceFileName fileName);
void Save();
}
}
@@ -42,22 +42,22 @@ void GetServiceReferencesFolder()
public ICodeDomProvider CodeDomProvider { get; private set; }
- public string GetServiceReferenceFileName(string serviceReferenceName)
+ public ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName)
{
- return Path.Combine(ServiceReferencesFolder, serviceReferenceName, "Reference.cs");
+ return new ServiceReferenceFileName(ServiceReferencesFolder, serviceReferenceName);
}
- public void AddServiceReferenceProxyFile(string fileName)
+ public void AddServiceReferenceProxyFile(ServiceReferenceFileName fileName)
{
AddServiceReferenceFileToProject(fileName);
AddServiceReferencesItemToProject();
AddServiceReferenceItemToProject(fileName);
}
- void AddServiceReferenceFileToProject(string fileName)
+ void AddServiceReferenceFileToProject(ServiceReferenceFileName fileName)
{
var projectItem = new FileProjectItem(project, ItemType.Compile);
- projectItem.FileName = fileName;
+ projectItem.FileName = fileName.Path;
AddProjectItemToProject(projectItem);
}
@@ -73,12 +73,10 @@ void AddServiceReferencesItemToProject()
AddProjectItemToProject(projectItem);
}
- void AddServiceReferenceItemToProject(string fileName)
+ void AddServiceReferenceItemToProject(ServiceReferenceFileName fileName)
{
var projectItem = new ServiceReferenceProjectItem(project);
- string directory = Path.GetDirectoryName(fileName);
- string serviceName = Path.GetFileName(directory);
- projectItem.Include = serviceName;
+ projectItem.Include = fileName.ServiceName;
AddProjectItemToProject(projectItem);
}
@@ -0,0 +1,52 @@
+// 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 IO = System.IO;
+
+namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
+{
+ public class ServiceReferenceFileName
+ {
+ string serviceReferencesFolder;
+ string serviceName;
+ string path;
+
+ public ServiceReferenceFileName()
+ : this(String.Empty, String.Empty)
+ {
+ }
+
+ public ServiceReferenceFileName(
+ string serviceReferencesFolder,
+ string serviceName)
+ {
+ this.serviceReferencesFolder = serviceReferencesFolder;
+ this.serviceName = serviceName;
+ }
+
+ public string Path {
+ get {
+ if (path == null) {
+ GetPath();
+ }
+ return path;
+ }
+ }
+
+ void GetPath()
+ {
+ path = IO.Path.Combine(serviceReferencesFolder, serviceName, "Reference.cs");
+ }
+
+ public string ServiceName {
+ get { return serviceName; }
+ set { serviceName = value; }
+ }
+
+ public string ServiceReferencesFolder {
+ get { return serviceReferencesFolder; }
+ set { serviceReferencesFolder = value; }
+ }
+ }
+}
@@ -47,10 +47,10 @@ public void AddServiceReference(MetadataSet metadata)
void GenerateServiceReferenceProxy(MetadataSet metadata)
{
- string fileName = project.GetServiceReferenceFileName(Namespace);
- CreateFolderForFileIfFolderMissing(fileName);
+ ServiceReferenceFileName fileName = project.GetServiceReferenceFileName(Namespace);
+ CreateFolderForFileIfFolderMissing(fileName.Path);
- proxyGenerator.GenerateProxy(metadata, fileName);
+ proxyGenerator.GenerateProxy(metadata, fileName.Path);
project.AddServiceReferenceProxyFile(fileName);
@@ -99,6 +99,7 @@
<Compile Include="ServiceReferences\ItemTypeTests.cs" />
<Compile Include="ServiceReferences\MSBuildBasedProjectTests.cs" />
<Compile Include="ServiceReferences\ProjectWithServiceReferencesTests.cs" />
+ <Compile Include="ServiceReferences\ServiceReferenceFileNameTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceGeneratorTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceNodeTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceProxyGeneratorTests.cs" />
@@ -46,9 +46,9 @@ void SetProjectCodeDomProvider(LanguageProperties languageProperties)
fakeProject.Stub(p => p.LanguageProperties).Return(languageProperties);
}
- ProjectItem GetFirstServiceReferenceFileInMSBuildProject(string fileName)
+ ProjectItem GetFirstServiceReferenceFileInMSBuildProject(ServiceReferenceFileName fileName)
{
- return msbuildProject.Items.SingleOrDefault(item => item.FileName == fileName);
+ return msbuildProject.Items.SingleOrDefault(item => item.FileName == fileName.Path);
}
ServiceReferencesProjectItem GetFirstWCFMetadataItemInMSBuildProject()
@@ -91,18 +91,21 @@ public void GetServiceReferenceProxyFileName_ProjectHasNoServiceReferences_Retur
CreateProject();
SetProjectDirectory(@"d:\projects\MyProject");
- string fileName = project.GetServiceReferenceFileName("Service1");
+ ServiceReferenceFileName fileName = project.GetServiceReferenceFileName("Service1");
string expectedFileName = @"d:\projects\MyProject\Service References\Service1\Reference.cs";
- Assert.AreEqual(expectedFileName, fileName);
+ Assert.AreEqual(expectedFileName, fileName.Path);
}
[Test]
public void AddServiceReferenceProxyFile_ProjectHasNoServiceReferences_ProxyFileAddedToProjectAsFileToCompile()
{
CreateProjectWithMSBuildProject();
- string proxyFileName = @"d:\projects\MyProject\Service References\Service1\Reference.cs";
+ var proxyFileName = new ServiceReferenceFileName() {
+ ServiceReferencesFolder = @"d:\projects\MyProject\Service References",
+ ServiceName = "Service1"
+ };
project.AddServiceReferenceProxyFile(proxyFileName);
ProjectItem item = GetFirstServiceReferenceFileInMSBuildProject(proxyFileName);
@@ -125,7 +128,7 @@ public void AddServiceReferenceProxyFile_ProjectHasNoServiceReferences_WCFMetada
{
CreateProjectWithMSBuildProject();
- string proxyFileName = @"d:\projects\MyProject\Service References\Service1\Reference.cs";
+ var proxyFileName = new ServiceReferenceFileName() { ServiceName = "Service1" };
project.AddServiceReferenceProxyFile(proxyFileName);
ServiceReferencesProjectItem item = GetFirstWCFMetadataItemInMSBuildProject();
@@ -138,7 +141,7 @@ public void AddServiceReferenceProxyFile_ProjectHasNoServiceReferences_WCFMetada
{
CreateProjectWithMSBuildProject();
- string proxyFileName = @"d:\projects\MyProject\Service References\Service1\Reference.cs";
+ var proxyFileName = new ServiceReferenceFileName() { ServiceName = "Service1" };
project.AddServiceReferenceProxyFile(proxyFileName);
ProjectItem item = GetFirstWCFMetadataStorageItemInMSBuildProject();
@@ -0,0 +1,42 @@
+// 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.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference;
+using NUnit.Framework;
+
+namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences
+{
+ [TestFixture]
+ public class ServiceReferenceFileNameTests
+ {
+ ServiceReferenceFileName fileName;
+
+ void CreateServiceReferenceFileName(string serviceReferencesFolder, string serviceName)
+ {
+ fileName = new ServiceReferenceFileName(serviceReferencesFolder, serviceName);
+ }
+
+ [Test]
+ public void Path_NewInstanceCreated_ReturnsFullPathToFile()
+ {
+ CreateServiceReferenceFileName(@"d:\projects\MyProject\Service References", "MyService");
+
+ string path = fileName.Path;
+
+ string expectedPath = @"d:\projects\MyProject\Service References\MyService\Reference.cs";
+
+ Assert.AreEqual(expectedPath, path);
+ }
+
+ [Test]
+ public void ServiceName_NewInstanceCreated_ReturnsFullPathToFile()
+ {
+ CreateServiceReferenceFileName(@"d:\projects\MyProject\Service References", "MyService");
+
+ string serviceName = fileName.ServiceName;
+
+ Assert.AreEqual("MyService", serviceName);
+ }
+ }
+}
@@ -29,20 +29,38 @@ void CreateGenerator()
generator = new ServiceReferenceGenerator(fakeProject, fakeProxyGenerator, fakeFileSystem);
}
- void SetServiceReferenceFileName(string serviceReferenceName, string fileName)
+ void SetServiceReferenceFileName(string serviceReferenceName, ServiceReferenceFileName fileName)
{
fakeProject.Stub(p => p.GetServiceReferenceFileName(serviceReferenceName)).Return(fileName);
}
+ ServiceReferenceFileName CreateProxyFileName(string serviceReferencesFolder, string serviceName)
+ {
+ return new ServiceReferenceFileName(serviceReferencesFolder, serviceName);
+ }
+
+ ServiceReferenceFileName AddProxyFileNameForServiceName(string serviceName)
+ {
+ return AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", serviceName);
+ }
+
+ ServiceReferenceFileName AddProxyFileNameForServiceName(string serviceReferencesFolder, string serviceName)
+ {
+ ServiceReferenceFileName proxyFileName = CreateProxyFileName(serviceReferencesFolder, serviceName);
+ SetServiceReferenceFileName(serviceName, proxyFileName);
+ return proxyFileName;
+ }
+
[Test]
public void AddServiceReference_GeneratesServiceReference_MetadataPassedToProxyGenerator()
{
CreateGenerator();
- string expectedProxyFileName = @"d:\projects\MyProject\Service References\MyServiceRef\Reference.cs";
- SetServiceReferenceFileName("MyServiceRef", expectedProxyFileName);
+ ServiceReferenceFileName proxyFileName =
+ AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef");
generator.Namespace = "MyServiceRef";
generator.AddServiceReference(metadata);
+ string expectedProxyFileName = @"d:\projects\MyProject\Service References\MyServiceRef\Reference.cs";
fakeProxyGenerator.AssertWasCalled(p => p.GenerateProxy(metadata, expectedProxyFileName));
}
@@ -51,8 +69,7 @@ public void AddServiceReference_GeneratesServiceReference_MetadataPassedToProxyG
public void AddServiceReference_ServiceReferenceDoesNotExist_ServiceReferenceFolderCreated()
{
CreateGenerator();
- string proxyFileName = @"d:\projects\MyProject\Service References\MyService1\Reference.cs";
- SetServiceReferenceFileName("MyService1", proxyFileName);
+ AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyService1");
generator.Namespace = "MyService1";
generator.AddServiceReference(metadata);
@@ -66,8 +83,8 @@ public void AddServiceReference_ServiceReferenceDoesNotExist_ServiceReferenceFol
public void AddServiceReference_GeneratesServiceReference_ServiceReferenceProxyFileAddedToProject()
{
CreateGenerator();
- string expectedProxyFileName = @"d:\projects\MyProject\Service References\MyServiceRef\Reference.cs";
- SetServiceReferenceFileName("MyServiceRef", expectedProxyFileName);
+ ServiceReferenceFileName expectedProxyFileName =
+ AddProxyFileNameForServiceName(@"d:\projects\MyProject\Service References", "MyServiceRef");
generator.Namespace = "MyServiceRef";
generator.AddServiceReference(metadata);
@@ -79,6 +96,8 @@ public void AddServiceReference_GeneratesServiceReference_ServiceReferenceProxyF
public void AddServiceReference_GeneratesServiceReference_ProjectIsSaved()
{
CreateGenerator();
+ AddProxyFileNameForServiceName("MyServiceRef");
+ generator.Namespace = "MyServiceRef";
generator.AddServiceReference(metadata);

0 comments on commit 8a968a3

Please sign in to comment.