Пример #1
0
 public void MessagesMadeFromSetContainKeyGivenToConstructor(string key)
 {
     Chatbase.MessageSet set = new Chatbase.MessageSet(key);
     Chatbase.Message    msg = set.NewMessage();
     Assert.Equal(msg.api_key, key);
     set.Add(msg);
     Assert.Equal(set.GetMessages().Count, 1);
 }
Пример #2
0
        public async Task <HttpResponseMessage> Send(MessageSet set)
        {
            MemoryStream stream            = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(
                typeof(MessageSet),
                new Type[] { typeof(MessageCollection), typeof(Message) });

            ser.WriteObject(stream, set);
            stream.Position = 0;
            StreamReader  sr      = new StreamReader(stream);
            string        json    = sr.ReadToEnd();
            string        url     = String.Format(Client.BatchMessageEndpoint, set.api_key);
            StringContent content = new StringContent(json, Encoding.UTF8, Client.ContentType);

            return(await client.PostAsync(url, content));
        }
Пример #3
0
        public void SendingValidSetReturnsSuccess(string uid, string plt, string ver)
        {
            string key = Environment.GetEnvironmentVariable("CB_TEST_API_KEY");

            if (String.IsNullOrEmpty(key))
            {
                ChatbaseClientUnitTests.PrintNoAPIKeyWarning();
            }
            else
            {
                Chatbase.MessageSet set = new Chatbase.MessageSet(key);
                Chatbase.Message    msg = set.NewMessage();
                msg.user_id  = uid;
                msg.platform = plt;
                msg.version  = ver;
                set.Add(msg);
                var resp = _client.Send(set).Result;
                Assert.Equal(resp.StatusCode, HttpStatusCode.OK);
            }
        }
Пример #4
0
 public void KeyToConstructorPropagatesToInstance(string key)
 {
     Chatbase.MessageSet set = new Chatbase.MessageSet(key);
     Assert.Equal(set.api_key, key);
 }