Skip to content

Commit

Permalink
Merge pull request #127 from OctopusDeploy/bug-stringCommunicationStyle
Browse files Browse the repository at this point in the history
Some older Tentacles have a string as the CommunicationStyle. This re-adds support for this.
  • Loading branch information
droyad authored Jun 26, 2019
2 parents c81b966 + 0596749 commit 844acd0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,22 @@ public void CommunicationStyleRoundtripsCorrectly()
var result = JsonConvert.DeserializeObject<OctopusServerConfiguration>(json, settings);
result.CommunicationStyle.Should().Be(CommunicationStyle.TentacleActive);
}


[Test]
public void CommunicationStyleAsStringCanBeRead()
{
var settings = GetSettings();
var result = JsonConvert.DeserializeObject<OctopusServerConfiguration>(@"{""CommunicationStyle"": ""TentacleActive"", ""Thumbprint"": ""A""}", settings);
result.CommunicationStyle.Should().Be(CommunicationStyle.TentacleActive);
}

[Test]
public void CommunicationStyleAsIntCanBeRead()
{
var settings = GetSettings();
var result = JsonConvert.DeserializeObject<OctopusServerConfiguration>(@"{""CommunicationStyle"": 2, ""Thumbprint"": ""A"" }", settings);
result.CommunicationStyle.Should().Be(CommunicationStyle.TentacleActive);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
=> writer.WriteValue((int) value);

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
=> reader.Value == null ? CommunicationStyle.None : (CommunicationStyle) Convert.ToInt32(reader.Value);
{
if (reader.Value == null)
return CommunicationStyle.None;

if (reader.Value is string str)
return Enum.Parse(typeof(CommunicationStyle), str);

return (CommunicationStyle) Convert.ToInt32(reader.Value);
}

public override bool CanConvert(Type objectType)
=> objectType == typeof(CommunicationStyle);
Expand Down

0 comments on commit 844acd0

Please sign in to comment.