Beispiel #1
0
        public void TestCreateRushObjectAsDynamic()
        {
            dynamic obj = new RushObject("User");

            obj.Name = "John Doe";
            Assert.IsNotNull(obj.Name);
        }
Beispiel #2
0
        public void TestCreateRushObjectUsingIndexer()
        {
            var obj = new RushObject("User");

            obj["Name"] = "John Doe";
            Assert.IsNotNull(obj["Name"]);
        }
Beispiel #3
0
        public async Task TestSaveRushObjectAsync()
        {
            RushObject obj = new RushObject("GameScore");

            obj["PlayerName"] = "John Doe";
            obj["Score"]      = 12000;
            obj["Array"]      = new string[] { "A", "B", "C" };

            await obj.SaveAsync();

            Assert.IsNotNull(obj.ObjectId);
        }
Beispiel #4
0
        public void TestGetFromStoreMongoDbRepository()
        {
            var obj = new RushObject("Player");

            obj["Name"] = "John Doe";

            var store = new StoreMongoDbRepository();

            store.Resource = obj.ClassName;
            store.Insert(obj);

            var fromDb = store.Get(obj.ObjectId);

            Assert.IsNotNull(fromDb);
        }
Beispiel #5
0
        public static async Task SaveAsync(this RushObject obj, CancellationToken cancellationToken)
        {
            var json    = JsonConvert.SerializeObject(obj.AsDictionary());
            var content = new StringContent(json);

            var client = new HttpClient();
            var result = await client.PostAsync(storeBaseUrl + obj.ClassName, content, cancellationToken);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                var saved = await result.Content.ReadAsStringAsync();
            }
            else
            {
            }
        }
Beispiel #6
0
        public void TestUpdateStoreMongoDbRepository()
        {
            var obj = new RushObject("Player");

            obj["Name"] = "John Doe";

            var store = new StoreMongoDbRepository();

            store.Resource = obj.ClassName;
            store.Insert(obj);

            obj["UpdateWorks"] = true;
            store.Update(obj.ObjectId, obj);

            Assert.IsNotNull(obj["UpdateWorks"]);
        }
Beispiel #7
0
        public void TestInsertIntoStoreMongoDbRepository()
        {
            var obj = new RushObject("Player");

            obj["Name"]  = "John Doe";
            obj["Score"] = 1000;
            obj["Array"] = new string[] { "A", "B", "C" };

            var store = new StoreMongoDbRepository();

            store.Resource = obj.ClassName;
            store.Insert(obj);

            Assert.IsNotNull(obj.ObjectId);
            Assert.IsNotNull(obj.CreatedAt);
        }
Beispiel #8
0
        public void TestDeleteStoreMongoDbRepository()
        {
            var obj = new RushObject("Player");

            obj["Name"] = "John Doe";

            var store = new StoreMongoDbRepository();

            store.Resource = obj.ClassName;
            store.Insert(obj);

            store.Delete(obj.ObjectId);

            var result = store.Get(obj.ObjectId);

            Assert.IsNull(result);
        }
Beispiel #9
0
 public static Task SaveAsync(this RushObject obj)
 {
     return(SaveAsync(obj, CancellationToken.None));
 }
Beispiel #10
0
 public static IDictionary <string, object> AsDictionary(this RushObject obj)
 {
     return(obj.GetPropertyValues().ToDictionary(p => p.Key, p => p.Value));
 }