diff --git a/src/Twilio/TwiML/Fax/Receive.cs b/src/Twilio/TwiML/Fax/Receive.cs index a30217243..88dee26f9 100644 --- a/src/Twilio/TwiML/Fax/Receive.cs +++ b/src/Twilio/TwiML/Fax/Receive.cs @@ -91,7 +91,7 @@ public Receive(Uri action = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Messaging/Message.cs b/src/Twilio/TwiML/Messaging/Message.cs index 85ffda8eb..b0351532d 100644 --- a/src/Twilio/TwiML/Messaging/Message.cs +++ b/src/Twilio/TwiML/Messaging/Message.cs @@ -78,7 +78,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.To != null) diff --git a/src/Twilio/TwiML/Messaging/Redirect.cs b/src/Twilio/TwiML/Messaging/Redirect.cs index 2a7647caf..cdf2071da 100644 --- a/src/Twilio/TwiML/Messaging/Redirect.cs +++ b/src/Twilio/TwiML/Messaging/Redirect.cs @@ -49,7 +49,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Method != null) diff --git a/src/Twilio/TwiML/Text.cs b/src/Twilio/TwiML/Text.cs index 5efb4a6e6..cc6e401b7 100644 --- a/src/Twilio/TwiML/Text.cs +++ b/src/Twilio/TwiML/Text.cs @@ -1,4 +1,9 @@ -using System.Xml.Linq; +#if !NET35 +using System.Threading; +using System.Threading.Tasks; +#endif +using System.Xml; +using System.Xml.Linq; namespace Twilio.TwiML { @@ -15,5 +20,18 @@ protected override XNode ToXml() { return new XText(_content); } + +#if !NET35 + protected override async Task WriteXml(XmlWriter writer, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + await writer.WriteStringAsync(_content).ConfigureAwait(false); + } +#endif + + protected override void WriteContent(XmlWriter writer) + { + writer.WriteString(_content); + } } -} +} \ No newline at end of file diff --git a/src/Twilio/TwiML/TwiML.cs b/src/Twilio/TwiML/TwiML.cs index ec625992d..290c52caf 100644 --- a/src/Twilio/TwiML/TwiML.cs +++ b/src/Twilio/TwiML/TwiML.cs @@ -1,34 +1,28 @@ using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text; using System.Xml.Linq; -using Twilio.Exceptions; namespace Twilio.TwiML { - /// /// Base class for all TwiML Objects. /// - public class TwiML + public partial class TwiML { /// /// Tag name /// private string TagName { get; } + /// /// Children elements /// private List Children { get; } + /// /// Additional tag attributes to set on the generated xml /// - private List> Options { get; } - /// - /// Attribute names to be transformed on the generated xml - /// - private Dictionary AttributeNameMapper = new Dictionary { { "for_", "for" } }; + private List> Options { get; } /// /// Base constructor to create any TwiML instance. @@ -36,9 +30,9 @@ public class TwiML /// TwiML tag name protected TwiML(string tagName) { - this.TagName = tagName; - this.Children = new List(); - this.Options = new List>(); + TagName = tagName; + Children = new List(); + Options = new List>(); } /// @@ -52,9 +46,9 @@ protected virtual string GetElementBody() /// /// Get the TwiML element attributes. /// - protected virtual List GetElementAttributes() + protected virtual IEnumerable GetElementAttributes() { - return new List(); + return Enumerable.Empty(); } /// @@ -63,13 +57,13 @@ protected virtual List GetElementAttributes() /// Child TwiML element to add public virtual TwiML Append(TwiML childElem) { - this.Children.Add(childElem); + Children.Add(childElem); return this; } public TwiML AddText(string text) { - this.Children.Add(new Text(text)); + Children.Add(new Text(text)); return this; } @@ -79,7 +73,7 @@ public TwiML AddText(string text) /// Child TwiML element to add public T Nest(T childElem) where T : TwiML { - this.Children.Add(childElem); + Children.Add(childElem); return childElem; } @@ -89,7 +83,7 @@ public T Nest(T childElem) where T : TwiML /// TwiML tag name public TwiML AddChild(string tagName) { - return this.Nest(new TwiML(tagName)); + return Nest(new TwiML(tagName)); } /// @@ -99,12 +93,12 @@ public TwiML AddChild(string tagName) /// Option value public TwiML SetOption(string key, object value) { - if (this.Options.Exists(e => e.Key.Equals(key))) + if (Options.Exists(e => e.Key.Equals(key))) { - this.Options.Remove(this.Options.Find(e => e.Key.Equals(key))); + Options.Remove(Options.Find(e => e.Key.Equals(key))); } - this.Options.Add(new KeyValuePair(key, value.ToString())); + Options.Add(new KeyValuePair(key, value.ToString())); return this; } @@ -114,77 +108,7 @@ public TwiML SetOption(string key, object value) /// Option key public virtual string GetOption(string key) { - return this.Options.Find(e => e.Key.Equals(key)).Value; - } - - /// - /// Generate XElement from TwiML object - /// - protected virtual XNode ToXml() - { - var elem = new XElement(this.TagName, this.GetElementBody()); - - this.GetElementAttributes().ForEach(attr => - { - string transformedAttr = attr.Name.LocalName; - if (AttributeNameMapper.TryGetValue(attr.Name.LocalName, out transformedAttr)) - { - elem.Add(new XAttribute(transformedAttr, attr.Value)); - } - else - { - elem.Add(attr); - } - }); - - this.Options.ForEach(e => - { - if (e.Key.StartsWith("xml:")) - { - var attribute = new XAttribute(XNamespace.Xml + e.Key.Substring(4), e.Value); - elem.Add(attribute); - } - else - { - elem.Add(new XAttribute(e.Key, e.Value)); - } - }); - - this.Children.ForEach(child => elem.Add(child.ToXml())); - - return elem; - } - - /// - /// Generate XDocument from TwiML object - /// - public XDocument ToXDocument() - { - var declaration = new XDeclaration("1.0", "utf-8", null); - var elem = this.ToXml(); - var document = new XDocument(declaration, elem); - return document; - } - - /// - /// Generate XML string from TwiML object - /// - /// Change generated string format. - public string ToString(SaveOptions formattingOptions = SaveOptions.None) - { - var document = this.ToXDocument(); - var writer = new Utf8StringWriter(); - document.Save(writer, formattingOptions); - return writer.GetStringBuilder().ToString(); + return Options.Find(e => e.Key.Equals(key)).Value; } } - - /// - /// StringWriter which overrides default encoding to use UTF8. - /// - public class Utf8StringWriter : StringWriter - { - public override Encoding Encoding => Encoding.UTF8; - } - } \ No newline at end of file diff --git a/src/Twilio/TwiML/TwiMLSerializer.cs b/src/Twilio/TwiML/TwiMLSerializer.cs new file mode 100644 index 000000000..5bf4818fb --- /dev/null +++ b/src/Twilio/TwiML/TwiMLSerializer.cs @@ -0,0 +1,390 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading; +using System.Xml; +using System.Xml.Linq; +using Stream = System.IO.Stream; +#if !NET35 +using System.Threading.Tasks; +using Task = System.Threading.Tasks.Task; +#endif + +namespace Twilio.TwiML +{ + /// + /// Base class for all TwiML Objects. + /// + public partial class TwiML + { + /// + /// Attribute names to be transformed on the generated xml + /// + private static Dictionary AttributeNameMapper = new Dictionary { { "for_", "for" } }; + + /// + /// Generate XElement from TwiML object + /// + [Obsolete] + protected virtual XNode ToXml() + { + var elem = new XElement(TagName, GetElementBody()); + + foreach (var attr in GetElementAttributes()) + { + string transformedAttr = attr.Name.LocalName; + if (AttributeNameMapper.TryGetValue(attr.Name.LocalName, out transformedAttr)) + { + elem.Add(new XAttribute(transformedAttr, attr.Value)); + } + else + { + elem.Add(attr); + } + } + + Options.ForEach(e => + { + if (e.Key.StartsWith("xml:")) + { + var attribute = new XAttribute(XNamespace.Xml + e.Key.Substring(4), e.Value); + elem.Add(attribute); + } + else + { + elem.Add(new XAttribute(e.Key, e.Value)); + } + }); + + Children.ForEach(child => elem.Add(child.ToXml())); + + return elem; + } + + /// + /// Generate XDocument from TwiML object + /// + [Obsolete("ToXDocument will be removed in the future. Please use ToString, Save, or SaveAsync.")] + public XDocument ToXDocument() + { + var declaration = new XDeclaration("1.0", "utf-8", null); + var elem = ToXml(); + var document = new XDocument(declaration, elem); + return document; + } + + /// + /// Write TwiML to TextWriter as XML. + /// + /// TextWriter to write XML string to. + public void Save(TextWriter textWriter) + { + Save(textWriter, SaveOptions.None); + } + + /// + /// Write TwiML to TextWriter as XML. + /// + /// TextWriter to write XML string to. + /// Change generated string format. + public void Save(TextWriter textWriter, SaveOptions formattingOptions) + { + var ws = GetXmlWriterSettings(formattingOptions); + using (var writer = XmlWriter.Create(textWriter, ws)) + Save(writer); + } + + /// + /// Write TwiML to Stream as XML. + /// + /// Stream to write XML string to. + public void Save(Stream stream) + { + Save(stream, SaveOptions.None); + } + + /// + /// Write TwiML to Stream as XML. + /// + /// Stream to write XML string to. + /// Change generated string format. + public void Save(Stream stream, SaveOptions formattingOptions) + { + var ws = GetXmlWriterSettings(formattingOptions); + using (var writer = XmlWriter.Create(stream, ws)) + Save(writer); + } + + /// + /// Write TwiML to XmlWriter as XML. Configure the XmlWriter before invoking Save. + /// + /// XmlWriter to write XML string to. + public void Save(XmlWriter writer) + { + writer.WriteStartDocument(); + WriteContent(writer); + writer.WriteEndDocument(); + writer.Flush(); + } + + /// + /// Write the Element, Attributes, and inner XML of this TwiML object. + /// + /// XmlWriter to write XML string to. + protected virtual void WriteContent(XmlWriter writer) + { + writer.WriteStartElement(null, TagName, null); + + foreach (var attribute in GetElementAttributes()) + { + var attributeName = attribute.Name.LocalName; + string mappedName; + if (AttributeNameMapper.TryGetValue(attributeName, out mappedName)) + { + writer.WriteAttributeString( + null, + mappedName, + attribute.Name.NamespaceName, + attribute.Value + ); + } + else + { + writer.WriteAttributeString( + null, + attributeName, + attribute.Name.NamespaceName, + attribute.Value + ); + } + } + + foreach (var option in Options) + { + if (option.Key.StartsWith("xml:")) + { + writer.WriteAttributeString( + null, + option.Key.Substring(4), + XNamespace.Xml.NamespaceName, + option.Value + ); + } + else + { + writer.WriteAttributeString(null, option.Key, null, option.Value); + } + } + + var body = GetElementBody(); + if (!string.IsNullOrEmpty(body)) + { + writer.WriteString(body); + } + else + { + foreach (var child in Children) + { + child.WriteContent(writer); + } + } + + writer.WriteEndElement(); + } + +#if !NET35 + /// + /// Write TwiML to TextWriter as XML. + /// + /// TextWriter to write XML string to. + /// A cancellation token. + public Task SaveAsync(TextWriter textWriter, CancellationToken cancellationToken) + { + return SaveAsync(textWriter, SaveOptions.None, cancellationToken); + } + + /// + /// Write TwiML to TextWriter as XML. + /// + /// TextWriter to write XML string to. + /// Change generated string format. + /// A cancellation token. + public async Task SaveAsync( + TextWriter textWriter, SaveOptions + formattingOptions, + CancellationToken cancellationToken + ) + { + var ws = GetXmlWriterSettings(formattingOptions); + ws.Async = true; + var writer = XmlWriter.Create(textWriter, ws); +#if NET6_0_OR_GREATER + await using (writer.ConfigureAwait(false)) + { +#else + using (writer) + { +#endif + await SaveAsync(writer, cancellationToken).ConfigureAwait(false); + } + } + + /// + /// Write TwiML to Stream as XML. + /// + /// Stream to write XML string to. + /// A cancellation token. + public Task SaveAsync(Stream stream, CancellationToken cancellationToken) + { + return SaveAsync(stream, SaveOptions.None, cancellationToken); + } + + /// + /// Write TwiML to Stream as XML. + /// + /// Stream to write XML string to. + /// Change generated string format. + /// A cancellation token. + public async Task SaveAsync(Stream stream, SaveOptions formattingOptions, CancellationToken cancellationToken) + { + var ws = GetXmlWriterSettings(formattingOptions); + ws.Async = true; + var writer = XmlWriter.Create(stream, ws); +#if NET6_0_OR_GREATER + await using (writer.ConfigureAwait(false)) + { +#else + using (writer) + { +#endif + await SaveAsync(writer, cancellationToken).ConfigureAwait(false); + } + } + + /// + /// Write TwiML to XmlWriter as XML. Configure the XmlWriter before invoking Save. + /// + /// XmlWriter to write XML string to. + /// A cancellation token. + public async Task SaveAsync(XmlWriter writer, CancellationToken cancellationToken) + { + await writer.WriteStartDocumentAsync().ConfigureAwait(false); + await WriteXml(writer, cancellationToken).ConfigureAwait(false); + await writer.WriteEndDocumentAsync().ConfigureAwait(false); + await writer.FlushAsync().ConfigureAwait(false); + } + + /// + /// Write the Element, Attributes, and inner XML of this TwiML object. + /// + /// XmlWriter to write XML string to. + /// A cancellation token. + protected virtual async Task WriteXml(XmlWriter writer, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + await writer.WriteStartElementAsync(null, TagName, null).ConfigureAwait(false); + + foreach (var attribute in GetElementAttributes()) + { + var attributeName = attribute.Name.LocalName; + string mappedName; + if (AttributeNameMapper.TryGetValue(attributeName, out mappedName)) + { + await writer.WriteAttributeStringAsync( + null, + mappedName, + attribute.Name.NamespaceName, + attribute.Value + ).ConfigureAwait(false); + } + else + { + await writer.WriteAttributeStringAsync( + null, + attributeName, + attribute.Name.NamespaceName, + attribute.Value + ).ConfigureAwait(false); + } + } + + foreach (var option in Options) + { + if (option.Key.StartsWith("xml:")) + { + await writer.WriteAttributeStringAsync( + null, + option.Key.Substring(4), + XNamespace.Xml.NamespaceName, + option.Value + ).ConfigureAwait(false); + } + else + { + await writer.WriteAttributeStringAsync(null, option.Key, null, option.Value) + .ConfigureAwait(false); + } + } + + var body = GetElementBody(); + if (!string.IsNullOrEmpty(body)) + { + await writer.WriteStringAsync(body).ConfigureAwait(false); + } + else + { + foreach (var child in Children) + { + await child.WriteXml(writer, cancellationToken).ConfigureAwait(false); + } + } + + await writer.WriteEndElementAsync().ConfigureAwait(false); + } +#endif + + private static XmlWriterSettings GetXmlWriterSettings(SaveOptions saveOptions) + { + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; + + if ((saveOptions & SaveOptions.DisableFormatting) == 0) settings.Indent = true; +#if !NET35 + if ((saveOptions & SaveOptions.OmitDuplicateNamespaces) != 0) + settings.NamespaceHandling |= NamespaceHandling.OmitDuplicates; +#endif + return settings; + } + + /// + /// Generate XML string from TwiML object. + /// + public override string ToString() + { + return ToString(SaveOptions.None); + } + + /// + /// Generate XML string from TwiML object. + /// + /// Change generated string format. + public string ToString(SaveOptions formattingOptions) + { + using (var writer = new Utf8StringWriter()) + { + Save(writer, formattingOptions); + return writer.ToString(); + } + } + } + + /// + /// StringWriter which overrides default encoding to use UTF8. + /// + public class Utf8StringWriter : StringWriter + { + public override Encoding Encoding => Encoding.UTF8; + } +} \ No newline at end of file diff --git a/src/Twilio/TwiML/Voice/Application.cs b/src/Twilio/TwiML/Voice/Application.cs index ef71db232..b753d499b 100644 --- a/src/Twilio/TwiML/Voice/Application.cs +++ b/src/Twilio/TwiML/Voice/Application.cs @@ -110,7 +110,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Url != null) diff --git a/src/Twilio/TwiML/Voice/Client.cs b/src/Twilio/TwiML/Voice/Client.cs index 60efc8c3f..7a4c9d0c1 100644 --- a/src/Twilio/TwiML/Voice/Client.cs +++ b/src/Twilio/TwiML/Voice/Client.cs @@ -95,7 +95,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Url != null) diff --git a/src/Twilio/TwiML/Voice/Conference.cs b/src/Twilio/TwiML/Voice/Conference.cs index 6d1d52b32..03da0284a 100644 --- a/src/Twilio/TwiML/Voice/Conference.cs +++ b/src/Twilio/TwiML/Voice/Conference.cs @@ -293,7 +293,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Muted != null) diff --git a/src/Twilio/TwiML/Voice/Config.cs b/src/Twilio/TwiML/Voice/Config.cs index 6e1ba86a0..36aab18cb 100644 --- a/src/Twilio/TwiML/Voice/Config.cs +++ b/src/Twilio/TwiML/Voice/Config.cs @@ -39,7 +39,7 @@ public Config(string name = null, string value = null) : base("Config") /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Name != null) diff --git a/src/Twilio/TwiML/Voice/Connect.cs b/src/Twilio/TwiML/Voice/Connect.cs index f2c2c6bc1..3666bfa17 100644 --- a/src/Twilio/TwiML/Voice/Connect.cs +++ b/src/Twilio/TwiML/Voice/Connect.cs @@ -41,7 +41,7 @@ public Connect(Uri action = null, Twilio.Http.HttpMethod method = null) : base(" /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Voice/Conversation.cs b/src/Twilio/TwiML/Voice/Conversation.cs index a3f4e8b38..e6093b493 100644 --- a/src/Twilio/TwiML/Voice/Conversation.cs +++ b/src/Twilio/TwiML/Voice/Conversation.cs @@ -188,7 +188,7 @@ public Conversation(string serviceInstanceSid = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.ServiceInstanceSid != null) diff --git a/src/Twilio/TwiML/Voice/Dial.cs b/src/Twilio/TwiML/Voice/Dial.cs index 0ed3b60a1..c1dfc05bd 100644 --- a/src/Twilio/TwiML/Voice/Dial.cs +++ b/src/Twilio/TwiML/Voice/Dial.cs @@ -275,7 +275,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Voice/Enqueue.cs b/src/Twilio/TwiML/Voice/Enqueue.cs index 24d5013f3..23f9666eb 100644 --- a/src/Twilio/TwiML/Voice/Enqueue.cs +++ b/src/Twilio/TwiML/Voice/Enqueue.cs @@ -85,7 +85,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Voice/Gather.cs b/src/Twilio/TwiML/Voice/Gather.cs index 60ba91ffd..e0fb797d7 100644 --- a/src/Twilio/TwiML/Voice/Gather.cs +++ b/src/Twilio/TwiML/Voice/Gather.cs @@ -327,7 +327,7 @@ public Gather(IEnumerable input = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Input != null) diff --git a/src/Twilio/TwiML/Voice/Number.cs b/src/Twilio/TwiML/Voice/Number.cs index ebd433ca7..faa5a71bb 100644 --- a/src/Twilio/TwiML/Voice/Number.cs +++ b/src/Twilio/TwiML/Voice/Number.cs @@ -159,7 +159,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.SendDigits != null) diff --git a/src/Twilio/TwiML/Voice/Parameter.cs b/src/Twilio/TwiML/Voice/Parameter.cs index 4e09c9188..4d5819643 100644 --- a/src/Twilio/TwiML/Voice/Parameter.cs +++ b/src/Twilio/TwiML/Voice/Parameter.cs @@ -39,7 +39,7 @@ public Parameter(string name = null, string value = null) : base("Parameter") /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Name != null) diff --git a/src/Twilio/TwiML/Voice/Pause.cs b/src/Twilio/TwiML/Voice/Pause.cs index b48553de1..935a1c9b4 100644 --- a/src/Twilio/TwiML/Voice/Pause.cs +++ b/src/Twilio/TwiML/Voice/Pause.cs @@ -33,7 +33,7 @@ public Pause(int? length = null) : base("Pause") /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Length != null) diff --git a/src/Twilio/TwiML/Voice/Pay.cs b/src/Twilio/TwiML/Voice/Pay.cs index 7401a5e11..e9f37e370 100644 --- a/src/Twilio/TwiML/Voice/Pay.cs +++ b/src/Twilio/TwiML/Voice/Pay.cs @@ -270,7 +270,7 @@ public Pay(Pay.InputEnum input = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Input != null) diff --git a/src/Twilio/TwiML/Voice/Play.cs b/src/Twilio/TwiML/Voice/Play.cs index 6e9cefb47..d42197170 100644 --- a/src/Twilio/TwiML/Voice/Play.cs +++ b/src/Twilio/TwiML/Voice/Play.cs @@ -55,7 +55,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Loop != null) diff --git a/src/Twilio/TwiML/Voice/Prompt.cs b/src/Twilio/TwiML/Voice/Prompt.cs index 4bf5e3b89..3c82bd823 100644 --- a/src/Twilio/TwiML/Voice/Prompt.cs +++ b/src/Twilio/TwiML/Voice/Prompt.cs @@ -122,7 +122,7 @@ public Prompt(Prompt.ForEnum for_ = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.For_ != null) diff --git a/src/Twilio/TwiML/Voice/Queue.cs b/src/Twilio/TwiML/Voice/Queue.cs index 1330fc0cd..f91d816a0 100644 --- a/src/Twilio/TwiML/Voice/Queue.cs +++ b/src/Twilio/TwiML/Voice/Queue.cs @@ -71,7 +71,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Url != null) diff --git a/src/Twilio/TwiML/Voice/Record.cs b/src/Twilio/TwiML/Voice/Record.cs index 20eafd12d..a9fe79948 100644 --- a/src/Twilio/TwiML/Voice/Record.cs +++ b/src/Twilio/TwiML/Voice/Record.cs @@ -141,7 +141,7 @@ public Record(Uri action = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Voice/Redirect.cs b/src/Twilio/TwiML/Voice/Redirect.cs index d5fb144a6..a6006387b 100644 --- a/src/Twilio/TwiML/Voice/Redirect.cs +++ b/src/Twilio/TwiML/Voice/Redirect.cs @@ -49,7 +49,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Method != null) diff --git a/src/Twilio/TwiML/Voice/Refer.cs b/src/Twilio/TwiML/Voice/Refer.cs index 5a708d763..dd36b86ef 100644 --- a/src/Twilio/TwiML/Voice/Refer.cs +++ b/src/Twilio/TwiML/Voice/Refer.cs @@ -41,7 +41,7 @@ public Refer(Uri action = null, Twilio.Http.HttpMethod method = null) : base("Re /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Voice/Reject.cs b/src/Twilio/TwiML/Voice/Reject.cs index 52140d649..56de60c15 100644 --- a/src/Twilio/TwiML/Voice/Reject.cs +++ b/src/Twilio/TwiML/Voice/Reject.cs @@ -47,7 +47,7 @@ public Reject(Reject.ReasonEnum reason = null) : base("Reject") /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Reason != null) diff --git a/src/Twilio/TwiML/Voice/Room.cs b/src/Twilio/TwiML/Voice/Room.cs index 41da43f7b..2dc215b0e 100644 --- a/src/Twilio/TwiML/Voice/Room.cs +++ b/src/Twilio/TwiML/Voice/Room.cs @@ -47,7 +47,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.ParticipantIdentity != null) diff --git a/src/Twilio/TwiML/Voice/Say.cs b/src/Twilio/TwiML/Voice/Say.cs index e10f28547..58c987523 100644 --- a/src/Twilio/TwiML/Voice/Say.cs +++ b/src/Twilio/TwiML/Voice/Say.cs @@ -236,7 +236,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Voice != null) diff --git a/src/Twilio/TwiML/Voice/Sip.cs b/src/Twilio/TwiML/Voice/Sip.cs index 1db062cd0..1df94c806 100644 --- a/src/Twilio/TwiML/Voice/Sip.cs +++ b/src/Twilio/TwiML/Voice/Sip.cs @@ -159,7 +159,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Username != null) diff --git a/src/Twilio/TwiML/Voice/Siprec.cs b/src/Twilio/TwiML/Voice/Siprec.cs index 8d761df76..fb17bed58 100644 --- a/src/Twilio/TwiML/Voice/Siprec.cs +++ b/src/Twilio/TwiML/Voice/Siprec.cs @@ -60,7 +60,7 @@ public Siprec(string name = null, string connectorName = null, Siprec.TrackEnum /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Name != null) diff --git a/src/Twilio/TwiML/Voice/Sms.cs b/src/Twilio/TwiML/Voice/Sms.cs index f72235ae0..bd43c2b7d 100644 --- a/src/Twilio/TwiML/Voice/Sms.cs +++ b/src/Twilio/TwiML/Voice/Sms.cs @@ -78,7 +78,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.To != null) diff --git a/src/Twilio/TwiML/Voice/SsmlBreak.cs b/src/Twilio/TwiML/Voice/SsmlBreak.cs index 756e5ee13..05c99bc51 100644 --- a/src/Twilio/TwiML/Voice/SsmlBreak.cs +++ b/src/Twilio/TwiML/Voice/SsmlBreak.cs @@ -58,7 +58,7 @@ public SsmlBreak(SsmlBreak.StrengthEnum strength = null, string time = null) : b /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Strength != null) diff --git a/src/Twilio/TwiML/Voice/SsmlEmphasis.cs b/src/Twilio/TwiML/Voice/SsmlEmphasis.cs index 9a86d161d..fd2f7305f 100644 --- a/src/Twilio/TwiML/Voice/SsmlEmphasis.cs +++ b/src/Twilio/TwiML/Voice/SsmlEmphasis.cs @@ -62,7 +62,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Level != null) diff --git a/src/Twilio/TwiML/Voice/SsmlLang.cs b/src/Twilio/TwiML/Voice/SsmlLang.cs index aa7068030..23f879c35 100644 --- a/src/Twilio/TwiML/Voice/SsmlLang.cs +++ b/src/Twilio/TwiML/Voice/SsmlLang.cs @@ -95,7 +95,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.XmlLang != null) diff --git a/src/Twilio/TwiML/Voice/SsmlPhoneme.cs b/src/Twilio/TwiML/Voice/SsmlPhoneme.cs index 29a692199..a7e601613 100644 --- a/src/Twilio/TwiML/Voice/SsmlPhoneme.cs +++ b/src/Twilio/TwiML/Voice/SsmlPhoneme.cs @@ -71,7 +71,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Alphabet != null) diff --git a/src/Twilio/TwiML/Voice/SsmlProsody.cs b/src/Twilio/TwiML/Voice/SsmlProsody.cs index e9bd17b96..9d73ab5c2 100644 --- a/src/Twilio/TwiML/Voice/SsmlProsody.cs +++ b/src/Twilio/TwiML/Voice/SsmlProsody.cs @@ -64,7 +64,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Volume != null) diff --git a/src/Twilio/TwiML/Voice/SsmlSayAs.cs b/src/Twilio/TwiML/Voice/SsmlSayAs.cs index 753c59dc6..2ca1a87b1 100644 --- a/src/Twilio/TwiML/Voice/SsmlSayAs.cs +++ b/src/Twilio/TwiML/Voice/SsmlSayAs.cs @@ -102,7 +102,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.InterpretAs != null) diff --git a/src/Twilio/TwiML/Voice/SsmlSub.cs b/src/Twilio/TwiML/Voice/SsmlSub.cs index c71dc29e0..c1418cf66 100644 --- a/src/Twilio/TwiML/Voice/SsmlSub.cs +++ b/src/Twilio/TwiML/Voice/SsmlSub.cs @@ -48,7 +48,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Alias != null) diff --git a/src/Twilio/TwiML/Voice/SsmlW.cs b/src/Twilio/TwiML/Voice/SsmlW.cs index 8fe0ff50c..4563ab3aa 100644 --- a/src/Twilio/TwiML/Voice/SsmlW.cs +++ b/src/Twilio/TwiML/Voice/SsmlW.cs @@ -48,7 +48,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Role != null) diff --git a/src/Twilio/TwiML/Voice/Start.cs b/src/Twilio/TwiML/Voice/Start.cs index 114793d6a..d0bac2767 100644 --- a/src/Twilio/TwiML/Voice/Start.cs +++ b/src/Twilio/TwiML/Voice/Start.cs @@ -41,7 +41,7 @@ public Start(Uri action = null, Twilio.Http.HttpMethod method = null) : base("St /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Action != null) diff --git a/src/Twilio/TwiML/Voice/Stream.cs b/src/Twilio/TwiML/Voice/Stream.cs index 49d3bee8b..75c83e5e4 100644 --- a/src/Twilio/TwiML/Voice/Stream.cs +++ b/src/Twilio/TwiML/Voice/Stream.cs @@ -96,7 +96,7 @@ public Stream(string name = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Name != null) diff --git a/src/Twilio/TwiML/Voice/Task.cs b/src/Twilio/TwiML/Voice/Task.cs index 49ffeca4f..8238e85df 100644 --- a/src/Twilio/TwiML/Voice/Task.cs +++ b/src/Twilio/TwiML/Voice/Task.cs @@ -54,7 +54,7 @@ protected override string GetElementBody() /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.Priority != null) diff --git a/src/Twilio/TwiML/Voice/VirtualAgent.cs b/src/Twilio/TwiML/Voice/VirtualAgent.cs index 8b7cceb55..22c5bb807 100644 --- a/src/Twilio/TwiML/Voice/VirtualAgent.cs +++ b/src/Twilio/TwiML/Voice/VirtualAgent.cs @@ -61,7 +61,7 @@ public VirtualAgent(string connectorName = null, /// /// Return the attributes of the TwiML tag /// - protected override List GetElementAttributes() + protected override IEnumerable GetElementAttributes() { var attributes = new List(); if (this.ConnectorName != null) diff --git a/src/Twilio/Twilio.csproj b/src/Twilio/Twilio.csproj index 171834b2e..f3640ebe5 100644 --- a/src/Twilio/Twilio.csproj +++ b/src/Twilio/Twilio.csproj @@ -1,13 +1,13 @@  - netstandard1.4;netstandard2.0;net451;net35 + netstandard1.4;netstandard2.0;net451;net35;net60 true Twilio Twilio REST API helper library Copyright © Twilio Twilio en-US - 6.6.1 + 6.2.2 Twilio $(NoWarn);CS1591 @@ -38,6 +38,12 @@ + + + + + + diff --git a/test/Twilio.Test/TwiML/ApplicationSidTest.cs b/test/Twilio.Test/TwiML/ApplicationSidTest.cs index 19b12301a..a8b0e01dd 100644 --- a/test/Twilio.Test/TwiML/ApplicationSidTest.cs +++ b/test/Twilio.Test/TwiML/ApplicationSidTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new ApplicationSid(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ApplicationTest.cs b/test/Twilio.Test/TwiML/ApplicationTest.cs index ae040bf17..f9d2c85f8 100644 --- a/test/Twilio.Test/TwiML/ApplicationTest.cs +++ b/test/Twilio.Test/TwiML/ApplicationTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -52,10 +52,11 @@ public void TestElementWithExtraAttributes() var elem = new Application(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -73,7 +74,7 @@ public void TestElementWithChildren() "" + Environment.NewLine + "" + Environment.NewLine + " sid" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/AutopilotTest.cs b/test/Twilio.Test/TwiML/AutopilotTest.cs index c4f6ffe97..2b19858e6 100644 --- a/test/Twilio.Test/TwiML/AutopilotTest.cs +++ b/test/Twilio.Test/TwiML/AutopilotTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Autopilot(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/BodyTest.cs b/test/Twilio.Test/TwiML/BodyTest.cs index 9bd1cd250..72c6480cb 100644 --- a/test/Twilio.Test/TwiML/BodyTest.cs +++ b/test/Twilio.Test/TwiML/BodyTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Body(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ClientTest.cs b/test/Twilio.Test/TwiML/ClientTest.cs index b87759724..e95318edc 100644 --- a/test/Twilio.Test/TwiML/ClientTest.cs +++ b/test/Twilio.Test/TwiML/ClientTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -50,10 +50,11 @@ public void TestElementWithExtraAttributes() var elem = new Client(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -71,7 +72,7 @@ public void TestElementWithChildren() "" + Environment.NewLine + "" + Environment.NewLine + " client_identity" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/ConferenceTest.cs b/test/Twilio.Test/TwiML/ConferenceTest.cs index 330e16c68..9fbc9337f 100644 --- a/test/Twilio.Test/TwiML/ConferenceTest.cs +++ b/test/Twilio.Test/TwiML/ConferenceTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -65,10 +65,11 @@ public void TestElementWithExtraAttributes() var elem = new Conference(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ConfigTest.cs b/test/Twilio.Test/TwiML/ConfigTest.cs index d73797b6c..4d9a8613a 100644 --- a/test/Twilio.Test/TwiML/ConfigTest.cs +++ b/test/Twilio.Test/TwiML/ConfigTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Config("name", "value"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Config(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ConnectTest.cs b/test/Twilio.Test/TwiML/ConnectTest.cs index 8d400acbb..e53fbc209 100644 --- a/test/Twilio.Test/TwiML/ConnectTest.cs +++ b/test/Twilio.Test/TwiML/ConnectTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Connect(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Connect(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -99,9 +100,9 @@ public void TestElementWithChildren() "" + Environment.NewLine + " name" + Environment.NewLine + " name" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/ConversationTest.cs b/test/Twilio.Test/TwiML/ConversationTest.cs index 6225f4543..58e399997 100644 --- a/test/Twilio.Test/TwiML/ConversationTest.cs +++ b/test/Twilio.Test/TwiML/ConversationTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -47,7 +47,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -58,10 +58,11 @@ public void TestElementWithExtraAttributes() var elem = new Conversation(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/DialTest.cs b/test/Twilio.Test/TwiML/DialTest.cs index 31d91139e..962cc6be8 100644 --- a/test/Twilio.Test/TwiML/DialTest.cs +++ b/test/Twilio.Test/TwiML/DialTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -62,10 +62,11 @@ public void TestElementWithExtraAttributes() var elem = new Dial(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -81,7 +82,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() diff --git a/test/Twilio.Test/TwiML/EchoTest.cs b/test/Twilio.Test/TwiML/EchoTest.cs index 0a59e60e4..c88f8b31f 100644 --- a/test/Twilio.Test/TwiML/EchoTest.cs +++ b/test/Twilio.Test/TwiML/EchoTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,10 +32,11 @@ public void TestElementWithExtraAttributes() var elem = new Echo(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/EnqueueTest.cs b/test/Twilio.Test/TwiML/EnqueueTest.cs index 7b3ed5b78..6a1858585 100644 --- a/test/Twilio.Test/TwiML/EnqueueTest.cs +++ b/test/Twilio.Test/TwiML/EnqueueTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -51,10 +51,11 @@ public void TestElementWithExtraAttributes() var elem = new Enqueue(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/FaxResponseTest.cs b/test/Twilio.Test/TwiML/FaxResponseTest.cs index 61df4aa5f..553ec50b6 100644 --- a/test/Twilio.Test/TwiML/FaxResponseTest.cs +++ b/test/Twilio.Test/TwiML/FaxResponseTest.cs @@ -22,7 +22,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -33,10 +33,11 @@ public void TestElementWithExtraAttributes() var elem = new FaxResponse(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -57,7 +58,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/GatherTest.cs b/test/Twilio.Test/TwiML/GatherTest.cs index 5eb842a5e..f728f1dc0 100644 --- a/test/Twilio.Test/TwiML/GatherTest.cs +++ b/test/Twilio.Test/TwiML/GatherTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -51,7 +51,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -62,10 +62,11 @@ public void TestElementWithExtraAttributes() var elem = new Gather(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -81,7 +82,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() @@ -103,7 +104,7 @@ public void TestElementWithChildren() "" + Environment.NewLine + "" + Environment.NewLine + " message" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " https://example.com" + Environment.NewLine + "", elem.ToString() diff --git a/test/Twilio.Test/TwiML/HangupTest.cs b/test/Twilio.Test/TwiML/HangupTest.cs index 20aa9bead..1e572fa47 100644 --- a/test/Twilio.Test/TwiML/HangupTest.cs +++ b/test/Twilio.Test/TwiML/HangupTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,10 +32,11 @@ public void TestElementWithExtraAttributes() var elem = new Hangup(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -50,7 +51,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/IdentityTest.cs b/test/Twilio.Test/TwiML/IdentityTest.cs index 9051dcaab..6b036ca3e 100644 --- a/test/Twilio.Test/TwiML/IdentityTest.cs +++ b/test/Twilio.Test/TwiML/IdentityTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Identity(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/LeaveTest.cs b/test/Twilio.Test/TwiML/LeaveTest.cs index 5cb620488..f68d76d2f 100644 --- a/test/Twilio.Test/TwiML/LeaveTest.cs +++ b/test/Twilio.Test/TwiML/LeaveTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,10 +32,11 @@ public void TestElementWithExtraAttributes() var elem = new Leave(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/MediaTest.cs b/test/Twilio.Test/TwiML/MediaTest.cs index 29a979b6e..2e461b051 100644 --- a/test/Twilio.Test/TwiML/MediaTest.cs +++ b/test/Twilio.Test/TwiML/MediaTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Media(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/MessageTest.cs b/test/Twilio.Test/TwiML/MessageTest.cs index 3a299fe8c..d7c619cdb 100644 --- a/test/Twilio.Test/TwiML/MessageTest.cs +++ b/test/Twilio.Test/TwiML/MessageTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -50,10 +50,11 @@ public void TestElementWithExtraAttributes() var elem = new Message(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/MessagingResponseTest.cs b/test/Twilio.Test/TwiML/MessagingResponseTest.cs index 49fd79c47..b7abe7182 100644 --- a/test/Twilio.Test/TwiML/MessagingResponseTest.cs +++ b/test/Twilio.Test/TwiML/MessagingResponseTest.cs @@ -22,7 +22,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -33,10 +33,11 @@ public void TestElementWithExtraAttributes() var elem = new MessagingResponse(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -52,7 +53,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() diff --git a/test/Twilio.Test/TwiML/NumberTest.cs b/test/Twilio.Test/TwiML/NumberTest.cs index b5524cce9..1ac86c254 100644 --- a/test/Twilio.Test/TwiML/NumberTest.cs +++ b/test/Twilio.Test/TwiML/NumberTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -59,10 +59,11 @@ public void TestElementWithExtraAttributes() var elem = new Number(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ParameterTest.cs b/test/Twilio.Test/TwiML/ParameterTest.cs index a5c337068..108772ce3 100644 --- a/test/Twilio.Test/TwiML/ParameterTest.cs +++ b/test/Twilio.Test/TwiML/ParameterTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Parameter("name", "value"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Parameter(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/PauseTest.cs b/test/Twilio.Test/TwiML/PauseTest.cs index 1b9505e3a..53761439d 100644 --- a/test/Twilio.Test/TwiML/PauseTest.cs +++ b/test/Twilio.Test/TwiML/PauseTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Pause(1); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Pause(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/PayTest.cs b/test/Twilio.Test/TwiML/PayTest.cs index 1a7d60982..affdbefde 100644 --- a/test/Twilio.Test/TwiML/PayTest.cs +++ b/test/Twilio.Test/TwiML/PayTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -51,7 +51,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -62,10 +62,11 @@ public void TestElementWithExtraAttributes() var elem = new Pay(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -81,7 +82,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() @@ -106,8 +107,8 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/PlayTest.cs b/test/Twilio.Test/TwiML/PlayTest.cs index e89ac63f0..2051fe6f6 100644 --- a/test/Twilio.Test/TwiML/PlayTest.cs +++ b/test/Twilio.Test/TwiML/PlayTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Play(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/PromptTest.cs b/test/Twilio.Test/TwiML/PromptTest.cs index b9d65df0e..368cf134f 100644 --- a/test/Twilio.Test/TwiML/PromptTest.cs +++ b/test/Twilio.Test/TwiML/PromptTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -38,7 +38,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -49,10 +49,11 @@ public void TestElementWithExtraAttributes() var elem = new Prompt(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -68,7 +69,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() @@ -91,7 +92,7 @@ public void TestElementWithChildren() "" + Environment.NewLine + " message" + Environment.NewLine + " https://example.com" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/QueueTest.cs b/test/Twilio.Test/TwiML/QueueTest.cs index b7714b0e9..8394499a6 100644 --- a/test/Twilio.Test/TwiML/QueueTest.cs +++ b/test/Twilio.Test/TwiML/QueueTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -49,10 +49,11 @@ public void TestElementWithExtraAttributes() var elem = new Queue(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ReceiveTest.cs b/test/Twilio.Test/TwiML/ReceiveTest.cs index 809b430e4..cb273972a 100644 --- a/test/Twilio.Test/TwiML/ReceiveTest.cs +++ b/test/Twilio.Test/TwiML/ReceiveTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -38,7 +38,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -49,10 +49,11 @@ public void TestElementWithExtraAttributes() var elem = new Receive(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/RecordTest.cs b/test/Twilio.Test/TwiML/RecordTest.cs index 587b11322..319f48274 100644 --- a/test/Twilio.Test/TwiML/RecordTest.cs +++ b/test/Twilio.Test/TwiML/RecordTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -45,7 +45,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -56,10 +56,11 @@ public void TestElementWithExtraAttributes() var elem = new Record(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/RedirectTest.cs b/test/Twilio.Test/TwiML/RedirectTest.cs index 41ce20a08..d19b555d4 100644 --- a/test/Twilio.Test/TwiML/RedirectTest.cs +++ b/test/Twilio.Test/TwiML/RedirectTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Redirect(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ReferSipTest.cs b/test/Twilio.Test/TwiML/ReferSipTest.cs index 800dc67a6..988ca399f 100644 --- a/test/Twilio.Test/TwiML/ReferSipTest.cs +++ b/test/Twilio.Test/TwiML/ReferSipTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new ReferSip(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/ReferTest.cs b/test/Twilio.Test/TwiML/ReferTest.cs index dfe6b9746..faff70453 100644 --- a/test/Twilio.Test/TwiML/ReferTest.cs +++ b/test/Twilio.Test/TwiML/ReferTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Refer(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Refer(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/RejectTest.cs b/test/Twilio.Test/TwiML/RejectTest.cs index 91ac2f0ee..fad737b35 100644 --- a/test/Twilio.Test/TwiML/RejectTest.cs +++ b/test/Twilio.Test/TwiML/RejectTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Reject(Reject.ReasonEnum.Rejected); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Reject(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -61,7 +62,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/RoomTest.cs b/test/Twilio.Test/TwiML/RoomTest.cs index cb72a684b..60a6a6006 100644 --- a/test/Twilio.Test/TwiML/RoomTest.cs +++ b/test/Twilio.Test/TwiML/RoomTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Room(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SayTest.cs b/test/Twilio.Test/TwiML/SayTest.cs index 91f67bd41..78a39be35 100644 --- a/test/Twilio.Test/TwiML/SayTest.cs +++ b/test/Twilio.Test/TwiML/SayTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Say(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -79,7 +80,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + "

