public async Task UpdateArticleAsyncTest()
        {
            // Create an article
            var     now = DateTime.Now;
            dynamic obj = new Article("object");

            obj.intfield     = 1;
            obj.decimalfield = 10.0m;
            obj.datefield    = "2012-12-20";
            obj.stringfield  = "initial";
            obj.Tags.Add("initial");

            var createdResponse = await(new CreateArticleRequest()
            {
                Article = obj
            }).ExecuteAsync();

            Assert.IsNotNull(createdResponse, "Article creation failed.");
            Assert.IsNotNull(createdResponse.Status, "Status is null.");
            Assert.IsTrue(createdResponse.Status.IsSuccessful,
                          createdResponse.Status.Message ?? "Create article failed.");
            var created = createdResponse.Article;

            // Update the article
            var updateRequest = new UpdateArticleRequest()
            {
                Id   = created.Id,
                Type = created.Type
            };

            updateRequest.PropertyUpdates["intfield"]     = "2";
            updateRequest.PropertyUpdates["decimalfield"] = 20.0m.ToString();
            updateRequest.PropertyUpdates["stringfield"]  = null;
            updateRequest.PropertyUpdates["datefield"]    = "2013-11-20";
            updateRequest.AddedTags.AddRange(new[] { "tag1", "tag2" });
            updateRequest.RemovedTags.AddRange(new[] { "initial" });
            var updatedResponse = await updateRequest.ExecuteAsync();


            Assert.IsNotNull(updatedResponse, "Update article response is null.");
            Assert.IsNotNull(updatedResponse.Status, "Update article response status is null.");
            Assert.IsNotNull(updatedResponse.Article, "Updated article is null.");
            var updated = updatedResponse.Article;

            Assert.IsTrue(updated.Get <string>("intfield") == "2");
            Assert.IsTrue(updated.Get <string>("decimalfield") == "20.0");
            Assert.IsTrue(updated.Get <string>("stringfield") == null);
            Assert.IsTrue(updated.Get <string>("datefield") == "2013-11-20");
            Assert.IsTrue(updated.Tags.Count() == 2);
            Assert.IsTrue(updated.Tags.Intersect(new[] { "tag1", "tag2" }).Count() == 2);
        }
        protected override async Task <Entity> UpdateAsync(IDictionary <string, object> propertyUpdates, IDictionary <string, string> attributeUpdates, IEnumerable <string> addedTags, IEnumerable <string> removedTags, int specificRevision)
        {
            var request = new UpdateArticleRequest {
                Id = this.Id, Type = this.Type
            };

            if (propertyUpdates != null && propertyUpdates.Count > 0)
            {
                propertyUpdates.For(x => request.PropertyUpdates[x.Key] = x.Value);
            }
            if (attributeUpdates != null && attributeUpdates.Count > 0)
            {
                attributeUpdates.For(x => request.AttributeUpdates[x.Key] = x.Value);
            }
            if (addedTags != null)
            {
                request.AddedTags.AddRange(addedTags);
            }
            if (removedTags != null)
            {
                request.RemovedTags.AddRange(removedTags);
            }

            // Check if an update is needed.
            if (request.PropertyUpdates.Count == 0 &&
                request.AttributeUpdates.Count == 0 &&
                request.AddedTags.Count == 0 &&
                request.RemovedTags.Count == 0)
            {
                return(null);
            }

            var response = await request.ExecuteAsync();

            if (response.Status.IsSuccessful == false)
            {
                throw response.Status.ToFault();
            }

            // 3. Update the last known state based on the differences
            Debug.Assert(response.Article != null, "If status is successful, then updated article should not be null.");
            return(response.Article);
        }
        public async Task BugId14Test()
        {
            // Ref: https://github.com/appacitive/Gossamer/issues/14
            // Updating a null property with a null value fails
            // Create an article
            var     now = DateTime.Now;
            dynamic obj = new Article("object");

            obj.intfield     = 1;
            obj.decimalfield = 10.0m;
            obj.stringfield  = null;

            var createdResponse = await(new CreateArticleRequest()
            {
                Article = obj
            }).ExecuteAsync();

            Assert.IsNotNull(createdResponse, "Article creation failed.");
            Assert.IsNotNull(createdResponse.Status, "Status is null.");
            Assert.IsTrue(createdResponse.Status.IsSuccessful, createdResponse.Status.Message ?? "Create article failed.");
            var created = createdResponse.Article;

            // Update the article twice
            for (int i = 0; i < 2; i++)
            {
                var updateRequest = new UpdateArticleRequest()
                {
                    Id   = created.Id,
                    Type = created.Type
                };
                updateRequest.PropertyUpdates["stringfield"] = null;
                var updatedResponse = await updateRequest.ExecuteAsync();

                Assert.IsNotNull(updatedResponse, "Update article response is null.");
                Assert.IsNotNull(updatedResponse.Status, "Update article response status is null.");
                Assert.IsTrue(updatedResponse.Status.IsSuccessful, updatedResponse.Status.Message ?? "NULL");
                Assert.IsNotNull(updatedResponse.Article, "Updated article is null.");
                var updated = updatedResponse.Article;
                Assert.IsTrue(updated["stringfield"] is NullValue);
            }
        }