public void ReadAuthFails() { Portable.Firebase firebase = new Portable.Firebase(TestConfig.RootUrl); try { firebase.Get("sec/no/shouldFail"); Assert.Fail("Should have thrown HTTP 401 error"); } catch (AggregateException ex) { Exception cur = ex; while (cur != null) { if (cur is HttpRequestException && cur.Message.Contains("401")) { // we found our auth exception return; } cur = cur.InnerException; } throw; } }
public void ReadAuthPasses() { string authToken = getToken(); Portable.Firebase firebase = new Portable.Firebase(TestConfig.RootUrl, authToken); firebase.Get("sec/no/shouldPass"); }
public void EndToEnd() { Portable.Firebase fb = new Portable.Firebase(new Uri(TestConfig.RootUrl)); string testRoot = string.Format("/test/{0}", DateTime.UtcNow.Ticks); List <ValueAddedEventArgs> callbackResults = new List <ValueAddedEventArgs>(); List <string> created = new List <string>(); ManualResetEvent received = new ManualResetEvent(false); using (fb.GetStreaming(testRoot, added: (sender, args) => { callbackResults.Add(args); received.Set(); })) { for (int i = 0; i < 10; i++) { created.Add(fb.Post(testRoot, string.Format("{{\"value\": \"{0}\"}}", i))); received.WaitOne(); received.Reset(); } } // now go take everything we created and load it from our // stream gets. Read the values out and then re-fetch them // individually. Compare the values to make sure they match. // Then delete the individual node and perform another // get to make sure it is missing. foreach (string keyResponse in created) { dynamic keyObj = JsonConvert.DeserializeObject(keyResponse); string key = keyObj.name; var found = callbackResults.First(c => c.Path.Contains(key)); Assert.IsNotNull(found, "The key was added but missing from stream"); string singlePath = testRoot + found.Path; string single = fb.Get(singlePath); dynamic payloadSingle = JsonConvert.DeserializeObject(single); Assert.AreEqual(found.Data, payloadSingle); fb.Delete(singlePath); string missing = fb.Get(singlePath); Assert.AreEqual("null", missing); } fb.Delete(testRoot); }
public void ComplexTypes() { Person me = new Person { Name = "Me Horvick", Age = 37, Address = new Address { StreetAddress1 = "123 Generic Suburban St.", City = "Raleigh", State = "NC", Zip = "12345", }, }; Person wife = new Person { Name = "Spouse Horvick", Age = 38, Address = me.Address, }; Person kid1 = new Person { Name = "Kid1 Horvick", Age = 17, Address = me.Address, }; Person kid2 = new Person { Name = "Kid2 Horvick", Age = 14, Address = me.Address, }; me.Children.Add(kid1); me.Children.Add(kid2); wife.Children.Add(kid1); wife.Children.Add(kid2); string blob = JsonConvert.SerializeObject(me); Portable.Firebase fb = new Portable.Firebase(TestConfig.RootUrl); fb.Put("test/people/me", blob); string gotBack = fb.Get("test/people/me"); Person meAgain = JsonConvert.DeserializeObject <Person>(gotBack); Assert.IsTrue(me.Equals(meAgain)); }