words

" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/SerializationTest.cs b/test/Twilio.Test/TwiML/SerializationTest.cs new file mode 100644 index 000000000..811837592 --- /dev/null +++ b/test/Twilio.Test/TwiML/SerializationTest.cs @@ -0,0 +1,256 @@ +using NUnit.Framework; +using System; +using System.IO; +using System.Threading; +using System.Xml.Linq; +using Twilio.Converters; +using Twilio.TwiML; +using Twilio.TwiML.Voice; + +namespace Twilio.Tests.TwiML +{ + [TestFixture] + public class SerializationTest : TwilioTest + { + private Twilio.TwiML.TwiML twiml; + private string twimlOutput; + + public SerializationTest() + { + var elem = new VoiceResponse(); + + elem.Connect(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); + + elem.Dial( + "number", + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + 1, + true, + 1, + "caller_id", + Dial.RecordEnum.DoNotRecord, + Dial.TrimEnum.TrimSilence, + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + Promoter.ListOfOne(Dial.RecordingEventEnum.InProgress), + true, + Dial.RingToneEnum.At, + Dial.RecordingTrackEnum.Both, + true, + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get + ); + + elem.Echo(); + + elem.Enqueue( + "name", + new Uri("https://example.com"), + 1, + Twilio.Http.HttpMethod.Get, + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + "workflow_sid" + ); + + elem.Gather( + Promoter.ListOfOne(Gather.InputEnum.Dtmf), + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + 1, + "speech_timeout", + 1, + true, + "finish_on_key", + 1, + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + Gather.LanguageEnum.AfZa, + "hints", + true, + true, + true, + Gather.SpeechModelEnum.Default, + true + ); + + elem.Hangup(); + + elem.Leave(); + + elem.Pause(1); + + elem.Play(new Uri("https://example.com"), 1, "digits"); + + elem.Queue( + "name", + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + "reservation_sid", + "post_work_activity_sid" + ); + + elem.Record( + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + 1, + "finish_on_key", + 1, + true, + Record.TrimEnum.TrimSilence, + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + Promoter.ListOfOne(Record.RecordingEventEnum.InProgress), + true, + new Uri("https://example.com") + ); + + elem.Redirect(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); + + elem.Reject(Reject.ReasonEnum.Rejected); + + elem.Say("message", Say.VoiceEnum.Man, 1, Say.LanguageEnum.Arb); + + elem.Sms( + "message", + new Twilio.Types.PhoneNumber("+15558675310"), + new Twilio.Types.PhoneNumber("+15017122661"), + new Uri("https://example.com"), + Twilio.Http.HttpMethod.Get, + new Uri("https://example.com") + ); + + elem.Pay( + Pay.InputEnum.Dtmf, + new Uri("https://example.com"), + Pay.BankAccountTypeEnum.ConsumerChecking, + new Uri("https://example.com"), + Pay.StatusCallbackMethodEnum.Get, + 1, + 1, + true, + "postal_code", + 1, + "payment_connector", + Pay.PaymentMethodEnum.AchDebit, + Pay.TokenTypeEnum.OneTime, + "charge_amount", + "currency", + "description", + Promoter.ListOfOne(Pay.ValidCardTypesEnum.Visa), + Pay.LanguageEnum.DeDe + ); + + elem.Prompt( + Prompt.ForEnum.PaymentCardNumber, + Promoter.ListOfOne(Prompt.ErrorTypeEnum.Timeout), + Promoter.ListOfOne(Prompt.CardTypeEnum.Visa), + Promoter.ListOfOne(1), + true + ); + + elem.Start(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); + + elem.Stop(); + + elem.Refer(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); + + twiml = elem; + + twimlOutput = "" + Environment.NewLine + + "" + Environment.NewLine + + " " + Environment.NewLine + + " number" + + Environment.NewLine + + " " + Environment.NewLine + + " name" + + Environment.NewLine + + " " + + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " https://example.com" + Environment.NewLine + + " name" + + Environment.NewLine + + " " + + Environment.NewLine + + " https://example.com" + Environment.NewLine + + " " + Environment.NewLine + + " message" + Environment.NewLine + + " message" + + Environment.NewLine + + " " + + Environment.NewLine + + " " + + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + ""; + } + + [Test] + public void TestSaveStream() + { + string output; + using (var memoryStream = new MemoryStream()) + { + twiml.Save(memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + using (var reader = new StreamReader(memoryStream)) + { + output = reader.ReadToEnd(); + } + } + + Assert.AreEqual(twimlOutput, output); + } + + [Test] + public void TestSaveTextWriter() + { + string output; + using (var writer = new Utf8StringWriter()) + { + twiml.Save(writer); + output = writer.ToString(); + } + + Assert.AreEqual(twimlOutput, output); + } + +#if !NET35 + [Test] + public async System.Threading.Tasks.Task TestSaveAsyncStream() + { + string output; + using (var memoryStream = new MemoryStream()) + { + await twiml.SaveAsync(memoryStream, CancellationToken.None); + memoryStream.Seek(0, SeekOrigin.Begin); + using (var reader = new StreamReader(memoryStream)) + { + output = await reader.ReadToEndAsync(); + } + } + + Assert.AreEqual(twimlOutput, output); + } + + [Test] + public async System.Threading.Tasks.Task TestSaveAsyncTextWriter() + { + string output; + using (var writer = new Utf8StringWriter()) + { + await twiml.SaveAsync(writer, CancellationToken.None); + output = writer.ToString(); + } + + Assert.AreEqual(twimlOutput, output); + } +#endif + } +} \ No newline at end of file diff --git a/test/Twilio.Test/TwiML/SimTest.cs b/test/Twilio.Test/TwiML/SimTest.cs index 82ff3fa42..5db8bade9 100644 --- a/test/Twilio.Test/TwiML/SimTest.cs +++ b/test/Twilio.Test/TwiML/SimTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Sim(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SipTest.cs b/test/Twilio.Test/TwiML/SipTest.cs index 860ed4aad..752ab7edd 100644 --- a/test/Twilio.Test/TwiML/SipTest.cs +++ b/test/Twilio.Test/TwiML/SipTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -59,10 +59,11 @@ public void TestElementWithExtraAttributes() var elem = new Sip(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SiprecTest.cs b/test/Twilio.Test/TwiML/SiprecTest.cs index 36a3be33d..a832229e5 100644 --- a/test/Twilio.Test/TwiML/SiprecTest.cs +++ b/test/Twilio.Test/TwiML/SiprecTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Siprec("name", "connector_name", Siprec.TrackEnum.InboundTrack); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Siprec(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -61,7 +62,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/SmsTest.cs b/test/Twilio.Test/TwiML/SmsTest.cs index 7737faee8..cb0a2fb3e 100644 --- a/test/Twilio.Test/TwiML/SmsTest.cs +++ b/test/Twilio.Test/TwiML/SmsTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -50,10 +50,11 @@ public void TestElementWithExtraAttributes() var elem = new Sms(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SsmlBreakTest.cs b/test/Twilio.Test/TwiML/SsmlBreakTest.cs index 47de34aba..1b3836acb 100644 --- a/test/Twilio.Test/TwiML/SsmlBreakTest.cs +++ b/test/Twilio.Test/TwiML/SsmlBreakTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new SsmlBreak(SsmlBreak.StrengthEnum.None, "time"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlBreak(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SsmlEmphasisTest.cs b/test/Twilio.Test/TwiML/SsmlEmphasisTest.cs index 68603357e..66a6a6ea5 100644 --- a/test/Twilio.Test/TwiML/SsmlEmphasisTest.cs +++ b/test/Twilio.Test/TwiML/SsmlEmphasisTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlEmphasis(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -75,7 +76,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/SsmlLangTest.cs b/test/Twilio.Test/TwiML/SsmlLangTest.cs index bf25e8cff..41f7790cf 100644 --- a/test/Twilio.Test/TwiML/SsmlLangTest.cs +++ b/test/Twilio.Test/TwiML/SsmlLangTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlLang(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -79,7 +80,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + "

