Esempio n. 1
0
        public void Append_ToArray_TableWithAllCollectionTypes()
        {
            var(table, expectedEntities) = EntityWithAllCollectionTypes.GetDefaultTable(Session, _tableName);

            var singleEntity = expectedEntities.First();
            var toAppend     = new string[] { "tag1", "tag2", "tag3" };

            table.Where(t => t.Id == singleEntity.Id)
            .Select(t => new EntityWithAllCollectionTypes {
                ArrayType = CqlOperator.Append(toAppend)
            })
            .Update().Execute();

            VerifyBoundStatement(
                $"UPDATE {_tableName} SET ArrayType = ArrayType + ? WHERE Id = ?",
                1,
                toAppend, singleEntity.Id);

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    $"SELECT ArrayType, DictionaryType, Id, ListType FROM {_tableName} WHERE Id = ?",
                    when => when.WithParam(singleEntity.Id))
                .ThenRowsSuccess(
                    new[] { "ArrayType", "DictionaryType", "Id", "ListType" },
                    r => r.WithRow(
                        singleEntity.ArrayType.Concat(toAppend),
                        singleEntity.DictionaryType,
                        singleEntity.Id,
                        singleEntity.ListType)));

            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            CollectionAssert.AreEqual(singleEntity.ArrayType.Concat(toAppend), entityList.First().ArrayType);
        }
Esempio n. 2
0
        public void Append_ToArray_TableWithAllCollectionTypes()
        {
            Tuple <Table <EntityWithAllCollectionTypes>, List <EntityWithAllCollectionTypes> > tupleAllCollectionTypes = EntityWithAllCollectionTypes.SetupDefaultTable(_session);
            Table <EntityWithAllCollectionTypes> table            = tupleAllCollectionTypes.Item1;
            List <EntityWithAllCollectionTypes>  expectedEntities = tupleAllCollectionTypes.Item2;

            EntityWithAllCollectionTypes singleEntity = expectedEntities.First();
            var toAppend = new string[] { "tag1", "tag2", "tag3" };

            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithAllCollectionTypes {
                ArrayType = CqlOperator.Append(toAppend)
            }).Update().Execute();
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            CollectionAssert.AreEqual(singleEntity.ArrayType.Concat(toAppend), entityList.First().ArrayType);
        }
Esempio n. 3
0
        public void Append_ToDictionary_TableWithAllCollectionTypes()
        {
            Tuple <Table <EntityWithAllCollectionTypes>, List <EntityWithAllCollectionTypes> > tupleAllCollectionTypes = EntityWithAllCollectionTypes.SetupDefaultTable(_session);
            Table <EntityWithAllCollectionTypes> table            = tupleAllCollectionTypes.Item1;
            List <EntityWithAllCollectionTypes>  expectedEntities = tupleAllCollectionTypes.Item2;

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

            expectedEntity.DictionaryType.Add("key1", "val1");
            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithAllCollectionTypes {
                DictionaryType = CqlOperator.Append(expectedEntity.DictionaryType)
            }).Update().Execute();
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            CollectionAssert.AreEqual(expectedEntity.ArrayType, singleEntity.ArrayType);
            entityList.First().AssertEquals(expectedEntity);
        }
Esempio n. 4
0
        public void Append_ToList_TableWithAllCollectionTypes()
        {
            Tuple <Table <EntityWithAllCollectionTypes>, List <EntityWithAllCollectionTypes> > tupleAllCollectionTypes = EntityWithAllCollectionTypes.SetupDefaultTable(_session);
            Table <EntityWithAllCollectionTypes> table            = tupleAllCollectionTypes.Item1;
            List <EntityWithAllCollectionTypes>  expectedEntities = tupleAllCollectionTypes.Item2;

            var originalEntityListInCass = table.Select(m => m).ExecuteAsync().Result.ToList();

            Console.WriteLine(originalEntityListInCass.Count);

            EntityWithAllCollectionTypes singleEntity = expectedEntities.First();
            var toAppend = new List <int> {
                5, 6
            };

            table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithAllCollectionTypes {
                ListType = CqlOperator.Append(toAppend)
            }).Update().Execute();
            var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList();

            Assert.AreEqual(1, entityList.Count);
            CollectionAssert.AreEqual(singleEntity.ListType.Concat(toAppend), entityList.First().ListType);
        }