public void should_throw_an_exception_when_given_an_empty_string_for_a_channel_name_async() { var reset = new AutoResetEvent(false); var pusherServer = ClientServerFactory.CreateServer(); ArgumentException caughtException = null; IGetResult <PresenceChannelMessage> result = null; try { pusherServer.FetchUsersFromPresenceChannelAsync <PresenceChannelMessage>(string.Empty, getResult => { result = getResult; reset.Set(); }); } catch (ArgumentException ex) { caughtException = ex; } StringAssert.IsMatch("channelName cannot be null or empty", caughtException.Message); }
public void It_should_be_possible_to_deserialize_the_request_result_body_as_an_object() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret); IGetResult <object> result = pusher.Get <object>("/channels"); Assert.NotNull(result.Data); }
public void It_should_be_possible_to_deserialize_the_a_channels_result_body_as_an_ChannelsList() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret); IGetResult <ChannelsList> result = pusher.Get <ChannelsList>("/channels"); Assert.IsTrue(result.Data.Channels.Count >= 0); }
/// <summary> /// Sets callback function to receive results of recognition /// </summary> /// <param name="resultReciever">interface link to the object - receiver</param> public void setResultRecieverMethod(IGetResult resultReciever) { if (_speechRecognizer != null) { _speechRecognizer.recognitionResult += resultReciever.getResult; } }
public ActionResult SendMessage(String message, String username) { Debug.WriteLine(username); var pusher = new Pusher("72484", "e9473350e86cf2fd89ac", "3e1cbae89445267f362f"); IGetResult <object> result = pusher.Get <object>("/channels/presence-channel/users"); PusherUsers users = new JavaScriptSerializer().Deserialize <PusherUsers>(result.Body); pusher.Trigger("presence-channel", "my_event", new { message = message, user = Session["FBID"], username = username }); // Database logging using (ChatContext db = new ChatContext()) { // Insert chat message row ChatMessage c = new ChatMessage { FBID = (String)Session["FBID"], Message = message, UserName = username, TimeSent = DateTime.Now }; db.ChatMessages.Add(c); db.SaveChanges(); // SaveChanges() is called to get a ChatMessageID value from the DB. // Insert user-to-chat rows for all connected users foreach (PusherUser user in users.users) { UserToChatMessage u = new UserToChatMessage { FBID = user.id.ToString(), ChatMessageID = c.ChatMessageID }; db.UserToChatMessages.Add(u); } db.SaveChanges(); } return(new HttpStatusCodeResult((int)HttpStatusCode.OK)); }
public void It_should_return_a_200_response() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret); IGetResult <object> result = pusher.Get <object>("/channels"); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public ResultsContainer(IBeam beam) { _beam = beam; NormalForce = new NormalForceResult(_beam); Shear = new ShearResult(_beam); BendingMoment = new BendingMomentResult(_beam); HorizontalDeflection = new HorizontalDeflectionResult(_beam); VerticalDeflection = new VerticalDeflectionResult(_beam); Rotation = new RotationResult(_beam); }
public async Task It_should_return_a_200_response() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost }); IGetResult <object> result = await pusher.GetAsync <object>("/channels"); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task It_should_be_possible_to_deserialize_the_request_result_body_as_an_object() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost }); IGetResult <object> result = await pusher.GetAsync <object>("/channels"); Assert.NotNull(result.Data); }
public async Task It_should_be_possible_to_deserialize_the_a_channels_result_body_as_an_ChannelsList() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost }); IGetResult <ChannelsList> result = await pusher.GetAsync <ChannelsList>("/channels"); Assert.IsTrue(result.Data.Channels.Count >= 0); }
public async Task Run() { var pusher = Controllers.Pusher.Pusher.Create(); IGetResult <object> result = await pusher.GetAsync <object>("/channels/global-channel", new { info = "subscription_count" }); SubCount sub = Newtonsoft.Json.JsonConvert.DeserializeObject <SubCount>(result.Body); if (sub.subscription_count == 0) { return; } await pusher.TriggerAsync(channelName : "global-channel", eventName : "user_count", data : sub.subscription_count); }
public async Task Should_get_an_empty_list_of_subscribed_users_asynchronously_when_using_the_correct_channel_name_and_no_users_are_subscribed() { var reset = new AutoResetEvent(false); string channelName = "presence-test-channel-async-2"; var pusherServer = ClientServerFactory.CreateServer(); IGetResult <PresenceChannelMessage> result = await pusherServer.FetchUsersFromPresenceChannelAsync <PresenceChannelMessage>(channelName); reset.Set(); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual(0, result.Data.Users.Length); }
public async Task should_return_bad_request_asynchronously_using_an_incorrect_channel_name_and_users_are_subscribed() { var reset = new AutoResetEvent(false); string channelName = "presence-test-channel-async-3"; var pusherServer = ClientServerFactory.CreateServer(); var pusherClient = ClientServerFactory.CreateClient(pusherServer, reset, channelName); IGetResult <PresenceChannelMessage> result = await pusherServer.FetchUsersFromPresenceChannelAsync <PresenceChannelMessage>("test-channel-async"); reset.Set(); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public async Task WhereCasWorks() { // insert a new document var id = Guid.NewGuid().ToString(); var pizza = new Pizza { SizeInches = 14, Toppings = new List <string> { "Pepperoni", "Mushroom" }, ExtraCheese = true }; await Collection.InsertAsync(id, pizza); // get document with CAS IGetResult getResult = await Collection.GetAsync(id); Assert.That(getResult.Cas, Is.GreaterThan(0)); // replace with CAS pizza.ExtraCheese = false; var replaceOptions = new ReplaceOptions(); replaceOptions.Cas(getResult.Cas); // there IS a CAS option for replace IMutationResult replaceResult = await Collection.ReplaceAsync(id, pizza, replaceOptions); Assert.That(replaceResult.Cas, Is.Not.EqualTo(getResult.Cas)); Assert.That(replaceResult.Cas, Is.GreaterThan(0)); // upsert with CAS? pizza.ExtraCheese = true; var upsertOptions = new UpsertOptions(); // upsertOptions.Cas(. . . ) there is no Cas option here! IMutationResult upsertResult = await Collection.UpsertAsync(id, pizza, upsertOptions); Assert.That(upsertResult.Cas, Is.GreaterThan(0)); Assert.That(upsertResult.Cas, Is.Not.EqualTo(getResult.Cas)); Assert.That(upsertResult.Cas, Is.Not.EqualTo(replaceResult.Cas)); // if you have a CAS value, use replace instead }
public void It_should_return_the_state_asynchronously_When_given_a_channel_name_that_exists_and_no_info_object_is_provided() { var reset = new AutoResetEvent(false); var channelName = "presence-multiple-state-channel-async-3"; var pusherServer = ClientServerFactory.CreateServer(); var pusherClient = ClientServerFactory.CreateClient(pusherServer, reset, channelName); IGetResult <object> result = null; pusherServer.FetchStateForChannelsAsync <object>(getResult => { result = getResult; reset.Set(); }); reset.WaitOne(TimeSpan.FromSeconds(30)); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task GetReturnIsDifferent() { // insert a document, no Document<T> necessary var id = Guid.NewGuid().ToString(); var pizza = new Pizza { SizeInches = 14, Toppings = new List <string> { "Pepperoni", "Mushrooms" }, ExtraCheese = true }; await Collection.InsertAsync(id, pizza); // get a document, no type necessary IGetResult result = await Collection.GetAsync(id); // use ContentAs to serialize to a given type Pizza myPizza = result.ContentAs <Pizza>(); Assert.That(myPizza.SizeInches, Is.EqualTo(pizza.SizeInches)); }
public void Should_get_a_list_of_subscribed_users_asynchronously_when_using_the_correct_channel_name_and_users_are_subscribed() { var reset = new AutoResetEvent(false); string channelName = "presence-test-channel-async-1"; var pusherServer = ClientServerFactory.CreateServer(); var pusherClient = ClientServerFactory.CreateClient(pusherServer, reset, channelName); IGetResult <PresenceChannelMessage> result = null; pusherServer.FetchUsersFromPresenceChannelAsync <PresenceChannelMessage>(channelName, getResult => { result = getResult; reset.Set(); }); reset.WaitOne(TimeSpan.FromSeconds(30)); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual(1, result.Data.Users.Length); Assert.AreEqual("Mr Pusher", result.Data.Users[0].Id); }
public void It_should_throw_an_exception_when_given_a_null_as_a_channel_name_async() { var pusherServer = ClientServerFactory.CreateServer(); var info = new { info = "user_count" }; ArgumentException caughtException = null; IGetResult <ChannelStateMessage> result = null; try { pusherServer.FetchStateForChannelAsync <ChannelStateMessage>(string.Empty, info, getResult => { result = getResult; }); } catch (ArgumentException ex) { caughtException = ex; } StringAssert.IsMatch("channelName cannot be null or empty", caughtException.Message); }
public void It_should_return_the_state_asynchronously_When_given_a_channel_name_that_exists() { var reset = new AutoResetEvent(false); var channelName = "presence-multiple-state-channel-async-3"; var pusherServer = ClientServerFactory.CreateServer(); var pusherClient = ClientServerFactory.CreateClient(pusherServer, reset, channelName); var info = new { info = "user_count", filter_by_prefix = "presence-" }; IGetResult <object> result = null; pusherServer.FetchStateForChannelsAsync <object>(info, getResult => { result = getResult; reset.Set(); }); reset.WaitOne(TimeSpan.FromSeconds(30)); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual(1, ((((Dictionary <string, object>)result.Data)["channels"] as Dictionary <string, object>)["presence-multiple-state-channel-async-3"] as Dictionary <string, object>)["user_count"]); }
public void It_should_not_return_the_state_asynchronously_based_When_given_a_channel_name_that_exists_an_bad_attributes() { AutoResetEvent reset = new AutoResetEvent(false); string channelName = "presence-multiple-state-channel-async-4"; var pusherServer = ClientServerFactory.CreateServer(); var pusherClient = ClientServerFactory.CreateClient(pusherServer, reset, channelName); var info = new { info = "does-not-exist" }; IGetResult <object> result = null; pusherServer.FetchStateForChannelsAsync <object>(info, getResult => { result = getResult; reset.Set(); }); reset.WaitOne(TimeSpan.FromSeconds(30)); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); StringAssert.IsMatch("info should be a comma separated list of attributes", (result as GetResult <object>).OriginalContent); }
public void It_should_return_the_state_asynchronously_When_given_a_channel_name_that_exists() { var reset = new AutoResetEvent(false); var channelName = "presence-state-channel-async-1"; var pusherServer = ClientServerFactory.CreateServer(); var pusherClient = ClientServerFactory.CreateClient(pusherServer, reset, channelName); var info = new { info = "user_count" }; IGetResult <ChannelStateMessage> result = null; pusherServer.FetchStateForChannelAsync <ChannelStateMessage>(channelName, info, getResult => { result = getResult; reset.Set(); }); reset.WaitOne(TimeSpan.FromSeconds(30)); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual(1, result.Data.User_Count); }