From 3836c7a12c3be9e0115bd4ab6ebac7b380e47f31 Mon Sep 17 00:00:00 2001 From: Shannon Lewis Date: Wed, 13 Dec 2017 14:41:56 +1000 Subject: [PATCH 1/3] removed the extensibility package and moved the code back in here --- .../Attributes/ApiPropertyAttribute.cs | 8 +++ .../Attributes/WriteableAttribute.cs | 21 +++++++ .../ExtensionConfigurationResource.cs | 19 ++++++ source/Octopus.Client/Extensibility/Href.cs | 62 +++++++++++++++++++ .../Octopus.Client/Extensibility/IResource.cs | 14 +++++ .../Extensibility/LinkCollection.cs | 24 +++++++ source/Octopus.Client/Octopus.Client.csproj | 3 - 7 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 source/Octopus.Client/Extensibility/Attributes/ApiPropertyAttribute.cs create mode 100644 source/Octopus.Client/Extensibility/Attributes/WriteableAttribute.cs create mode 100644 source/Octopus.Client/Extensibility/Extensions/Infrastructure/Configuration/ExtensionConfigurationResource.cs create mode 100644 source/Octopus.Client/Extensibility/Href.cs create mode 100644 source/Octopus.Client/Extensibility/IResource.cs create mode 100644 source/Octopus.Client/Extensibility/LinkCollection.cs diff --git a/source/Octopus.Client/Extensibility/Attributes/ApiPropertyAttribute.cs b/source/Octopus.Client/Extensibility/Attributes/ApiPropertyAttribute.cs new file mode 100644 index 000000000..27322154a --- /dev/null +++ b/source/Octopus.Client/Extensibility/Attributes/ApiPropertyAttribute.cs @@ -0,0 +1,8 @@ +using System; + +namespace Octopus.Client.Extensibility.Attributes +{ + public abstract class ApiPropertyAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Extensibility/Attributes/WriteableAttribute.cs b/source/Octopus.Client/Extensibility/Attributes/WriteableAttribute.cs new file mode 100644 index 000000000..e86e515aa --- /dev/null +++ b/source/Octopus.Client/Extensibility/Attributes/WriteableAttribute.cs @@ -0,0 +1,21 @@ +using System; + +namespace Octopus.Client.Extensibility.Attributes +{ + /// + /// Properties with this attribute will be persisted to the server when sent using a POST or PUT request. + /// + [AttributeUsage(AttributeTargets.Property)] + public class WriteableAttribute : ApiPropertyAttribute + { + } + + /// + /// Properties with this attribute will be persisted to the server when sent using a POST request. + /// + [AttributeUsage(AttributeTargets.Property)] + public class WriteableOnCreateAttribute : ApiPropertyAttribute + { + } + +} \ No newline at end of file diff --git a/source/Octopus.Client/Extensibility/Extensions/Infrastructure/Configuration/ExtensionConfigurationResource.cs b/source/Octopus.Client/Extensibility/Extensions/Infrastructure/Configuration/ExtensionConfigurationResource.cs new file mode 100644 index 000000000..b1e6d3e56 --- /dev/null +++ b/source/Octopus.Client/Extensibility/Extensions/Infrastructure/Configuration/ExtensionConfigurationResource.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using Octopus.Client.Extensibility.Attributes; + +namespace Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration +{ + public abstract class ExtensionConfigurationResource: IResource + { + public string Id { get; set; } + + [DisplayName("Is Enabled")] + [Description("Whether or not this extension is enabled")] + [Required] + [Writeable] + public bool IsEnabled { get; set; } + + public LinkCollection Links { get; set; } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Extensibility/Href.cs b/source/Octopus.Client/Extensibility/Href.cs new file mode 100644 index 000000000..b4e0e4780 --- /dev/null +++ b/source/Octopus.Client/Extensibility/Href.cs @@ -0,0 +1,62 @@ +using System; + +namespace Octopus.Client.Extensibility +{ + public class Href : IEquatable + { + readonly string link; + + public Href(string link) + { + this.link = link; + } + + public string AsString() + { + return link; + } + + public bool Equals(Href other) + { + return string.Equals(link, other.link); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Href)obj); + } + + public override int GetHashCode() + { + return (link != null ? link.GetHashCode() : 0); + } + + public override string ToString() + { + return link; + } + + public static bool operator ==(Href left, Href right) + { + return Equals(left, right); + } + + public static bool operator !=(Href left, Href right) + { + return !Equals(left, right); + } + + public static implicit operator String(Href href) + { + return href.link; + } + + public static implicit operator Href(string href) + { + return new Href(href); + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Extensibility/IResource.cs b/source/Octopus.Client/Extensibility/IResource.cs new file mode 100644 index 000000000..cf8b02aac --- /dev/null +++ b/source/Octopus.Client/Extensibility/IResource.cs @@ -0,0 +1,14 @@ +namespace Octopus.Client.Extensibility +{ + public interface IResource + { + string Id { get; } + + LinkCollection Links { get; set; } + } + + public interface INamedResource + { + string Name { get; } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Extensibility/LinkCollection.cs b/source/Octopus.Client/Extensibility/LinkCollection.cs new file mode 100644 index 000000000..33258510f --- /dev/null +++ b/source/Octopus.Client/Extensibility/LinkCollection.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace Octopus.Client.Extensibility +{ + public class LinkCollection : Dictionary + { + public LinkCollection() + : base(StringComparer.OrdinalIgnoreCase) + { + } + + public new LinkCollection Add(string name, Href value) + { + base.Add(name, value); + return this; + } + + public static LinkCollection Self(Href self) + { + return new LinkCollection().Add("Self", self); + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Octopus.Client.csproj b/source/Octopus.Client/Octopus.Client.csproj index 64bdacdc1..7674d5317 100644 --- a/source/Octopus.Client/Octopus.Client.csproj +++ b/source/Octopus.Client/Octopus.Client.csproj @@ -53,7 +53,4 @@ This package contains the client library for the HTTP API in Octopus. - - - \ No newline at end of file From 86f4e1d07caa0b4b72a572ec4e9cb4736117367d Mon Sep 17 00:00:00 2001 From: Shannon Lewis Date: Wed, 13 Dec 2017 14:57:21 +1000 Subject: [PATCH 2/3] fixed tests --- .../Conventions/ClientConventions.cs | 2 +- ...houldNotRegress..NETFramework.approved.txt | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/source/Octopus.Client.Tests/Conventions/ClientConventions.cs b/source/Octopus.Client.Tests/Conventions/ClientConventions.cs index 50f196ccb..d68d9950e 100644 --- a/source/Octopus.Client.Tests/Conventions/ClientConventions.cs +++ b/source/Octopus.Client.Tests/Conventions/ClientConventions.cs @@ -40,7 +40,7 @@ public class ClientConventions .ToArray(); private static readonly TypeInfo[] ResourceTypes = ExportedTypes - .Where(t => t.Name.EndsWith("Resource")) + .Where(t => !t.IsInterface && !t.IsAbstract && t.Name.EndsWith("Resource")) .ToArray(); private static readonly TypeInfo[] RepositoryResourceTypes = ResourceTypes diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index d2202ed70..583b8f6f4 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -935,6 +935,75 @@ Octopus.Client.Exceptions .ctor(String) } } +Octopus.Client.Extensibility +{ + class Href + IEquatable + { + .ctor(String) + String AsString() + Boolean Equals(Octopus.Client.Extensibility.Href) + Boolean Equals(Object) + Int32 GetHashCode() + String ToString() + } + interface INamedResource + { + String Name { get; } + } + interface IResource + { + String Id { get; } + Octopus.Client.Extensibility.LinkCollection Links { get; set; } + } + class LinkCollection + IDictionary + ICollection> + IEnumerable> + IEnumerable + IDictionary + ICollection + IReadOnlyDictionary + IReadOnlyCollection> + ISerializable + IDeserializationCallback + Dictionary + { + .ctor() + Octopus.Client.Extensibility.LinkCollection Add(String, Octopus.Client.Extensibility.Href) + static Octopus.Client.Extensibility.LinkCollection Self(Octopus.Client.Extensibility.Href) + } +} +Octopus.Client.Extensibility.Attributes +{ + abstract class ApiPropertyAttribute + _Attribute + Attribute + { + } + class WriteableAttribute + _Attribute + Octopus.Client.Extensibility.Attributes.ApiPropertyAttribute + { + .ctor() + } + class WriteableOnCreateAttribute + _Attribute + Octopus.Client.Extensibility.Attributes.ApiPropertyAttribute + { + .ctor() + } +} +Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration +{ + abstract class ExtensionConfigurationResource + Octopus.Client.Extensibility.IResource + { + String Id { get; set; } + Boolean IsEnabled { get; set; } + Octopus.Client.Extensibility.LinkCollection Links { get; set; } + } +} Octopus.Client.Extensions { abstract class StringExtensions From 27dd5842f5a2a7693fe1c8995078bb9f7198d8c1 Mon Sep 17 00:00:00 2001 From: Shannon Lewis Date: Wed, 13 Dec 2017 15:03:33 +1000 Subject: [PATCH 3/3] another test fix --- ...AreaShouldNotRegress..NETCore.approved.txt | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index d819144a6..68bdbad45 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -541,6 +541,72 @@ Octopus.Client.Exceptions .ctor(String) } } +Octopus.Client.Extensibility +{ + class Href + IEquatable + { + .ctor(String) + String AsString() + Boolean Equals(Octopus.Client.Extensibility.Href) + Boolean Equals(Object) + Int32 GetHashCode() + String ToString() + } + interface INamedResource + { + String Name { get; } + } + interface IResource + { + String Id { get; } + Octopus.Client.Extensibility.LinkCollection Links { get; set; } + } + class LinkCollection + IDictionary + ICollection> + IEnumerable> + IEnumerable + IDictionary + ICollection + IReadOnlyDictionary + IReadOnlyCollection> + ISerializable + IDeserializationCallback + Dictionary + { + .ctor() + Octopus.Client.Extensibility.LinkCollection Add(String, Octopus.Client.Extensibility.Href) + static Octopus.Client.Extensibility.LinkCollection Self(Octopus.Client.Extensibility.Href) + } +} +Octopus.Client.Extensibility.Attributes +{ + abstract class ApiPropertyAttribute + Attribute + { + } + class WriteableAttribute + Octopus.Client.Extensibility.Attributes.ApiPropertyAttribute + { + .ctor() + } + class WriteableOnCreateAttribute + Octopus.Client.Extensibility.Attributes.ApiPropertyAttribute + { + .ctor() + } +} +Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration +{ + abstract class ExtensionConfigurationResource + Octopus.Client.Extensibility.IResource + { + String Id { get; set; } + Boolean IsEnabled { get; set; } + Octopus.Client.Extensibility.LinkCollection Links { get; set; } + } +} Octopus.Client.Extensions { abstract class StringExtensions