Skip to content

Commit

Permalink
DX-2554 Add machineSpeedEndThreshold (#48)
Browse files Browse the repository at this point in the history
* Add machineSpeedEndThreshold

* Serailized is not a word

* Weather vs whether

* Don't guess at the json ordering
  • Loading branch information
hamermike authored Apr 15, 2022
1 parent 1640f3d commit 877b7ba
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 18 deletions.
53 changes: 35 additions & 18 deletions Bandwidth.Standard/Voice/Models/MachineDetectionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MachineDetectionConfiguration
private string password;
private string fallbackUsername;
private string fallbackPassword;
private double? machineSpeechEndThreshold;
private Dictionary<string, bool> shouldSerialize = new Dictionary<string, bool>
{
{ "callbackUrl", false },
Expand Down Expand Up @@ -64,6 +65,7 @@ public MachineDetectionConfiguration()
/// <param name="password">password.</param>
/// <param name="fallbackUsername">fallbackUsername.</param>
/// <param name="fallbackPassword">fallbackPassword.</param>
/// <param name="machineSpeechEndThreshold">machineSpeechEndThreshold.</param>
public MachineDetectionConfiguration(
Models.ModeEnum? mode = null,
double? detectionTimeout = null,
Expand All @@ -78,7 +80,8 @@ public MachineDetectionConfiguration(
string username = null,
string password = null,
string fallbackUsername = null,
string fallbackPassword = null)
string fallbackPassword = null,
double? machineSpeechEndThreshold = null)
{
this.Mode = mode;
this.DetectionTimeout = detectionTimeout;
Expand Down Expand Up @@ -126,6 +129,7 @@ public MachineDetectionConfiguration(
this.FallbackPassword = fallbackPassword;
}

this.MachineSpeechEndThreshold = machineSpeechEndThreshold;
}

/// <summary>
Expand Down Expand Up @@ -308,6 +312,12 @@ public string FallbackPassword
}
}

/// <summary>
/// When an answering machine is detected, the amount of silence (in seconds) before assuming the message has finished playing.
/// </summary>
[JsonProperty("machineSpeechEndThreshold", NullValueHandling = NullValueHandling.Ignore)]
public double? MachineSpeechEndThreshold;

