Example #1
0
        private static void UpdateField <T>(int contentId, int fieldId, string fieldName, T value, string stringValue)
        {
            var articleId = GetArticleId(contentId);
            var data      = new[]
            {
                new ArticleData
                {
                    ContentId = contentId,
                    Id        = articleId,
                    Fields    = new[]
                    {
                        new FieldData
                        {
                            Id    = fieldId,
                            Value = stringValue
                        }
                    }.ToList()
                }
            };

            var result = ArticleService.BatchUpdate(data);

            Assert.That(result, Is.Not.Null.And.Empty, BatchUpdateResultIncorrect);

            var newValue = GetFieldValue <T>(contentId, fieldName, articleId);

            Assert.That(value, Is.EqualTo(newValue));
        }
Example #2
0
        private int SaveProducts(int productId, Dictionary <int, Product <CloningMode> > dictionary, List <Article> missedAggArticles)
        {
            foreach (var a in missedAggArticles)
            {
                FieldValue fieldValue = a.FieldValues.Single(fv => fv.Field.Aggregated);
                int        oldId      = Int32.Parse(fieldValue.Value);
                fieldValue.Value = dictionary[oldId].Article.Id.ToString();
            }
            var articles = dictionary.Values.Select(p => p.Article).Union(missedAggArticles).ToArray();

            var result = ArticleService.BatchUpdate(articles);

            return(result.First().CreatedArticleId);
        }
Example #3
0
        public void BatchUpdate_BaseContent_UpdateExtensionField()
        {
            var articleId = GetArticleId(BaseContentId);

            ClearClassifierField(articleId);

            var data = new[]
            {
                new ArticleData
                {
                    ContentId = BaseContentId,
                    Id        = articleId,
                    Fields    = new[]
                    {
                        new FieldData
                        {
                            Id         = BaseFieldEx2Id,
                            Value      = Ex21ContentId.ToString(),
                            ArticleIds = new[] { -1 }
                        }
                    }.ToList()
                },
                new ArticleData
                {
                    ContentId = Ex21ContentId,
                    Id        = -1
                }
            };

            var result = ArticleService.BatchUpdate(data);

            Assert.That(result, Is.Not.Null, BatchUpdateResultIncorrect);
            Assert.That(result, Has.Length.EqualTo(1));

            var extensionResult = result[0];

            Assert.That(extensionResult.ContentId, Is.EqualTo(Ex21ContentId));
            Assert.That(extensionResult.OriginalArticleId, Is.Not.EqualTo(extensionResult.CreatedArticleId));

            var parentValues = Global.GetFieldValues <decimal>(DbConnector, Ex21ContentId, Ex21Parent, new[] { extensionResult.CreatedArticleId });

            Assert.That(parentValues, Is.Not.Null, ValuesNotFound);
            Assert.That(parentValues, Has.Length.EqualTo(1));

            var parentValue = parentValues[0];

            Assert.That(articleId, Is.EqualTo(parentValue));
        }
Example #4
0
 public InsertData[] BatchUpdate(IEnumerable <Article> articles, bool createVersions = false)
 {
     return(ArticleService.BatchUpdate(articles, createVersions));
 }
Example #5
0
        public void BatchUpdate_DictionaryContent_InsertArticle()
        {
            var random = Guid.NewGuid().ToString();
            var key    = "key_" + random;
            var value  = "value_" + random;
            var data   = new[]
            {
                new ArticleData
                {
                    ContentId = DictionaryContentId,
                    Id        = -1,
                    Fields    = new[]
                    {
                        new FieldData
                        {
                            Id    = DictionaryKeyId,
                            Value = key
                        },
                        new FieldData
                        {
                            Id    = DictionaryValueId,
                            Value = value
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtMBackwardId
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtOBackwardId
                        }
                    }.ToList()
                }
            };

            var result = ArticleService.BatchUpdate(data);

            Assert.That(result, Is.Not.Null, BatchUpdateResultIncorrect);
            Assert.That(result, Has.Length.EqualTo(1));
            var articleResult = result[0];

            Assert.That(DictionaryContentId, Is.EqualTo(articleResult.ContentId));
            Assert.That(articleResult.OriginalArticleId, Is.Not.EqualTo(articleResult.CreatedArticleId));

            using (new QPConnectionScope(Global.ConnectionString))
            {
                var article = ArticleService.Read(articleResult.CreatedArticleId);
                Assert.That(article, Is.Not.Null, CantReadArticle);

                var keyFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryKey);
                Assert.That(keyFv, Is.Not.Null);
                Assert.That(key, Is.EqualTo(keyFv.Value));

                var valueFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryValue);
                Assert.That(valueFv, Is.Not.Null);
                Assert.That(value, Is.EqualTo(valueFv.Value));

                var mtoValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtOBackward, articleResult.CreatedArticleId);
                Assert.That(mtoValue, Is.EqualTo(BaseFieldOtMId), WrongMtORelation);

                var mtmValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtMBackward, articleResult.CreatedArticleId);
                Assert.That(mtmValue, Is.Not.Null, WrongMtMRelation);
                var mtmFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryFieldMtMBackward);
                Assert.That(mtmFv, Is.Not.Null);
                Assert.That(mtmFv.Field.Default, Is.EqualTo(mtmValue.Value.ToString(CultureInfo.InvariantCulture)), WrongMtMRelation);

                ArticleService.Delete(article.Id);
            }
        }
