Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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));
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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"]);
        }
Example #13
0
        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"]);
        }
Example #14
0
        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);
        }
Example #15
0
        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);
        }