public async Task DeleteAllAdditionalClients() { var clientsResponse = await Connector.Get("client.api/list"); Assert.AreEqual(HttpStatusCode.OK, clientsResponse.StatusCode); var clientsResponsePayload = await clientsResponse.Content.ReadAsStringAsync(); var clientsResponseObj = ResponseParser.Deserialize <ClientsResponse>(clientsResponsePayload); foreach (var client in clientsResponseObj.Clients) { if (client.Name == "Redington") { continue; } Debug.WriteLine("Deleting " + client.Id); var request = new ClientRequest() { Id = client.Id }; var xml = ResponseParser.Serialize(request); Debug.WriteLine(xml); var deleteRequestContent = new StringContent(xml); var deleteResponse = await Connector.Post("/client.api/delete", deleteRequestContent); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.StatusCode); } }
public void CategoryList_Deserialization_WorksOk() { var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Response api-method=\"List\"><Status>OK</Status><Categories /></Response>"; var x = ResponseParser.Deserialize <CategoriesResponse>(content); Assert.AreEqual(0, x.Categories.Count); }
public async Task CreateAndDeleteClient() { var createRequestObject = new XmlClient() { Name = "TestingClient" + Guid.NewGuid() }; var serializedXml = ResponseParser.Serialize(createRequestObject); Debug.WriteLine("CreateClient XML Request: " + serializedXml); var content = new StringContent(serializedXml); var createResponse = await Connector.Post("client.api/add", content); Assert.AreEqual(HttpStatusCode.OK, createResponse.StatusCode); var responsePayload = await createResponse.Content.ReadAsStringAsync(); Debug.WriteLine("CreateClient XML Response: " + responsePayload); var response = ResponseParser.Deserialize <ClientResponse>(responsePayload); var request = new ClientRequest() { Id = response.Client.Id }; var xml = ResponseParser.Serialize(request); Debug.WriteLine(xml); var deleteRequestContent = new StringContent(xml); var deleteResponse = await Connector.Post("/client.api/delete", deleteRequestContent); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.StatusCode); }
public void ShouldRemapMessagesToConcreteTypes() { var meMessage = new MeMessage { Type = EventType.Message, Subtype = MessageSubType.MeMessage, Text = "me", Team = "team1" }; var topicMessage = new ChannelTopic { Type = EventType.Message, Subtype = MessageSubType.ChannelTopic, Topic = "topic" }; var plainMessage = new PlainMessage { Type = EventType.Message, Subtype = MessageSubType.PlainMessage, Text = "text" }; var parser = new ResponseParser(); var messages = new List <MessageBase> { parser.Deserialize <MessageBase>(parser.SerializeMessage(meMessage)), parser.Deserialize <MessageBase>(parser.SerializeMessage(topicMessage)), parser.Deserialize <MessageBase>(parser.SerializeMessage(plainMessage)) }; var concreteMessages = parser.RemapMessagesToConcreteTypes(messages).ToList(); Assert.IsType <MeMessage>(concreteMessages[0]); Assert.IsType <ChannelTopic>(concreteMessages[1]); Assert.IsType <PlainMessage>(concreteMessages[2]); Assert.Equal(EventType.Message, concreteMessages[0].Type); Assert.Equal(MessageSubType.MeMessage, concreteMessages[0].Subtype); Assert.Equal("me", concreteMessages[0].Text); Assert.Equal("team1", concreteMessages[0].Team); Assert.Equal(EventType.Message, concreteMessages[1].Type); Assert.Equal("topic", ((ChannelTopic)concreteMessages[1]).Topic); }
public async Task GetCategoriesList() { var response = await Connector.Get("category.api/list"); var obj = ResponseParser.Deserialize <CategoriesResponse>(await response.Content.ReadAsStringAsync()); Assert.AreEqual(Status.Success, obj.Status); Assert.AreEqual(0, obj.Categories.Count); }
public void ClientAdd_Deserialization_ReturnProperClientObject() { var content = "<Response api-method=\"Add\"><Status>OK</Status><Client><ID>11587321</ID><Name>TestingClient2185576d-ba67-41bb-a66c-59cb1760b831</Name><Address></Address><City></City><Region></Region><PostCode></PostCode><Country></Country><PostalAddress></PostalAddress><PostalCity></PostalCity><PostalRegion></PostalRegion><PostalPostCode></PostalPostCode><PostalCountry></PostalCountry><Phone></Phone><Fax></Fax><Website></Website><ReferralSource></ReferralSource><ExportCode></ExportCode><IsProspect>No</IsProspect><IsArchived>No</IsArchived><IsDeleted>No</IsDeleted><Contacts /><Notes /></Client></Response>"; var response = ResponseParser.Deserialize <ClientResponse>(content); Assert.AreEqual(11587321, response.Client.Id); }
public void CanDeserializeHelloEvent() { var messageContent = @"{""type"":""hello""}"; var parser = new ResponseParser(); var result = parser.Deserialize<Hello>(messageContent); Assert.NotNull(result); Assert.Equal(EventType.Hello, result.Type); }
public void ErrorResponse_Deserialization_ThrowsApplicationException() { var messageContents = @"<?xml version=""1.0"" encoding=""UTF-8""?> <Response> <Status>ERROR</Status> <ErrorDescription>A detailed explanation of the error</ErrorDescription> </Response>"; Assert.Throws <ApplicationException>(() => ResponseParser.Deserialize <ErrorResponse>(messageContents)); }
public void CanDeserializeHelloEvent() { var messageContent = @"{""type"":""hello""}"; var parser = new ResponseParser(); var result = parser.Deserialize <Hello>(messageContent); Assert.NotNull(result); Assert.Equal(EventType.Hello, result.Type); }
public void CanDeserializeMeMessage() { var messageContent = @"{""type"":""message"",""subtype"":""me_message""}"; var parser = new ResponseParser(); var result = parser.Deserialize<MeMessage>(messageContent); Assert.NotNull(result); Assert.Equal(EventType.Message, result.Type); Assert.Equal(MessageSubType.MeMessage, result.Subtype); }
public void CanDeserializeMeMessage() { var messageContent = @"{""type"":""message"",""subtype"":""me_message""}"; var parser = new ResponseParser(); var result = parser.Deserialize <MeMessage>(messageContent); Assert.NotNull(result); Assert.Equal(EventType.Message, result.Type); Assert.Equal(MessageSubType.MeMessage, result.Subtype); }
public void CanDeserializeEventWithExtraData() { var messageContent = @"{""type"":""message"",""subtype"":""me_message"",""something"":""extra""}"; var parser = new ResponseParser(); var result = parser.Deserialize<MeMessage>(messageContent); Assert.NotNull(result); Assert.Equal(EventType.Message, result.Type); Assert.Equal(MessageSubType.MeMessage, result.Subtype); Assert.Equal("extra", result.UnmatchedAdditionalJsonData["something"]); }
public void CanDeserializeEventWithExtraData() { var messageContent = @"{""type"":""message"",""subtype"":""me_message"",""something"":""extra""}"; var parser = new ResponseParser(); var result = parser.Deserialize <MeMessage>(messageContent); Assert.NotNull(result); Assert.Equal(EventType.Message, result.Type); Assert.Equal(MessageSubType.MeMessage, result.Subtype); Assert.Equal("extra", result.UnmatchedAdditionalJsonData["something"]); }
public void ClientList_Deserialization_WorksOk() { var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Response api-method=\"List\"><Status>OK</Status><Clients><Client><ID>11571445</ID><Name>Redington</Name><Address></Address><City></City><Region></Region><PostCode></PostCode><Country></Country><PostalAddress></PostalAddress><PostalCity></PostalCity><PostalRegion></PostalRegion><PostalPostCode></PostalPostCode><PostalCountry></PostalCountry><Phone></Phone><Fax></Fax><Website></Website><ReferralSource></ReferralSource><ExportCode></ExportCode><IsProspect>No</IsProspect><IsArchived>No</IsArchived><IsDeleted>Yes</IsDeleted><Contacts /></Client></Clients></Response>"; var x = ResponseParser.Deserialize <ClientsResponse>(content); Assert.AreEqual(1, x.Clients.Count); var redington = x.Clients.Single(); Assert.AreEqual(11571445, redington.Id); Assert.AreEqual("Redington", redington.Name); Assert.AreEqual("No", redington.IsProspect); Assert.AreEqual("Yes", redington.IsDeleted); Assert.AreEqual("No", redington.IsArchived); }
public void ShouldRemapMessagesToConcreteTypes() { var meMessage = new MeMessage { Type = EventType.Message, Subtype = MessageSubType.MeMessage, Text = "me", Team = "team1" }; var topicMessage = new ChannelTopic { Type = EventType.Message, Subtype = MessageSubType.ChannelTopic, Topic = "topic" }; var plainMessage = new PlainMessage { Type = EventType.Message, Subtype = MessageSubType.PlainMessage, Text = "text" }; var parser = new ResponseParser(); var messages = new List<MessageBase> { parser.Deserialize<MessageBase>(parser.SerializeMessage(meMessage)), parser.Deserialize<MessageBase>(parser.SerializeMessage(topicMessage)), parser.Deserialize<MessageBase>(parser.SerializeMessage(plainMessage)) }; var concreteMessages = parser.RemapMessagesToConcreteTypes(messages).ToList(); Assert.IsType<MeMessage>(concreteMessages[0]); Assert.IsType<ChannelTopic>(concreteMessages[1]); Assert.IsType<PlainMessage>(concreteMessages[2]); Assert.Equal(EventType.Message, concreteMessages[0].Type); Assert.Equal(MessageSubType.MeMessage, concreteMessages[0].Subtype); Assert.Equal("me", concreteMessages[0].Text); Assert.Equal("team1", concreteMessages[0].Team); Assert.Equal(EventType.Message, concreteMessages[1].Type); Assert.Equal("topic", ((ChannelTopic)concreteMessages[1]).Topic); }