Example #6
0
        public void BatchUpdate_DictionaryContent_RecoverContentData()
        {
            var random = Guid.NewGuid().ToString();
            var key    = "key_" + random;
            var value  = "value_" + random;
            var data   = new[]
            {
                new ArticleData
                {
                    ContentId = DictionaryContentId,
                    Id        = -1,
                    Fields    = new[]
                    {
                        new FieldData
                        {
                            Id    = DictionaryKeyId,
                            Value = string.Empty
                        },
                        new FieldData
                        {
                            Id    = DictionaryValueId,
                            Value = string.Empty
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtMBackwardId
                        },
                        new FieldData
                        {
                            Id = DictionaryFieldMtOBackwardId
                        }
                    }.ToList()
                }
            };

            var result = ArticleService.BatchUpdate(data);

            Assert.That(result, Is.Not.Null, BatchUpdateResultIncorrect);
            Assert.That(result, Has.Length.EqualTo(1));

            var articleResult = result[0];

            Assert.That(articleResult.ContentId, Is.EqualTo(DictionaryContentId));
            Assert.That(articleResult.CreatedArticleId, Is.Not.EqualTo(articleResult.OriginalArticleId));

            data[0].Id = articleResult.CreatedArticleId;
            data[0].Fields[0].Value = key;
            data[0].Fields[1].Value = value;

            Global.ClearContentData(DbConnector, articleResult.CreatedArticleId);
            result = ArticleService.BatchUpdate(data);
            Assert.That(result, Is.Not.Null.And.Empty, BatchUpdateResultIncorrect);

            var contentData = Global.GetContentData(DbConnector, articleResult.CreatedArticleId);

            Assert.That(contentData, Is.Not.Null);
            Assert.That(contentData, Has.Length.EqualTo(4), ContentDataIsEmpty);

            using (new QPConnectionScope(Global.ConnectionString))
            {
                var article = ArticleService.Read(articleResult.CreatedArticleId);
                Assert.That(article, Is.Not.Null, CantReadArticle);

                var keyFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryKey);
                Assert.That(keyFv, Is.Not.Null);
                Assert.That(key, Is.EqualTo(keyFv.Value));
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryKeyId && itm.Data == key));

                var valueFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryValue);
                Assert.That(valueFv, Is.Not.Null);
                Assert.That(value, Is.EqualTo(valueFv.Value));
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryValueId && itm.Data == value));

                var mtoValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtOBackward, articleResult.CreatedArticleId);
                Assert.That(mtoValue, Is.EqualTo(BaseFieldOtMId), WrongMtORelation);
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryFieldMtOBackwardId && itm.Data == BaseFieldOtMId.ToString(CultureInfo.InvariantCulture)), WrongMtORelation);

                var mtmValue = GetFieldValue <decimal?>(DictionaryContentId, DictionaryFieldMtMBackward, articleResult.CreatedArticleId);
                Assert.That(mtmValue, Is.Not.Null, WrongMtMRelation);

                var mtmFv = article.FieldValues.Single(fv => fv.Field.Name == DictionaryFieldMtMBackward);
                Assert.That(mtmFv, Is.Not.Null);
                Assert.That(mtmFv.Field.Default, Is.EqualTo(mtmValue.Value.ToString(CultureInfo.InvariantCulture)), WrongMtMRelation);
                Assert.That(contentData.Any(itm => itm.FieldId == DictionaryFieldMtMBackwardId && itm.Data == mtmFv.Field.Default), WrongMtMRelation);

                ArticleService.Delete(article.Id);
            }
        }