/// <inheritdoc/>
public override string ToString()
{
Expand All @@ -319,63 +329,63 @@ public override string ToString()
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetCallbackUrl()
{
this.shouldSerialize["callbackUrl"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetCallbackMethod()
{
this.shouldSerialize["callbackMethod"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetFallbackUrl()
{
this.shouldSerialize["fallbackUrl"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetFallbackMethod()
{
this.shouldSerialize["fallbackMethod"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetUsername()
{
this.shouldSerialize["username"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetPassword()
{
this.shouldSerialize["password"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetFallbackUsername()
{
this.shouldSerialize["fallbackUsername"] = false;
}

/// <summary>
/// Marks the field to not be serailized.
/// Marks the field to not be serialized.
/// </summary>
public void UnsetFallbackPassword()
{
Expand All @@ -385,7 +395,7 @@ public void UnsetFallbackPassword()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeCallbackUrl()
{
return this.shouldSerialize["callbackUrl"];
Expand All @@ -394,7 +404,7 @@ public bool ShouldSerializeCallbackUrl()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeCallbackMethod()
{
return this.shouldSerialize["callbackMethod"];
Expand All @@ -403,7 +413,7 @@ public bool ShouldSerializeCallbackMethod()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeFallbackUrl()
{
return this.shouldSerialize["fallbackUrl"];
Expand All @@ -412,7 +422,7 @@ public bool ShouldSerializeFallbackUrl()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeFallbackMethod()
{
return this.shouldSerialize["fallbackMethod"];
Expand All @@ -421,7 +431,7 @@ public bool ShouldSerializeFallbackMethod()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeUsername()
{
return this.shouldSerialize["username"];
Expand All @@ -430,7 +440,7 @@ public bool ShouldSerializeUsername()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializePassword()
{
return this.shouldSerialize["password"];
Expand All @@ -439,7 +449,7 @@ public bool ShouldSerializePassword()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeFallbackUsername()
{
return this.shouldSerialize["fallbackUsername"];
Expand All @@ -448,7 +458,7 @@ public bool ShouldSerializeFallbackUsername()
/// <summary>
/// Checks if the field should be serialized or not.
/// </summary>
/// <returns>A boolean weather the field should be serialized or not.</returns>
/// <returns>A boolean whether the field should be serialized or not.</returns>
public bool ShouldSerializeFallbackPassword()
{
return this.shouldSerialize["fallbackPassword"];
Expand Down Expand Up @@ -481,7 +491,8 @@ public override bool Equals(object obj)
((this.Username == null && other.Username == null) || (this.Username?.Equals(other.Username) == true)) &&
((this.Password == null && other.Password == null) || (this.Password?.Equals(other.Password) == true)) &&
((this.FallbackUsername == null && other.FallbackUsername == null) || (this.FallbackUsername?.Equals(other.FallbackUsername) == true)) &&
((this.FallbackPassword == null && other.FallbackPassword == null) || (this.FallbackPassword?.Equals(other.FallbackPassword) == true));
((this.FallbackPassword == null && other.FallbackPassword == null) || (this.FallbackPassword?.Equals(other.FallbackPassword) == true)) &&
((this.MachineSpeechEndThreshold == null && other.MachineSpeechEndThreshold == null) || (this.MachineSpeechEndThreshold?.Equals(other.MachineSpeechEndThreshold) == true));
}

/// <inheritdoc/>
Expand Down Expand Up @@ -559,6 +570,11 @@ public override int GetHashCode()
hashCode += this.FallbackPassword.GetHashCode();
}

if (this.MachineSpeechEndThreshold != null)
{
hashCode += this.MachineSpeechEndThreshold.GetHashCode();
}

return hashCode;
}

Expand All @@ -582,6 +598,7 @@ protected void ToString(List<string> toStringOutput)
toStringOutput.Add($"this.Password = {(this.Password == null ? "null" : this.Password == string.Empty ? "" : this.Password)}");
toStringOutput.Add($"this.FallbackUsername = {(this.FallbackUsername == null ? "null" : this.FallbackUsername == string.Empty ? "" : this.FallbackUsername)}");
toStringOutput.Add($"this.FallbackPassword = {(this.FallbackPassword == null ? "null" : this.FallbackPassword == string.Empty ? "" : this.FallbackPassword)}");
toStringOutput.Add($"this.MachineSpeechEndThreshold = {(this.MachineSpeechEndThreshold == null ? "null" : this.MachineSpeechEndThreshold.ToString())}");
}
}
}
99 changes: 99 additions & 0 deletions Bandwidth.StandardTests/Voice/ModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Bandwidth.Standard.Voice.Models;
using Newtonsoft.Json;
using Xunit;

namespace Bandwidth.StandardTests.Voice
{
public class ModelTests
{
[Fact]
public void PopulateMachineDetectionConfiguration()
{
var machineDetectionConfiguration = new MachineDetectionConfiguration
{
Mode = ModeEnum.Async,
DetectionTimeout = 3.2,
SilenceTimeout = 5.6,
SpeechThreshold = 1.2,
SpeechEndThreshold = 7.6,
DelayResult = false,
CallbackUrl = "https://www.example.com/",
CallbackMethod = CallbackMethodEnum.GET,
FallbackUrl = "https://www.example-fallback.com/",
FallbackMethod = FallbackMethodEnum.GET,
Username = "neato-username",
Password = "neato-password",
FallbackUsername = "neato-username-fallback",
FallbackPassword = "neato-password-fallback",
MachineSpeechEndThreshold = 3.4
};

Assert.Equal(ModeEnum.Async, machineDetectionConfiguration.Mode);
Assert.Equal(3.2, machineDetectionConfiguration.DetectionTimeout);
Assert.Equal(5.6, machineDetectionConfiguration.SilenceTimeout);
Assert.Equal(1.2, machineDetectionConfiguration.SpeechThreshold);
Assert.Equal(7.6, machineDetectionConfiguration.SpeechEndThreshold);
Assert.False(machineDetectionConfiguration.DelayResult);
Assert.Equal("https://www.example.com/", machineDetectionConfiguration.CallbackUrl);
Assert.Equal(CallbackMethodEnum.GET, machineDetectionConfiguration.CallbackMethod);
Assert.Equal("https://www.example-fallback.com/", machineDetectionConfiguration.FallbackUrl);
Assert.Equal(FallbackMethodEnum.GET, machineDetectionConfiguration.FallbackMethod);
Assert.Equal("neato-username", machineDetectionConfiguration.Username);
Assert.Equal("neato-password", machineDetectionConfiguration.Password);
Assert.Equal("neato-username-fallback", machineDetectionConfiguration.FallbackUsername);
Assert.Equal("neato-password-fallback", machineDetectionConfiguration.FallbackPassword);
Assert.Equal(3.4, machineDetectionConfiguration.MachineSpeechEndThreshold);
}

[Fact]
public void SerializeMachineDetectionConfiguration()
{
var machineDetectionConfiguration = new MachineDetectionConfiguration
{
Mode = ModeEnum.Async,
DetectionTimeout = 3.2,
SilenceTimeout = 5.6,
SpeechThreshold = 1.2,
SpeechEndThreshold = 7.6,
DelayResult = false,
CallbackUrl = "https://www.example.com/",
CallbackMethod = CallbackMethodEnum.GET,
FallbackUrl = "https://www.example-fallback.com/",
FallbackMethod = FallbackMethodEnum.GET,
Username = "neato-username",
Password = "neato-password",
FallbackUsername = "neato-username-fallback",
FallbackPassword = "neato-password-fallback",
MachineSpeechEndThreshold = 3.4
};

var json = JsonConvert.SerializeObject(machineDetectionConfiguration);
Assert.Equal("{\"machineSpeechEndThreshold\":3.4,\"mode\":\"async\",\"detectionTimeout\":3.2,\"silenceTimeout\":5.6,\"speechThreshold\":1.2,\"speechEndThreshold\":7.6,\"delayResult\":false,\"callbackUrl\":\"https://www.example.com/\",\"callbackMethod\":\"GET\",\"fallbackUrl\":\"https://www.example-fallback.com/\",\"fallbackMethod\":\"GET\",\"username\":\"neato-username\",\"password\":\"neato-password\",\"fallbackUsername\":\"neato-username-fallback\",\"fallbackPassword\":\"neato-password-fallback\"}", json);
}

[Fact]
public void SerializeMachineDetectionConfigurationUnsetMachineSpeechEndThreshold()
{
var machineDetectionConfiguration = new MachineDetectionConfiguration
{
Mode = ModeEnum.Async,
DetectionTimeout = 3.2,
SilenceTimeout = 5.6,
SpeechThreshold = 1.2,
SpeechEndThreshold = 7.6,
DelayResult = false,
CallbackUrl = "https://www.example.com/",
CallbackMethod = CallbackMethodEnum.GET,
FallbackUrl = "https://www.example-fallback.com/",
FallbackMethod = FallbackMethodEnum.GET,
Username = "neato-username",
Password = "neato-password",
FallbackUsername = "neato-username-fallback",
FallbackPassword = "neato-password-fallback"
};

var json = JsonConvert.SerializeObject(machineDetectionConfiguration);
Assert.Equal("{\"mode\":\"async\",\"detectionTimeout\":3.2,\"silenceTimeout\":5.6,\"speechThreshold\":1.2,\"speechEndThreshold\":7.6,\"delayResult\":false,\"callbackUrl\":\"https://www.example.com/\",\"callbackMethod\":\"GET\",\"fallbackUrl\":\"https://www.example-fallback.com/\",\"fallbackMethod\":\"GET\",\"username\":\"neato-username\",\"password\":\"neato-password\",\"fallbackUsername\":\"neato-username-fallback\",\"fallbackPassword\":\"neato-password-fallback\"}", json);
}
}
}

0 comments on commit 877b7ba

Please sign in to comment.