Browse Source

Implement advanced options for generating service references.

pull/6/merge
Matt Ward 14 years ago
parent
commit
2513d08f9f
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 9
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs
  3. 76
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs
  4. 2
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs
  5. 2
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs
  6. 8
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs
  7. 1
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs
  8. 2
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs
  9. 116
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs
  10. 3
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs
  11. 21
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs
  12. 22
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs
  13. 4
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs
  14. 1
      src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
  15. 19
      src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs
  16. 75
      src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorOptionsTests.cs
  17. 52
      src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -292,7 +292,6 @@ @@ -292,7 +292,6 @@
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceProxyGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilCommandLine.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilMessageView.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilOptions.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilPath.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilRunner.cs" />
<Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.cs" />

9
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs

@ -37,6 +37,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -37,6 +37,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
List<string> mruServices = new List<string>();
string selectedService;
IProject project;
ServiceReferenceGenerator serviceGenerator;
List<ServiceItem> items = new List <ServiceItem>();
ServiceItem myItem;
@ -53,6 +54,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -53,6 +54,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public AddServiceReferenceViewModel(IProject project)
{
this.project = project;
this.serviceGenerator = new ServiceReferenceGenerator(project);
discoverButtonContent = "Discover";
HeadLine = header1 + header2;
@ -114,10 +116,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -114,10 +116,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
void ExecuteAdvancedDialogCommand()
{
var vm = new AdvancedServiceViewModel();
var vm = new AdvancedServiceViewModel(serviceGenerator.Options.Clone());
var view = new AdvancedServiceDialog();
view.DataContext = vm;
view.ShowDialog();
if (view.ShowDialog() ?? false) {
serviceGenerator.Options = vm.Options;
}
}
#endregion
@ -376,7 +380,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -376,7 +380,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public void AddServiceReference()
{
var serviceGenerator = new ServiceReferenceGenerator(project);
serviceGenerator.Options.Namespace = defaultNameSpace;
serviceGenerator.Options.Url = discoveryUri.ToString();
serviceGenerator.AddServiceReference();

76
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AdvancedServiceViewModel.cs

@ -39,14 +39,23 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -39,14 +39,23 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public enum DictionaryCollectionTypes
{
[Description("System.Collections.Generic.Dictionary")]
Dictionary,
[Description("System.Collections.Generic.SortedList")]
SortedList,
[Description("System.Collections.Generic.SortedDictionary")]
SortedDictionary,
[Description("System.Collections.Hashtable")]
HashTable,
[Description("System.Collections.ObjectModel.KeyedCollection")]
KeyedCollection,
[Description("System.Collections.SortedList")]
SortedList_2,
[Description("System.Collections.Specialized.HybridDictionary")]
HybridDictionary,
[Description("System.Collections.Specialized.ListDictionary")]
ListDictionary,
[Description("System.Collections.Specialized.OrderedDictionary")]
OrderedDictionary
}
@ -55,10 +64,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -55,10 +64,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
string compatibilityText = "Add a Web Reference instead of a Service Reference. ";
string c_2 = "This will generate code based on .NET Framework 2.0 Web Services technology.";
string accesslevel = "Access level for generated classes:";
ServiceReferenceGeneratorOptions options;
public AdvancedServiceViewModel()
public AdvancedServiceViewModel(ServiceReferenceGeneratorOptions options)
{
Title ="Service Reference Settings";
this.options = options;
UpdateSettingsFromOptions();
Title = "Service Reference Settings";
UseReferencedAssemblies = true;
BitmapSource image = PresentationResourceService.GetBitmapSource("Icons.16x16.Reference");
AssembliesToReference = new ObservableCollection<CheckableImageAndDescription>();
@ -73,6 +85,36 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -73,6 +85,36 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
AssembliesToReference.Add(new CheckableImageAndDescription(image, "System.Xml.Linq"));
}
public ServiceReferenceGeneratorOptions Options {
get { return options; }
}
void UpdateSettingsFromOptions()
{
UpdateSelectedModifier();
UpdateReferencedTypes();
}
void UpdateReferencedTypes()
{
if (options.UseTypesInProjectReferences) {
this.ReuseTypes = true;
this.UseReferencedAssemblies = true;
} else {
this.ReuseTypes = false;
this.UseReferencedAssemblies = false;
}
}
void UpdateSelectedModifier()
{
if (options.GenerateInternalClasses) {
SelectedModifier = Modifiers.Internal;
} else {
SelectedModifier = Modifiers.Public;
}
}
public string Title { get; set; }
public string AccessLevel {
@ -89,42 +131,34 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -89,42 +131,34 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
}
}
bool generateAsyncOperations;
public bool GenerateAsyncOperations {
get { return generateAsyncOperations; }
get { return options.GenerateAsyncOperations; }
set {
generateAsyncOperations = value;
options.GenerateAsyncOperations = value;
base.RaisePropertyChanged(() => GenerateAsyncOperations);
}
}
bool generateMessageContract;
public bool GenerateMessageContract {
get { return generateMessageContract; }
get { return options.GenerateMessageContract; }
set {
generateMessageContract = value;
options.GenerateMessageContract = value;
base.RaisePropertyChanged(() => GenerateMessageContract);
}
}
CollectionTypes collectionType;
public CollectionTypes CollectionType {
get { return collectionType; }
get { return options.ArrayCollectionType; }
set {
collectionType = value;
options.ArrayCollectionType = value;
base.RaisePropertyChanged(() => CollectionType);
}
}
DictionaryCollectionTypes dictionaryCollectionType;
public DictionaryCollectionTypes DictionaryCollectionType {
get { return dictionaryCollectionType; }
get { return options.DictionaryCollectionType; }
set {
dictionaryCollectionType = value;
options.DictionaryCollectionType = value;
base.RaisePropertyChanged(() => DictionaryCollectionType);
}
}
@ -140,12 +174,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -140,12 +174,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
}
}
bool reuseTypes;
public bool ReuseTypes {
get { return reuseTypes; }
get { return options.UseTypesInProjectReferences; }
set {
reuseTypes = value;
options.UseTypesInProjectReferences = value;
base.RaisePropertyChanged(() => ReuseTypes);
}
}

