public void DeserializesMessageCorrectly_Presence(string messageJson, params PresenceMessage[] expectedMessages) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); StringBuilder message = new StringBuilder("{\"presence\":") .Append(messageJson).Append("}"); Console.WriteLine(new DateTimeOffset(new DateTime(2015, 5, 5, 0, 0, 0, DateTimeKind.Utc)).ToUnixTimeInMilliseconds()); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message.ToString()); // Assert Assert.NotNull(target); Assert.NotNull(target.Presence); Assert.Equal <int>(expectedMessages.Length, target.Presence.Length); for (int i = 0; i < expectedMessages.Length; i++) { Assert.Equal <string>(expectedMessages[i].ClientId, target.Presence[i].ClientId); Assert.Equal <string>(expectedMessages[i].ConnectionId, target.Presence[i].ConnectionId); Assert.Equal <PresenceMessage.ActionType>(expectedMessages[i].Action, target.Presence[i].Action); Assert.Equal <string>(expectedMessages[i].Id, target.Presence[i].Id); Assert.Equal <DateTimeOffset>(expectedMessages[i].Timestamp, target.Presence[i].Timestamp); Assert.Equal(expectedMessages[i].Data, target.Presence[i].Data); } }
public void DeserializesMessageCorrectly_Flags(object flags) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"flags\":{0}}}", flags); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <byte>(byte.Parse(flags.ToString(), System.Globalization.CultureInfo.InstalledUICulture), (byte)target.Flags); }
public void DeserializesMessageCorrectly_Count(object count) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"count\":{0}}}", count); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <int>(int.Parse(count.ToString(), System.Globalization.CultureInfo.InstalledUICulture), target.Count); }
public void DeserializesMessageCorrectly_MsgSerial(object serial) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"msgSerial\":{0}}}", serial); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <long>(long.Parse(serial.ToString(), System.Globalization.CultureInfo.InstalledUICulture), target.MsgSerial); }
public void DeserializesMessageCorrectly_Id(string id) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"id\":\"{0}\"}}", id); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <string>(id, target.Id); }
public void DeserializesMessageCorrectly_ConnectionKey(string connectionKey) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"connectionKey\":\"{0}\"}}", connectionKey); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <string>(connectionKey, target.ConnectionKey); }
public void DeserializesMessageCorrectly_ChannelSerial(string serial) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"channelSerial\":\"{0}\"}}", serial); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <string>(serial, target.ChannelSerial); }
public void DeserializesMessageCorrectly_Channel(string channel) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"channel\":{0}}}", channel == null ? "null" : string.Format("\"{0}\"", channel)); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <string>(channel, target.Channel); }
public void DeserializesMessageCorrectly_Action(ProtocolMessage.MessageAction action) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); string message = string.Format("{{\"action\":{0}}}", (int)action); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message); // Assert Assert.NotNull(target); Assert.Equal <ProtocolMessage.MessageAction>(action, target.Action); }
public void DeserializesMessageCorrectly_Messages(string messageJson, params Message[] expectedMessages) { // Arrange JsonMessageSerializer serializer = new JsonMessageSerializer(); StringBuilder message = new StringBuilder("{\"messages\":") .Append(messageJson).Append("}"); // Act ProtocolMessage target = serializer.DeserializeProtocolMessage(message.ToString()); // Assert Assert.NotNull(target); Assert.NotNull(target.Messages); Assert.Equal <int>(expectedMessages.Length, target.Messages.Length); for (int i = 0; i < expectedMessages.Length; i++) { Assert.Equal <string>(expectedMessages[i].Name, target.Messages[i].Name); Assert.Equal(expectedMessages[i].Data, target.Messages[i].Data); } }