public async Task UpdateArticleWithNoUpdateAsyncTest()
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            // Create the article
            dynamic article = new Article("object");
            decimal pi      = 22.0m / 7.0m;

            article.intfield     = 1;
            article.decimalfield = pi;

            var saved = await ObjectHelper.CreateNewAsync(article as Article);

            var firstUpdateTime = saved.UtcLastUpdated;

            stopWatch.Start();

            //Dummy update, shouldn't make any api call, assuming api call takes atleast 50 ms
            await saved.SaveAsync();

            stopWatch.Stop();

            Assert.IsTrue(stopWatch.ElapsedMilliseconds < 50);
            Console.WriteLine(stopWatch.ElapsedMilliseconds);

            //Cleanup
            await Articles.DeleteAsync(saved.Type, saved.Id);
        }
예제 #2
0
        public async Task GetBotSettingsWithExistingDataTest()
        {
            // Create dummy data for deployments
            var deployment = new Article("deployment");

            deployment.Set("name", Unique.NewString);
            deployment.Set("description", "lorem ipsum etc..");
            await deployment.SaveAsync();;

            // Insert some bot settings
            var bot = new Article("bot");

            bot.Set("supplier_family", "pegasus");
            bot.Set("version_to_start_from", 123);
            bot.Set("min_poll_interval_in_seconds", 10);
            bot.Set("max_poll_interval_in_seconds", 100);
            bot.Set("bot_type", "hotel_content");
            await Connection.New("bots")
            .FromExistingArticle("deployment", deployment.Id)
            .ToNewArticle("bot", bot)
            .SaveAsync();

            // Test sync db
            ISyncDb syncDb = new SyncDb();
            var     bots   = await syncDb.GetBotSettings(deployment.Get <string>("name"));

            var ids = bots.Select(b => b.Id);

            Assert.IsTrue(ids.Union(new[] { bot.Id }).Count() == 1);

            // Clean up the test data
            await Articles.DeleteAsync("bot", bot.Id, true);

            await Articles.DeleteAsync("deployment", deployment.Id);
        }
        public async Task UpdateArticleAttributeAsyncTest()
        {
            string attrToRemove = "one";
            string attrPersist  = "two";
            string attrToAdd    = "three";

            // Create the article
            dynamic article = new Article("object");
            decimal pi      = 22.0m / 7.0m;

            article.intfield     = 1;
            article.decimalfield = pi;

            //Add Attributes
            article.SetAttribute(attrToRemove, attrToRemove);
            article.SetAttribute(attrPersist, attrPersist);

            var saved = await ObjectHelper.CreateNewAsync(article as Article);

            // Get the newly created article
            var afterFirstUpdate = await Articles.GetAsync("object", saved.Id);

            Assert.IsNotNull(afterFirstUpdate);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToRemove, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterFirstUpdate.Attributes.Count() == 2);

            //Add/Remove Attribute
            afterFirstUpdate.RemoveAttribute(attrToRemove);
            afterFirstUpdate.SetAttribute(attrToAdd, attrToAdd);
            await afterFirstUpdate.SaveAsync();

            var afterSecondUpdate = await Articles.GetAsync("object", saved.Id);

            Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToAdd, StringComparison.OrdinalIgnoreCase)) == 1);
            Assert.IsTrue(afterSecondUpdate.Attributes.Count() == 2);

            //Cleanup
            await Articles.DeleteAsync(afterSecondUpdate.Type, afterSecondUpdate.Id);
        }
        public async Task DeleteArticleAsyncTest()
        {
            // Create the article
            var saved = await ObjectHelper.CreateNewAsync();

            // Delete the article
            await Articles.DeleteAsync("object", saved.Id);

            // Try and get and confirm that the article is deleted.
            try
            {
                var copy = await Articles.GetAsync("object", saved.Id);

                Assert.Fail("Operation should have faulted since the article has been deleted.");
            }
            catch (Net45.AppacitiveException ex)
            {
                var msg = string.Format("Cannot locate article of type 'object' and id {0}.", saved.Id);
                Assert.IsTrue(ex.Message == msg);
            }
        }