2
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.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;
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
@ -19,5 +20,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -19,5 +20,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
bool HasAppConfigFile();
string GetAppConfigFileName();
void AddAppConfigFile();
IEnumerable<string> GetReferences();
}
}

2
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs

@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public interface IServiceReferenceProxyGenerator
{
ServiceReferenceGeneratorOptions Options { get; }
ServiceReferenceGeneratorOptions Options { get; set; }
void GenerateProxyFile();
}
}

8
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -156,5 +157,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -156,5 +157,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
return Path.Combine(project.Directory, "app.config");
}
public IEnumerable<string> GetReferences()
{
foreach (ProjectItem item in project.GetItemsOfType(ItemType.Reference)) {
yield return item.FileName;
}
}
}
}

1
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs

@ -28,6 +28,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -28,6 +28,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public ServiceReferenceGeneratorOptions Options {
get { return proxyGenerator.Options; }
set { proxyGenerator.Options = value; }
}
public void GenerateProxyFile()

2
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs

@ -40,6 +40,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -40,6 +40,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public ServiceReferenceGeneratorOptions Options {
get { return fileGenerator.Options; }
set { fileGenerator.Options = value; }
}
public void AddServiceReference()
@ -70,6 +71,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -70,6 +71,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
Options.NoAppConfig = false;
Options.MergeAppConfig = project.HasAppConfigFile();
Options.MapProjectLanguage(project.Language);
Options.AddProjectReferencesIfUsingTypesFromProjectReferences(project.GetReferences());
fileGenerator.GenerateProxyFile();
return referenceFileName;

116
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs

