public static ImagemapMessage ToImagemapMessage(this IImagemapMessage self) { if (self.BaseUrl == null) throw new InvalidOperationException("The base url cannot be null."); if (self.AlternativeText == null) throw new InvalidOperationException("The alternative text cannot be null."); if (self.BaseSize == null) throw new InvalidOperationException("The base size cannot be null."); if (self.Actions == null) throw new InvalidOperationException("The actions cannot be null."); ImagemapMessage imagemapMessage = self as ImagemapMessage; if (imagemapMessage == null) { imagemapMessage = new ImagemapMessage() { BaseUrl = self.BaseUrl, AlternativeText = self.AlternativeText, }; } imagemapMessage.BaseSize = self.BaseSize.ToImagemapSize(); imagemapMessage.Actions = self.Actions.ToImagemapActions().ToArray(); return imagemapMessage; }
public void Convert_ImagemapMessage_InstanceIsPreserved() { ImagemapMessage message = new ImagemapMessage() { BaseUrl = new Uri("https://foo.bar"), BaseSize = new ImagemapSize(1040, 1040), AlternativeText = "Alternative", Actions = new ImagemapAction[] { new ImagemapMessageAction("Text", 1, 2, 3, 4), new ImagemapUriAction("https://url.foo", 1, 2, 3, 4), } }; ISendMessage[] messages = MessageConverter.Convert(new ISendMessage[] { message }); Assert.AreEqual(1, messages.Length); IImagemapMessage imagemapMessage = messages[0] as IImagemapMessage; Assert.AreEqual(message, imagemapMessage); Assert.AreEqual(message.BaseSize, imagemapMessage.BaseSize); IImagemapAction[] actions = imagemapMessage.Actions.ToArray(); Assert.AreEqual(message.Actions.First(), actions[0]); ImagemapAction action = message.Actions.Skip(1).First(); Assert.AreEqual(action, actions[1]); Assert.AreEqual(action.Area, actions[1].Area); }
internal static ImagemapMessage Convert(IImagemapMessage message) { if (message.BaseUrl == null) { throw new InvalidOperationException("The base url cannot be null."); } if (message.AlternativeText == null) { throw new InvalidOperationException("The alternative text cannot be null."); } if (message.BaseSize == null) { throw new InvalidOperationException("The base size cannot be null."); } if (message.Actions == null) { throw new InvalidOperationException("The actions cannot be null."); } if (!(message is ImagemapMessage imagemapMessage)) { imagemapMessage = new ImagemapMessage() { BaseUrl = message.BaseUrl, AlternativeText = message.AlternativeText, }; } imagemapMessage.BaseSize = ImagemapSize.Convert(message.BaseSize); imagemapMessage.Actions = ConvertActions(message.Actions); return(imagemapMessage); }