示例#1
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);
        }
示例#2
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]);
        }
示例#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]);
        }
        public void SubtractAssign_FromDictionary(int remainingKeysCount, params string[] keysToRemove)
        {
            var tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(Session);
            var table = tupleDictionaryType.Item1;

            var newdict = new Dictionary <string, string>
            {
                { "firstKey", "firstvalue" },
                { "secondKey", "secondvalue" },
                { "lastkey", "lastvalue" },
            };
            var id        = Guid.NewGuid().ToString();
            var newEntity = new EntityWithDictionaryType
            {
                Id             = id,
                DictionaryType = newdict
            };

            table.Insert(newEntity).Execute();

            table.Where(t => t.Id == newEntity.Id).Select(x => new EntityWithDictionaryType
            {
                DictionaryType = x.DictionaryType.SubstractAssign(keysToRemove)
            }).Update().Execute();
            var updatedEntity = table.Where(t => t.Id == newEntity.Id).Execute().FirstOrDefault();

            Assert.NotNull(updatedEntity);
            Assert.AreEqual(remainingKeysCount, updatedEntity.DictionaryType.Count);
        }
        public void SubtractAssign_FromDictionary_NotAllowed()
        {
            var tupleDictionaryType = EntityWithDictionaryType.SetupDefaultTable(Session);
            var table            = tupleDictionaryType.Item1;
            var expectedEntities = tupleDictionaryType.Item2;

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

            expectedEntity.DictionaryType.Clear();
            var 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
            {
                // Use incorrect substract assign overload
                DictionaryType = CqlOperator.SubstractAssign(dictToDelete)
            }).Update();

            Assert.Throws <InvalidOperationException>(() => updateStatement.Execute(),
                                                      "Use dedicated method to substract assign keys only for maps");
        }
示例#6
0
        public void SubtractAssign_FromDictionary(int remainingKeysCount, params string[] keysToRemove)
        {
            var tupleDictionaryType = EntityWithDictionaryType.GetDefaultTable(Session, _tableName);
            var table = tupleDictionaryType.Item1;

            var newdict = new Dictionary <string, string>
            {
                { "firstKey", "firstvalue" },
                { "secondKey", "secondvalue" },
                { "lastkey", "lastvalue" },
            };
            var id        = Guid.NewGuid().ToString();
            var newEntity = new EntityWithDictionaryType
            {
                Id             = id,
                DictionaryType = newdict
            };

            table.Where(t => t.Id == newEntity.Id).Select(x => new EntityWithDictionaryType
            {
                DictionaryType = x.DictionaryType.SubstractAssign(keysToRemove)
            }).Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET DictionaryType = DictionaryType - ? WHERE Id = ?",
                1,
                keysToRemove, newEntity.Id);
        }
示例#7
0
        public void Append_ToDictionary_DuplicateAndNonDuplicateKey()
        {
            var(table, expectedEntities) = EntityWithDictionaryType.GetDefaultTable(Session, _tableName);

            var singleEntity = expectedEntities.First();
            var 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 }
            };
            var 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();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET DictionaryType = DictionaryType + ? WHERE Id = ?",
                1,
                dictToAdd, singleEntity.Id);
        }
示例#8
0
        public void Append_ToDictionary_EmptyDictionary()
        {
            var(table, expectedEntities) = EntityWithDictionaryType.GetDefaultTable(Session, _tableName);

            var dictToAdd = new Dictionary <string, string>()
            {
            };
            var singleEntity   = expectedEntities.First();
            var 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();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET DictionaryType = DictionaryType + ? WHERE Id = ?",
                1,
                dictToAdd, singleEntity.Id);
        }
示例#9
0
        public void Prepend_Dictionary()
        {
            var(table, expectedEntities) = EntityWithDictionaryType.GetDefaultTable(Session, _tableName);

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

            var singleEntity   = expectedEntities.First();
            var 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
            var expectedErrMsg = "Invalid operation (dictionarytype = ? - dictionarytype) for non list column dictionarytype";

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"UPDATE {_tableName} SET DictionaryType = ? + DictionaryType WHERE Id = ?",
                    when => when.WithParams(dictToAdd, singleEntity.Id))
                .ThenServerError(ServerError.Invalid, expectedErrMsg));
            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);
        }
示例#10
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]);
        }
示例#11
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());
        }