@ -2,19 +2,33 @@ @@ -2,19 +2,33 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public class ServiceReferenceGeneratorOptions
{
List<string> assemblies = new List<string>();
public ServiceReferenceGeneratorOptions()
: this(new string[0])
{
}
public ServiceReferenceGeneratorOptions(IEnumerable<string> assemblies)
{
this.assemblies.AddRange(assemblies);
this.AppConfigFileName = String.Empty;
this.MergeAppConfig = false;
this.OutputFileName = String.Empty;
this.Namespace = String.Empty;
this.Language = "CS";
this.NoAppConfig = true;
this.UseTypesInProjectReferences = true;
this.ArrayCollectionType = CollectionTypes.Array;
this.DictionaryCollectionType = DictionaryCollectionTypes.Dictionary;
}
public string Namespace { get; set; }
@ -24,6 +38,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -24,6 +38,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public string AppConfigFileName { get; set; }
public bool NoAppConfig { get; set; }
public bool MergeAppConfig { get; set; }
public bool GenerateInternalClasses { get; set; }
public bool GenerateAsyncOperations { get; set; }
public bool GenerateMessageContract { get; set; }
public bool UseTypesInProjectReferences { get; set; }
public CollectionTypes ArrayCollectionType { get; set; }
public DictionaryCollectionTypes DictionaryCollectionType { get; set; }
public void MapProjectLanguage(string language)
{
@ -33,5 +53,101 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -33,5 +53,101 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
Language = "CS";
}
}
public IList<string> Assemblies {
get { return assemblies; }
}
public ServiceReferenceGeneratorOptions Clone()
{
return new ServiceReferenceGeneratorOptions(this.assemblies) {
Namespace = this.Namespace,
OutputFileName = this.OutputFileName,
Url = this.Url,
Language = this.Language,
AppConfigFileName = this.AppConfigFileName,
NoAppConfig = this.NoAppConfig,
MergeAppConfig = this.MergeAppConfig,
UseTypesInProjectReferences = this.UseTypesInProjectReferences,
ArrayCollectionType = this.ArrayCollectionType,
DictionaryCollectionType = this.DictionaryCollectionType,
GenerateInternalClasses = this.GenerateInternalClasses,
GenerateAsyncOperations = this.GenerateAsyncOperations,
GenerateMessageContract = this.GenerateMessageContract
};
}
public string GetNamespaceMapping()
{
if (Namespace != null) {
return "*," + Namespace;
}
return null;
}
public string GetArrayCollectionTypeDescription()
{
string description = GetEnumTypeDescription(ArrayCollectionType.GetType(), ArrayCollectionType.ToString());
return description + GetGenericTypeSuffix(ArrayCollectionType);
}
string GetEnumTypeDescription(Type type, string name)
{
foreach (FieldInfo field in type.GetFields()) {
if (field.IsStatic) {
if (field.Name == name) {
return GetDescription(field);
}
}
}
return null;
}
string GetDescription(FieldInfo field)
{
foreach (DescriptionAttribute attribute in field.GetCustomAttributes(typeof(DescriptionAttribute), false))
return attribute.Description;
return field.Name;
}
string GetGenericTypeSuffix(CollectionTypes type)
{
switch (type) {
case CollectionTypes.List:
case CollectionTypes.LinkedList:
case CollectionTypes.ObservableCollection:
case CollectionTypes.Collection:
case CollectionTypes.BindingList:
return "`1";
}
return String.Empty;
}
public string GetDictionaryCollectionTypeDescription()
{
string description = GetEnumTypeDescription(DictionaryCollectionType.GetType(), DictionaryCollectionType.ToString());
return description + GetGenericTypeSuffix(DictionaryCollectionType);
}
string GetGenericTypeSuffix(DictionaryCollectionTypes type)
{
switch (type) {
case DictionaryCollectionTypes.SortedList_2:
case DictionaryCollectionTypes.HashTable:
case DictionaryCollectionTypes.HybridDictionary:
case DictionaryCollectionTypes.ListDictionary:
case DictionaryCollectionTypes.OrderedDictionary:
return String.Empty;
}
return "`2";
}
public void AddProjectReferencesIfUsingTypesFromProjectReferences(IEnumerable<string> assemblies)
{
if (UseTypesInProjectReferences) {
Assemblies.AddRange(assemblies);
}
}
}
}

3
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs

@ -10,10 +10,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -10,10 +10,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public class ServiceReferenceProxyGenerator : IServiceReferenceProxyGenerator
{
SvcUtilOptions options = new SvcUtilOptions();
ServiceReferenceGeneratorOptions options = new ServiceReferenceGeneratorOptions();
public ServiceReferenceGeneratorOptions Options {
get { return options; }
set { options = value; }
}
public void GenerateProxyFile()

21
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.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.Text;
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
@ -10,7 +11,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -10,7 +11,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
StringBuilder argumentBuilder = new StringBuilder();
public SvcUtilCommandLine(SvcUtilOptions options)
public SvcUtilCommandLine(ServiceReferenceGeneratorOptions options)
{
GenerateCommandLine(options);
}
@ -18,14 +19,19 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -18,14 +19,19 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public string Command { get; set; }
public string Arguments { get; private set; }
void GenerateCommandLine(SvcUtilOptions options)
void GenerateCommandLine(ServiceReferenceGeneratorOptions options)
{
AppendIfNotEmpty("/out:", options.OutputFileName);
AppendIfNotEmpty("/namespace:", options.GetNamespaceMapping());
AppendIfNotEmpty("/o:", options.OutputFileName);
AppendIfNotEmpty("/n:", options.GetNamespaceMapping());
AppendIfNotEmpty("/language:", options.Language);
AppendIfTrue("/noConfig", options.NoAppConfig);
AppendIfTrue("/i", options.GenerateInternalClasses);
AppendIfTrue("/a", options.GenerateAsyncOperations);
AppendIfTrue("/mergeConfig", options.MergeAppConfig);
AppendIfNotEmpty("/config:", options.AppConfigFileName);
AppendIfNotEmpty("/ct:", options.GetArrayCollectionTypeDescription());
AppendIfNotEmpty("/ct:", options.GetDictionaryCollectionTypeDescription());
AppendAssemblyReferences(options.Assemblies);
AppendIfNotEmpty(options.Url);
this.Arguments = argumentBuilder.ToString();
@ -83,5 +89,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -83,5 +89,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
return text.IndexOf(' ') >= 0;
}
void AppendAssemblyReferences(IEnumerable<string> assemblies)
{
foreach (string assembly in assemblies) {
AppendIfNotEmpty("/r:", assembly);
}
}
}
}

22
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilOptions.cs

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
// 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.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public class SvcUtilOptions : ServiceReferenceGeneratorOptions
{
public SvcUtilOptions()
{
}
public string GetNamespaceMapping()
{
if (Namespace != null) {
return "*," + Namespace;
}
return null;
}
}
}

4
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs

@ -8,12 +8,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -8,12 +8,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public class SvcUtilRunner
{
public SvcUtilRunner(SvcUtilOptions options)
public SvcUtilRunner(ServiceReferenceGeneratorOptions options)
{
this.Options = options;
}
public SvcUtilOptions Options { get; private set; }
public ServiceReferenceGeneratorOptions Options { get; private set; }
public void Run()
{

1
src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

@ -101,6 +101,7 @@ @@ -101,6 +101,7 @@
<Compile Include="ServiceReferences\MSBuildBasedProjectTests.cs" />
<Compile Include="ServiceReferences\ProjectWithServiceReferencesTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceFileNameTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceGeneratorOptionsTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceGeneratorTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceMapFileTests.cs" />
<Compile Include="ServiceReferences\ServiceReferenceMapFileGeneratorTests.cs" />

19
src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs

@ -97,6 +97,12 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences @@ -97,6 +97,12 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences
ProjectService.AddProjectItem(msbuildProject, fileItem);
}
void AddGacReferenceToProject(string name)
{
var referenceItem = new ReferenceProjectItem(msbuildProject, name);
ProjectService.AddProjectItem(msbuildProject, referenceItem);
}
int CountAssemblyReferencesInMSBuildProject()
{
return msbuildProject.GetItemsOfType(ItemType.Reference).Count();
@ -369,5 +375,18 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences @@ -369,5 +375,18 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences
Assert.AreEqual(@"d:\projects\MyProject\SubFolder\app.config", fileName);
}
[Test]
public void GetReferences_ProjectHasGacReference_ReturnsGacReference()
{
CreateProjectWithMSBuildProject();
AddGacReferenceToProject("System.Xml");
IEnumerable<string> references = project.GetReferences();
string[] expectedReferences = new string[] {
"System.Xml"
};
CollectionAssert.AreEqual(expectedReferences, references);
}
}
}