words

" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/SsmlPTest.cs b/test/Twilio.Test/TwiML/SsmlPTest.cs index 9534890a8..d204a21b0 100644 --- a/test/Twilio.Test/TwiML/SsmlPTest.cs +++ b/test/Twilio.Test/TwiML/SsmlPTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "

", + "

", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlP(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "

", + "

", elem.ToString() ); } @@ -77,7 +78,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "

" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/SsmlPhonemeTest.cs b/test/Twilio.Test/TwiML/SsmlPhonemeTest.cs index 2469c3299..56ae26cd6 100644 --- a/test/Twilio.Test/TwiML/SsmlPhonemeTest.cs +++ b/test/Twilio.Test/TwiML/SsmlPhonemeTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlPhoneme(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SsmlProsodyTest.cs b/test/Twilio.Test/TwiML/SsmlProsodyTest.cs index 1693cd6d8..1be35b31c 100644 --- a/test/Twilio.Test/TwiML/SsmlProsodyTest.cs +++ b/test/Twilio.Test/TwiML/SsmlProsodyTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlProsody(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -79,7 +80,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + "

words

" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/SsmlSTest.cs b/test/Twilio.Test/TwiML/SsmlSTest.cs index 75a385799..93b3d07c4 100644 --- a/test/Twilio.Test/TwiML/SsmlSTest.cs +++ b/test/Twilio.Test/TwiML/SsmlSTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlS(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -75,7 +76,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/SsmlSayAsTest.cs b/test/Twilio.Test/TwiML/SsmlSayAsTest.cs index 53a5e78eb..d9c2463e9 100644 --- a/test/Twilio.Test/TwiML/SsmlSayAsTest.cs +++ b/test/Twilio.Test/TwiML/SsmlSayAsTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlSayAs(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SsmlSubTest.cs b/test/Twilio.Test/TwiML/SsmlSubTest.cs index 42a04f44d..92a2a93c9 100644 --- a/test/Twilio.Test/TwiML/SsmlSubTest.cs +++ b/test/Twilio.Test/TwiML/SsmlSubTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlSub(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/SsmlWTest.cs b/test/Twilio.Test/TwiML/SsmlWTest.cs index 52bee0a20..17d638db1 100644 --- a/test/Twilio.Test/TwiML/SsmlWTest.cs +++ b/test/Twilio.Test/TwiML/SsmlWTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new SsmlW(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -71,7 +72,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + " words" + Environment.NewLine + diff --git a/test/Twilio.Test/TwiML/StartTest.cs b/test/Twilio.Test/TwiML/StartTest.cs index 0e6636434..34fbfd023 100644 --- a/test/Twilio.Test/TwiML/StartTest.cs +++ b/test/Twilio.Test/TwiML/StartTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,7 +32,7 @@ public void TestElementWithParams() var elem = new Start(new Uri("https://example.com"), Twilio.Http.HttpMethod.Get); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Start(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -62,7 +63,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() @@ -88,8 +89,8 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/StopTest.cs b/test/Twilio.Test/TwiML/StopTest.cs index 7567c8f91..97259d47e 100644 --- a/test/Twilio.Test/TwiML/StopTest.cs +++ b/test/Twilio.Test/TwiML/StopTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -32,10 +32,11 @@ public void TestElementWithExtraAttributes() var elem = new Stop(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -51,7 +52,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() @@ -77,8 +78,8 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/StreamTest.cs b/test/Twilio.Test/TwiML/StreamTest.cs index a77bdf268..81136c30f 100644 --- a/test/Twilio.Test/TwiML/StreamTest.cs +++ b/test/Twilio.Test/TwiML/StreamTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -39,7 +39,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -50,10 +50,11 @@ public void TestElementWithExtraAttributes() var elem = new Stream(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -68,7 +69,7 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/TaskTest.cs b/test/Twilio.Test/TwiML/TaskTest.cs index f220a3a97..cce712d7e 100644 --- a/test/Twilio.Test/TwiML/TaskTest.cs +++ b/test/Twilio.Test/TwiML/TaskTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -43,10 +43,11 @@ public void TestElementWithExtraAttributes() var elem = new Task(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } diff --git a/test/Twilio.Test/TwiML/VirtualAgentTest.cs b/test/Twilio.Test/TwiML/VirtualAgentTest.cs index f96b53a9b..7c7b8a19c 100644 --- a/test/Twilio.Test/TwiML/VirtualAgentTest.cs +++ b/test/Twilio.Test/TwiML/VirtualAgentTest.cs @@ -21,7 +21,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -38,7 +38,7 @@ public void TestElementWithParams() ); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -49,10 +49,11 @@ public void TestElementWithExtraAttributes() var elem = new VirtualAgent(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -69,8 +70,8 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/VoiceResponseTest.cs b/test/Twilio.Test/TwiML/VoiceResponseTest.cs index 364f12cf2..ca0f011e1 100644 --- a/test/Twilio.Test/TwiML/VoiceResponseTest.cs +++ b/test/Twilio.Test/TwiML/VoiceResponseTest.cs @@ -22,7 +22,7 @@ public void TestEmptyElement() Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -33,10 +33,11 @@ public void TestElementWithExtraAttributes() var elem = new VoiceResponse(); elem.SetOption("newParam1", "value"); elem.SetOption("newParam2", 1); + elem.SetOption("xml:lang", "en"); Assert.AreEqual( "" + Environment.NewLine + - "", + "", elem.ToString() ); } @@ -52,7 +53,7 @@ public void TestNestElement() "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + "", elem.ToString() @@ -100,7 +101,7 @@ public void TestElementWithChildren() ); elem.Gather( - new[] {Gather.InputEnum.Dtmf}, + new[] {Gather.InputEnum.Dtmf}, new Uri("https://example.com"), Twilio.Http.HttpMethod.Get, 1, @@ -204,26 +205,26 @@ public void TestElementWithChildren() Assert.AreEqual( "" + Environment.NewLine + "" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " number" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " name" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + " https://example.com" + Environment.NewLine + " name" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " https://example.com" + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " message" + Environment.NewLine + " message" + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + + " " + Environment.NewLine + "", elem.ToString() ); diff --git a/test/Twilio.Test/TwiML/XmlEscapeTest.cs b/test/Twilio.Test/TwiML/XmlEscapeTest.cs new file mode 100644 index 000000000..509de6ee8 --- /dev/null +++ b/test/Twilio.Test/TwiML/XmlEscapeTest.cs @@ -0,0 +1,36 @@ +using NUnit.Framework; +using System; +using Twilio.TwiML.Messaging; + +namespace Twilio.Tests.TwiML +{ + [TestFixture] + public class XmlEscapeTest : TwilioTest + { + [Test] + public void TestXmlEscapedBodyMessage() + { + var elem = new Message(""); + + Assert.AreEqual( + "" + Environment.NewLine + + "<InvalidBodyMessage></InvalidBodyMessage>", + elem.ToString() + ); + } + + [Test] + public void TestXmlEscapedText() + { + var elem = new Message(); + elem.AddText(""); + + Assert.AreEqual( + "" + Environment.NewLine + + "<InvalidText></InvalidText>", + elem.ToString() + ); + } + } + +} \ No newline at end of file diff --git a/test/Twilio.Test/Twilio.Test.csproj b/test/Twilio.Test/Twilio.Test.csproj index 7dbe27ad0..747f9706c 100644 --- a/test/Twilio.Test/Twilio.Test.csproj +++ b/test/Twilio.Test/Twilio.Test.csproj @@ -2,14 +2,14 @@ Exe Twilio.Tests - net6.0;net451;net35 + net7.0;net451;net35 win7-x86 win7-x86 false false - + runtime; build; native; contentfiles; analyzers; buildtransitive all