public void DeserializeMessageResponse() { string json = TestData["MessageResponse.json"]; MessageResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <MessageResponse>(json); DateTime expectSent = new DateTime(2017, 6, 9, 19, 1, 59); DateTime expectExpiration = new DateTime(2017, 7, 9, 19, 1, 59); Assert.IsNotNull(response.Header); Assert.AreEqual("Here is some full message text, no cut-off text", response.MessageText); Assert.IsNull(response.AttachmentId); Assert.IsNull(response.Attachment); Assert.IsNotNull(response.Actions); Assert.IsNotEmpty(response.Actions); Assert.AreEqual(1, response.Actions.Length); Assert.AreEqual(0, response.Header.SenderXuid); Assert.AreEqual("Xbox Live", response.Header.Sender); Assert.AreEqual("Service", response.Header.MessageType); Assert.IsTrue(response.Header.HasText); Assert.IsFalse(response.Header.HasPhoto); Assert.IsFalse(response.Header.HasAudio); Assert.AreEqual("Inbox", response.Header.MessageFolderType); Assert.AreEqual(0, response.Actions[0].Id); Assert.AreEqual("Launch website", response.Actions[0].VuiGui); Assert.IsNull(response.Actions[0].VuiAlm); Assert.IsNull(response.Actions[0].VuiPron); Assert.IsNull(response.Actions[0].VuiConf); Assert.AreEqual("https://xbox.com", response.Actions[0].Launch); Assert.AreEqual(LaunchType.DeepLink, response.Actions[0].LaunchType); }
public void DeserializeProfileResponse() { string json = TestData["ProfileResponse.json"]; ProfileResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <ProfileResponse>(json); Assert.IsNotNull(response.ProfileUsers); Assert.IsNotEmpty(response.ProfileUsers); Assert.AreEqual(1, response.ProfileUsers.Length); Assert.AreEqual(2580478784034343, response.ProfileUsers[0].Id); Assert.AreEqual(2580478784034343, response.ProfileUsers[0].HostId); Assert.IsFalse(response.ProfileUsers[0].IsSponsoredUser); Assert.IsNotNull(response.ProfileUsers[0].Settings); Assert.IsNotEmpty(response.ProfileUsers[0].Settings); Assert.AreEqual(6, response.ProfileUsers[0].Settings.Length); Assert.AreEqual(ProfileSetting.AppDisplayName, response.ProfileUsers[0].Settings[0].Id); Assert.AreEqual("Some Gamertag", response.ProfileUsers[0].Settings[0].Value); Assert.AreEqual(ProfileSetting.Gamerscore, response.ProfileUsers[0].Settings[1].Id); Assert.AreEqual("1337000", response.ProfileUsers[0].Settings[1].Value); Assert.AreEqual(ProfileSetting.Gamertag, response.ProfileUsers[0].Settings[2].Id); Assert.AreEqual("Some Gamertag", response.ProfileUsers[0].Settings[2].Value); Assert.AreEqual(ProfileSetting.PublicGamerpic, response.ProfileUsers[0].Settings[3].Id); Assert.AreEqual("http://images-eds.xboxlive.com/image?url=abcdef", response.ProfileUsers[0].Settings[3].Value); Assert.AreEqual(ProfileSetting.XboxOneRep, response.ProfileUsers[0].Settings[4].Id); Assert.AreEqual("Superstar", response.ProfileUsers[0].Settings[4].Value); Assert.AreEqual(ProfileSetting.RealName, response.ProfileUsers[0].Settings[5].Id); Assert.AreEqual("John Doe", response.ProfileUsers[0].Settings[5].Value); }
public void CreatePeopleBatchRequestBody() { ulong[] xuids = new ulong[] { 2580478784034343, 2535771801919068, 2508565379774180 }; string expected = TestData["PeopleBatchRequest.json"]; PeopleBatchRequest request = new PeopleBatchRequest(xuids); string body = NewtonsoftJsonSerializer.Create(JsonNamingStrategy.CamelCase) .Serialize(request); Assert.AreEqual(expected, body); }
public void ParseInvalidRefreshToken() { string content = TestData["InvalidData.json"]; WindowsLiveResponse response = NewtonsoftJsonSerializer.Create(JsonNamingStrategy.SnakeCase) .Deserialize <WindowsLiveResponse>(content); Assert.AreEqual(response.ExpiresIn, 0); Assert.IsNull(response.TokenType); Assert.IsNull(response.Scope); Assert.IsNull(response.AccessToken); Assert.IsNull(response.RefreshToken); Assert.IsNull(response.UserId); }
public void ParseValidRefreshToken() { string content = TestData["RefreshToken.json"]; WindowsLiveResponse response = NewtonsoftJsonSerializer.Create(JsonNamingStrategy.SnakeCase) .Deserialize <WindowsLiveResponse>(content); Assert.AreEqual(response.TokenType, "bearer"); Assert.AreEqual(response.ExpiresIn, 86400); Assert.AreEqual(response.Scope, "service::user.auth.xboxlive.com::MBI_SSL"); Assert.AreEqual(response.AccessToken, "EWCAA/bdf+sd34ji234kasdf34asfs=="); Assert.AreEqual(response.RefreshToken, "CuZ*4TX7!SAF33cW*kzdFLPRcz0DtU$$"); Assert.AreEqual(response.UserId, "a42bdc501731723e"); }
public void DeserializeConversationResponse() { string json = TestData["MessageConversationResponse.json"]; ConversationResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <ConversationResponse>(json); Assert.IsNotNull(response.Conversation); Assert.IsNotNull(response.Conversation.Summary); Assert.IsNull(response.Conversation.Summary.LastMessage); Assert.IsNotNull(response.Conversation.Messages); Assert.IsNotEmpty(response.Conversation.Messages); Assert.AreEqual(2, response.Conversation.Messages.Length); }
public void DeserializePeopleResponse() { string json = TestData["PeopleResponse.json"]; PeopleResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <PeopleResponse>(json); DateTime expectedDate0 = new DateTime(2017, 08, 05, 17, 03, 51).AddTicks(7279382); DateTime expectedDate1 = new DateTime(2017, 07, 22, 12, 55, 43).AddTicks(7301922); DateTime expectedDate2 = new DateTime(2013, 07, 01, 15, 10, 28).AddTicks(4600000); Assert.IsInstanceOf(typeof(IStringable), response); Assert.AreEqual(3, response.TotalCount); Assert.IsNotEmpty(response.People); Assert.AreEqual(3, response.People.Length); Assert.IsFalse(response.People[0].IsKnown); Assert.IsTrue(response.People[0].IsFavorite); Assert.IsTrue(response.People[0].IsFollowedByCaller); Assert.IsTrue(response.People[0].IsFollowingCaller); Assert.IsFalse(response.People[0].IsUnfollowingFeed); Assert.AreEqual(2580478784034343, response.People[0].Xuid); Assert.AreEqual(expectedDate0, response.People[0].AddedDateTimeUtc); Assert.IsNotNull(response.People[0].SocialNetworks); Assert.IsEmpty(response.People[0].SocialNetworks); Assert.IsFalse(response.People[1].IsKnown); Assert.IsTrue(response.People[1].IsFavorite); Assert.IsTrue(response.People[1].IsFollowedByCaller); Assert.IsTrue(response.People[1].IsFollowingCaller); Assert.IsFalse(response.People[1].IsUnfollowingFeed); Assert.AreEqual(2535771801919068, response.People[1].Xuid); Assert.AreEqual(expectedDate1, response.People[1].AddedDateTimeUtc); Assert.IsNotNull(response.People[1].SocialNetworks); Assert.IsEmpty(response.People[1].SocialNetworks); Assert.IsFalse(response.People[2].IsKnown); Assert.IsTrue(response.People[2].IsFavorite); Assert.IsTrue(response.People[2].IsFollowedByCaller); Assert.IsTrue(response.People[2].IsFollowingCaller); Assert.IsFalse(response.People[2].IsUnfollowingFeed); Assert.AreEqual(2508565379774180, response.People[2].Xuid); Assert.AreEqual(expectedDate2, response.People[2].AddedDateTimeUtc); Assert.IsNotNull(response.People[2].SocialNetworks); Assert.IsNotEmpty(response.People[2].SocialNetworks); Assert.AreEqual(1, response.People[2].SocialNetworks.Length); Assert.AreEqual("LegacyXboxLive", response.People[2].SocialNetworks[0]); }
public void DeserializePeopleSummaryResponse() { string json = TestData["PeopleSummaryResponse.json"]; PeopleSummaryResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <PeopleSummaryResponse>(json); Assert.IsFalse(response.IsTargetFollowingCaller); Assert.IsFalse(response.HasCallerMarkedTargetAsFavorite); Assert.IsTrue(response.IsCallerFollowingTarget); Assert.AreEqual("None", response.LegacyFriendStatus); Assert.IsFalse(response.HasCallerMarkedTargetAsKnown); Assert.AreEqual(94, response.TargetFollowingCount); Assert.AreEqual(3747535, response.TargetFollowerCount); }
public void DeserializeConversationsResponse() { string json = TestData["MessageConversationsResponse.json"]; ConversationsResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <ConversationsResponse>(json); Assert.IsInstanceOf(typeof(IStringable), response); Assert.IsNotNull(response.Results); Assert.IsNotEmpty(response.Results); Assert.AreEqual(2, response.Results.Length); Assert.IsNotNull(response.Results[0].LastMessage); Assert.IsNotNull(response.Results[1].LastMessage); Assert.IsNotEmpty(response.Results[0].LastMessage.Actions); Assert.IsNull(response.Results[1].LastMessage.Actions); }
public void CreateMessageSendRequest() { string expectedXuid = TestData["MessageSendMessageXuidRequest.json"]; string expectedGamertag = TestData["MessageSendMessageGtRequest.json"]; ulong[] xuids = new ulong[] { 2580478784034343, 2535771801919068, 2508565379774180 }; string[] gamertags = new string[] { "Gamertag1", "Gamertag2" }; MessageSendRequest requestXuid = new MessageSendRequest("TestString", xuids); MessageSendRequest requestGt = new MessageSendRequest("TestString", gamertags); string bodyXuid = NewtonsoftJsonSerializer.Create(JsonNamingStrategy.CamelCase) .Serialize(requestXuid); string bodyGt = NewtonsoftJsonSerializer.Create(JsonNamingStrategy.CamelCase) .Serialize(requestGt); Assert.AreEqual(expectedXuid, bodyXuid); Assert.AreEqual(expectedGamertag, bodyGt); }
public void DeserializePresenceBatchResponse() { string json = TestData["PresenceBatchResponse.json"]; PresenceBatchResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <PresenceBatchResponse>(json); DateTime expectedDate1 = new DateTime(2018, 6, 6, 19, 38, 14).AddTicks(0770062); DateTime expectedDate2 = new DateTime(2018, 5, 30, 20, 38, 4).AddTicks(3994143); Assert.IsInstanceOf(typeof(IStringable), response); Assert.AreEqual(3, response.Count); Assert.AreEqual(PresenceState.Offline, response[0].State); Assert.AreEqual(2580478784034343, response[0].Xuid); Assert.IsNull(response[0].Devices); Assert.IsNull(response[0].LastSeen); Assert.AreEqual(2535771801919068, response[1].Xuid); Assert.AreEqual(PresenceState.Online, response[1].State); Assert.IsNull(response[1].LastSeen); Assert.IsNotNull(response[1].Devices); Assert.AreEqual(1, response[1].Devices.Length); Assert.AreEqual(2, response[1].Devices[0].Titles.Length); Assert.AreEqual(DeviceType.XboxOne, response[1].Devices[0].Type); Assert.AreEqual(750323071, response[1].Devices[0].Titles[0].Id); Assert.AreEqual(TitleViewState.Background, response[1].Devices[0].Titles[0].Placement); Assert.AreEqual("Home", response[1].Devices[0].Titles[0].Name); Assert.AreEqual(expectedDate1, response[1].Devices[0].Titles[0].LastModified); Assert.AreEqual(TitleState.Active, response[1].Devices[0].Titles[0].State); Assert.IsNull(response[1].Devices[0].Titles[0].Activity); Assert.AreEqual(2508565379774180, response[2].Xuid); Assert.AreEqual(PresenceState.Offline, response[2].State); Assert.IsNotNull(response[2].LastSeen); Assert.AreEqual(DeviceType.WindowsOneCore, response[2].LastSeen.DeviceType); Assert.AreEqual(1653768775, response[2].LastSeen.TitleId); Assert.AreEqual("Cities: Skylines", response[2].LastSeen.TitleName); Assert.AreEqual(expectedDate2, response[2].LastSeen.Timestamp); }
public void DeserializePresenceResponse() { string json = TestData["PresenceResponse.json"]; PresenceResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <PresenceResponse>(json); DateTime expectedDate = new DateTime(2018, 6, 6, 19, 55, 10).AddTicks(5125990); Assert.AreEqual(2580478784034343, response.Xuid); Assert.AreEqual(PresenceState.Online, response.State); Assert.IsNull(response.LastSeen); Assert.IsNotNull(response.Devices); Assert.AreEqual(1, response.Devices.Length); Assert.AreEqual(1, response.Devices[0].Titles.Length); Assert.AreEqual(DeviceType.WindowsOneCore, response.Devices[0].Type); Assert.AreEqual(328178078, response.Devices[0].Titles[0].Id); Assert.AreEqual(TitleViewState.Full, response.Devices[0].Titles[0].Placement); Assert.AreEqual("Xbox App", response.Devices[0].Titles[0].Name); Assert.AreEqual(expectedDate, response.Devices[0].Titles[0].LastModified); Assert.AreEqual(TitleState.Active, response.Devices[0].Titles[0].State); Assert.IsNull(response.Devices[0].Titles[0].Activity); }
public void DeserializeInboxResponse() { string json = TestData["MessageInboxResponse.json"]; MessageInboxResponse response = NewtonsoftJsonSerializer .Create(JsonNamingStrategy.CamelCase) .Deserialize <MessageInboxResponse>(json); DateTime expectedDateSent0 = new DateTime(2018, 05, 20, 20, 08, 27); DateTime expectedDateExpiration0 = new DateTime(2018, 06, 19, 20, 08, 27); DateTime expectedDateSent1 = new DateTime(2018, 05, 08, 01, 07, 35); DateTime expectedDateExpiration1 = new DateTime(2018, 06, 07, 01, 07, 35); Assert.IsNotNull(response.PagingInfo); Assert.AreEqual(3, response.PagingInfo.TotalItems); Assert.IsNotEmpty(response.Results); Assert.AreEqual(3, response.Results.Length); Assert.IsNotNull(response.Results[0].Header); Assert.AreEqual(1191, response.Results[0].Header.Id); Assert.IsTrue(response.Results[0].Header.IsRead); Assert.AreEqual(2508565379774180, response.Results[0].Header.SenderXuid); Assert.AreEqual("Some Gamertag", response.Results[0].Header.Sender); Assert.AreEqual(expectedDateSent0, response.Results[0].Header.Sent); Assert.AreEqual(expectedDateExpiration0, response.Results[0].Header.Expiration); Assert.AreEqual("User", response.Results[0].Header.MessageType); Assert.IsTrue(response.Results[0].Header.HasText); Assert.IsFalse(response.Results[0].Header.HasPhoto); Assert.IsFalse(response.Results[0].Header.HasAudio); Assert.AreEqual("Inbox", response.Results[0].Header.MessageFolderType); Assert.AreEqual("Hey, how are you?", response.Results[0].MessageSummary); Assert.IsNull(response.Results[0].Actions); Assert.IsNotNull(response.Results[1].Header); Assert.AreEqual(1189, response.Results[1].Header.Id); Assert.IsTrue(response.Results[1].Header.IsRead); Assert.AreEqual(0, response.Results[1].Header.SenderXuid); Assert.AreEqual("Xbox Live", response.Results[1].Header.Sender); Assert.AreEqual(expectedDateSent1, response.Results[1].Header.Sent); Assert.AreEqual(expectedDateExpiration1, response.Results[1].Header.Expiration); Assert.AreEqual("Service", response.Results[1].Header.MessageType); Assert.IsTrue(response.Results[1].Header.HasText); Assert.IsFalse(response.Results[1].Header.HasPhoto); Assert.IsFalse(response.Results[1].Header.HasAudio); Assert.AreEqual("Inbox", response.Results[1].Header.MessageFolderType); Assert.AreEqual("Please remember: Xb", response.Results[1].MessageSummary); Assert.IsNotNull(response.Results[1].Actions); Assert.IsNotEmpty(response.Results[1].Actions); Assert.AreEqual(1, response.Results[2].Actions.Length); Assert.AreEqual(0, response.Results[2].Actions[0].Id); Assert.AreEqual("Redeem code", response.Results[2].Actions[0].VuiGui); Assert.IsNull(response.Results[2].Actions[0].VuiAlm); Assert.IsNull(response.Results[2].Actions[0].VuiPron); Assert.IsNull(response.Results[2].Actions[0].VuiConf); Assert.AreEqual("ABCDE-ABCDE-ABCDE-ABCDE-DCC9Z", response.Results[2].Actions[0].Launch); Assert.AreEqual(LaunchType.FiveByFive, response.Results[2].Actions[0].LaunchType); Assert.AreEqual("Thanks for parti...", response.Results[2].MessageSummary); }
public RestClientEx(string baseUrl, JsonNamingStrategy namingStrategy) : base(baseUrl) { SetSerializer(NewtonsoftJsonSerializer.Create(namingStrategy)); }
public IRestRequest AddJsonBody(Object obj, JsonNamingStrategy namingStrategy) { base.RequestFormat = DataFormat.Json; base.JsonSerializer = NewtonsoftJsonSerializer.Create(namingStrategy); return(base.AddJsonBody(obj)); }