75
src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorOptionsTests.cs

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
// 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 ServiceReferenceGeneratorOptionsTests
{
ServiceReferenceGeneratorOptions options;
void CreateOptions()
{
options = new ServiceReferenceGeneratorOptions();
}
[Test]
public void GetArrayCollectionTypeDescription_List_ReturnsFullyQualifiedListName()
{
CreateOptions();
options.ArrayCollectionType = CollectionTypes.List;
string text = options.GetArrayCollectionTypeDescription();
Assert.AreEqual("System.Collections.Generic.List`1", text);
}
[Test]
public void GetArrayCollectionTypeDescription_ArrayList_ReturnsFullyQualifiedArrayListName()
{
CreateOptions();
options.ArrayCollectionType = CollectionTypes.ArrayList;
string text = options.GetArrayCollectionTypeDescription();
Assert.AreEqual("System.Collections.ArrayList", text);
}
[Test]
public void GetDictionaryCollectionTypeDescription_HashTable_ReturnsFullyQualifiedHashTableName()
{
CreateOptions();
options.DictionaryCollectionType = DictionaryCollectionTypes.HashTable;
string text = options.GetDictionaryCollectionTypeDescription();
Assert.AreEqual("System.Collections.Hashtable", text);
}
[Test]
public void GetDictionaryCollectionTypeDescription_Dictionary_ReturnsFullyQualifiedDictionaryTypeName()
{
CreateOptions();
options.DictionaryCollectionType = DictionaryCollectionTypes.Dictionary;
string text = options.GetDictionaryCollectionTypeDescription();
Assert.AreEqual("System.Collections.Generic.Dictionary`2", text);
}
[Test]
public void GetDictionaryCollectionTypeDescription_GenericSortedList_ReturnsFullyQualifiedGenericSortedListName()
{
CreateOptions();
options.DictionaryCollectionType = DictionaryCollectionTypes.SortedList;
string text = options.GetDictionaryCollectionTypeDescription();
Assert.AreEqual("System.Collections.Generic.SortedList`2", text);
}
}
}

52
src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.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.ServiceModel.Description;
using ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference;
using ICSharpCode.SharpDevelop.Project;
@ -20,15 +21,16 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences @@ -20,15 +21,16 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences
ServiceReferenceFileGenerator fileGenerator;
IFileSystem fakeFileSystem;
ServiceReferenceGeneratorOptions options;
List<string> projectReferences;
void CreateGenerator()
{
options = new ServiceReferenceGeneratorOptions();
fakeProject = MockRepository.GenerateStub<IProjectWithServiceReferences>();
projectReferences = new List<string>();
fakeProject.Stub(p => p.GetReferences()).Return(projectReferences);
fakeProxyGenerator = MockRepository.GenerateStub<IServiceReferenceProxyGenerator>();
fakeProxyGenerator
.Stub(p => p.Options)
.Return(options);
fakeProxyGenerator.Options = options;
fakeReferenceMapGenerator = MockRepository.GenerateStub<IServiceReferenceMapGenerator>();
fileGenerator = new ServiceReferenceFileGenerator(fakeProxyGenerator, fakeReferenceMapGenerator);
fakeFileSystem = MockRepository.GenerateStub<IFileSystem>();
@ -110,6 +112,11 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences @@ -110,6 +112,11 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences
fakeProject.Stub(p => p.HasAppConfigFile()).Return(hasAppConfigFile);
}
void AddReferenceToProject(string reference)
{
projectReferences.Add(reference);
}
[Test]
public void AddServiceReference_GeneratesServiceReference_ProxyFileIsGenerated()
{
@ -320,5 +327,44 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences @@ -320,5 +327,44 @@ namespace ICSharpCode.SharpDevelop.Tests.ServiceReferences
Assert.IsTrue(fakeProxyGenerator.Options.MergeAppConfig);
fakeProject.AssertWasNotCalled(p => p.AddAppConfigFile());
}
[Test]
public void AddServiceReference_UseTypesInProjectReferencesIsTrue_ProjectReferencesAddedToOptions()
{
CreateGenerator();
AddProxyFileNameForServiceName("MyService");
AddMapFileNameForServiceName("MyService");
generator.Options.Namespace = "MyService";
generator.Options.UseTypesInProjectReferences = true;
AddReferenceToProject("System.Windows.Forms");
AddReferenceToProject(@"d:\projects\MyProject\lib\MyLib.dll");
generator.AddServiceReference();
string[] expectedReferences = new string[] {
"System.Windows.Forms",
@"d:\projects\MyProject\lib\MyLib.dll"
};
CollectionAssert.AreEqual(expectedReferences, fakeProxyGenerator.Options.Assemblies);
}
[Test]
public void AddServiceReference_UseTypesInProjectReferencesIsFalse_NoProjectReferencesAddedToOptions()
{
CreateGenerator();
AddProxyFileNameForServiceName("MyService");
AddMapFileNameForServiceName("MyService");
generator.Options.Namespace = "MyService";
generator.Options.UseTypesInProjectReferences = false;
AddReferenceToProject("System.Windows.Forms");
AddReferenceToProject(@"d:\projects\MyProject\lib\MyLib.dll");
generator.AddServiceReference();
Assert.AreEqual(0, fakeProxyGenerator.Options.Assemblies.Count);
}
}
}

Loading…
Cancel
Save