Exemplo n.º 1
0
        public void Append_ToDictionary_DuplicateAndNonDuplicateKey()
        {
            Tuple <Table <EntityWithDictionaryType>, List <EntityWithDictionaryType> > tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(_session);
            Table <EntityWithDictionaryType> table            = tupleDictionaryType.Item1;
            List <EntityWithDictionaryType>  expectedEntities = tupleDictionaryType.Item2;

            EntityWithDictionaryType    singleEntity = expectedEntities.First();
            Dictionary <string, string> dictToAdd    = new Dictionary <string, string>()
            {
                { "randomKey_" + Randomm.RandomAlphaNum(10), "randomVal_" + Randomm.RandomAlphaNum(10) },
                { "randomKey_" + Randomm.RandomAlphaNum(10), "randomVal_" + Randomm.RandomAlphaNum(10) },
                { singleEntity.DictionaryType.First().Key, singleEntity.DictionaryType.First().Value }
            };
            EntityWithDictionaryType expectedEntity = singleEntity.Clone();

            foreach (var keyValPair in dictToAdd)
            {
                if (!expectedEntity.DictionaryType.ContainsKey(keyValPair.Key))
                {
                    expectedEntity.DictionaryType.Add(keyValPair.Key, keyValPair.Value);
                }
            }

            // Append the values
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithDictionaryType {
                DictionaryType = CqlOperator.Append(dictToAdd)
            }).Update().Execute();
            // Validate the final state of the data
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            Assert.AreNotEqual(expectedEntity.DictionaryType, singleEntity.DictionaryType);
            expectedEntity.AssertEquals(entityList[0]);
        }
Exemplo n.º 2
0
        public void Prepend_Dictionary()
        {
            Tuple <Table <EntityWithDictionaryType>, List <EntityWithDictionaryType> > tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(_session);
            Table <EntityWithDictionaryType> table            = tupleDictionaryType.Item1;
            List <EntityWithDictionaryType>  expectedEntities = tupleDictionaryType.Item2;

            Dictionary <string, string> dictToAdd = new Dictionary <string, string>()
            {
                { "randomKey_" + Randomm.RandomAlphaNum(10), "randomVal_" + Randomm.RandomAlphaNum(10) },
                { "randomKey_" + Randomm.RandomAlphaNum(10), "randomVal_" + Randomm.RandomAlphaNum(10) },
            };

            EntityWithDictionaryType singleEntity   = expectedEntities.First();
            EntityWithDictionaryType expectedEntity = singleEntity.Clone();

            expectedEntity.DictionaryType.Clear();
            var dictToAddReversed = new Dictionary <string, string>(dictToAdd).Reverse();

            foreach (var keyValPair in dictToAddReversed)
            {
                expectedEntity.DictionaryType.Add(keyValPair.Key, keyValPair.Value);
            }
            foreach (var keyValPair in singleEntity.DictionaryType)
            {
                expectedEntity.DictionaryType.Add(keyValPair.Key, keyValPair.Value);
            }

            // Append the values
            string expectedErrMsg = "Invalid operation (dictionarytype = ? - dictionarytype) for non list column dictionarytype";
            var    err            = Assert.Throws <InvalidQueryException>(() => table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithDictionaryType {
                DictionaryType = CqlOperator.Prepend(dictToAdd)
            }).Update().Execute());

            Assert.AreEqual(expectedErrMsg, err.Message);
        }
Exemplo n.º 3
0
        public void Append_ToDictionary_EmptyDictionary()
        {
            Tuple <Table <EntityWithDictionaryType>, List <EntityWithDictionaryType> > tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(_session);
            Table <EntityWithDictionaryType> table            = tupleDictionaryType.Item1;
            List <EntityWithDictionaryType>  expectedEntities = tupleDictionaryType.Item2;

            Dictionary <string, string> dictToAdd = new Dictionary <string, string>()
            {
            };
            EntityWithDictionaryType singleEntity   = expectedEntities.First();
            EntityWithDictionaryType expectedEntity = singleEntity.Clone();

            foreach (var keyValPair in dictToAdd)
            {
                expectedEntity.DictionaryType.Add(keyValPair.Key, keyValPair.Value);
            }

            // Append the values
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithDictionaryType {
                DictionaryType = CqlOperator.Append(dictToAdd)
            }).Update().Execute();
            // Validate the final state of the data
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            expectedEntity.AssertEquals(entityList[0]);
        }
Exemplo n.º 4
0
        public void Append_ToDictionary_DuplicateKey()
        {
            Tuple <Table <EntityWithDictionaryType>, List <EntityWithDictionaryType> > tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(_session);
            Table <EntityWithDictionaryType> table            = tupleDictionaryType.Item1;
            List <EntityWithDictionaryType>  expectedEntities = tupleDictionaryType.Item2;

            EntityWithDictionaryType singleEntity   = expectedEntities.First();
            EntityWithDictionaryType expectedEntity = singleEntity.Clone();

            Assert.AreEqual(expectedEntity.DictionaryType, singleEntity.DictionaryType);

            // Append the values
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithDictionaryType {
                DictionaryType = CqlOperator.Append(singleEntity.DictionaryType)
            }).Update().Execute();

            // Validate the final state of the data
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            expectedEntity.AssertEquals(entityList[0]);
        }
Exemplo n.º 5
0
        public void SubtractAssign_FromDictionary_NotAllowed()
        {
            Tuple <Table <EntityWithDictionaryType>, List <EntityWithDictionaryType> > tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(_session);
            Table <EntityWithDictionaryType> table            = tupleDictionaryType.Item1;
            List <EntityWithDictionaryType>  expectedEntities = tupleDictionaryType.Item2;

            EntityWithDictionaryType singleEntity   = expectedEntities.First();
            EntityWithDictionaryType expectedEntity = singleEntity.Clone();

            expectedEntity.DictionaryType.Clear();
            Dictionary <string, string> dictToDelete = new Dictionary <string, string>()
            {
                { singleEntity.DictionaryType.First().Key, singleEntity.DictionaryType.First().Value },
            };

            // Attempt to remove the data
            var updateStatement = table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithDictionaryType {
                DictionaryType = CqlOperator.SubstractAssign(dictToDelete)
            }).Update();

            Assert.Throws <InvalidQueryException>(() => updateStatement.Execute());
        }