public void Append_ToArray_AppendEmptyArray_QueryUsingCql() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleArrayType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleArrayType.Item1; List <EntityWithArrayType> expectedEntities = tupleArrayType.Item2; string[] arrToAdd = new string[] { }; EntityWithArrayType singleEntity = expectedEntities.First(); EntityWithArrayType expectedEntity = singleEntity.Clone(); List <string> strValsAsList = new List <string>(); strValsAsList.AddRange(expectedEntity.ArrayType); strValsAsList.AddRange(arrToAdd); expectedEntity.ArrayType = strValsAsList.ToArray(); // Append the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.Append(arrToAdd) }).Update().Execute(); // Validate the final state of the data List <Row> rows = _session.Execute("SELECT * from " + table.Name + " where id='" + expectedEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); string[] actualArr = rows[0].GetValue <string[]>("arraytype"); Assert.AreEqual(expectedEntity.ArrayType, actualArr); }
public void Append_ToArray() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleArrayType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleArrayType.Item1; List <EntityWithArrayType> expectedEntities = tupleArrayType.Item2; string[] arrToAdd = new string[] { "random_" + Randomm.RandomAlphaNum(10), "random_" + Randomm.RandomAlphaNum(10), "random_" + Randomm.RandomAlphaNum(10), }; EntityWithArrayType singleEntity = expectedEntities.First(); EntityWithArrayType expectedEntity = singleEntity.Clone(); List <string> strValsAsList = new List <string>(); strValsAsList.AddRange(expectedEntity.ArrayType); strValsAsList.AddRange(arrToAdd); expectedEntity.ArrayType = strValsAsList.ToArray(); // Append the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.Append(arrToAdd) }).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.ArrayType, singleEntity.ArrayType); expectedEntity.AssertEquals(entityList[0]); }
public void Prepend_ToArray_QueryUsingCql() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleArrayType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleArrayType.Item1; List <EntityWithArrayType> expectedEntities = tupleArrayType.Item2; string[] arrToAdd = new string[] { "random_" + Randomm.RandomAlphaNum(10), "random_" + Randomm.RandomAlphaNum(10), "random_" + Randomm.RandomAlphaNum(10), }; List <string> listReversed = arrToAdd.ToList(); listReversed.Reverse(); string[] arrReversed = listReversed.ToArray(); EntityWithArrayType singleEntity = expectedEntities.First(); EntityWithArrayType expectedEntity = singleEntity.Clone(); List <string> strValsAsList = new List <string>(); strValsAsList.AddRange(expectedEntity.ArrayType); strValsAsList.InsertRange(0, arrReversed); expectedEntity.ArrayType = strValsAsList.ToArray(); // Append the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.Prepend(arrToAdd) }).Update().Execute(); // Validate the final state of the data List <Row> rows = _session.Execute("SELECT * from " + table.Name + " where id='" + expectedEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreNotEqual(expectedEntity.ArrayType, singleEntity.ArrayType); string[] actualArr = rows[0].GetValue <string[]>("arraytype"); CollectionAssert.AreEquivalent(expectedEntity.ArrayType, actualArr); }
public void SubtractAssign_FromArray_AllValues_QueryUsingCql() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleListType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleListType.Item1; List <EntityWithArrayType> expectedEntities = tupleListType.Item2; EntityWithArrayType singleEntity = expectedEntities.First(); EntityWithArrayType expectedEntity = singleEntity.Clone(); expectedEntity.ArrayType = new string[] {}; // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.SubstractAssign(singleEntity.ArrayType) }).Update().Execute(); // Validate final state of the data List <Row> rows = _session.Execute("SELECT * from " + table.Name + " where id='" + expectedEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreNotEqual(expectedEntity.ArrayType, singleEntity.ArrayType); object actualArr = rows[0].GetValue <object>("arraytype"); Assert.AreEqual(null, actualArr); }
public void SubtractAssign_FromArray_Duplicates() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleArrayType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleArrayType.Item1; List <EntityWithArrayType> expectedEntities = tupleArrayType.Item2; EntityWithArrayType singleEntity = expectedEntities.First(); Assert.AreEqual(1, singleEntity.ArrayType.Length); // make sure there's only one value in the list int indexToRemove = 0; singleEntity.ArrayType.ToList().AddRange(new[] { singleEntity.ArrayType[indexToRemove], singleEntity.ArrayType[indexToRemove], singleEntity.ArrayType[indexToRemove] }); // Overwrite one of the rows, validate the data got there table.Insert(singleEntity).Execute(); List <Row> rows = _session.Execute("SELECT * from " + table.Name + " where id='" + singleEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); string[] actualArr = rows[0].GetValue <string[]>("arraytype"); Assert.AreEqual(singleEntity.ArrayType, actualArr); // Get single value to remove string[] valsToDelete = new string[] { singleEntity.ArrayType[indexToRemove] }; EntityWithArrayType expectedEntity = singleEntity.Clone(); expectedEntity.ArrayType = new string[] {}; // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute(); // Validate final state of the data rows = _session.Execute("SELECT * from " + table.Name + " where id='" + expectedEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); object probablyNullArr = rows[0].GetValue <object>("arraytype"); Assert.AreEqual(null, probablyNullArr); }
public void SubtractAssign_FromArray_OneValueOfMany_IndexNonZero() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleArrayType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleArrayType.Item1; List <EntityWithArrayType> expectedEntities = tupleArrayType.Item2; EntityWithArrayType singleEntity = expectedEntities.First(); List <string> tempList = singleEntity.ArrayType.ToList(); tempList.AddRange(new[] { "999", "9999", "99999", "999999" }); singleEntity.ArrayType = tempList.ToArray(); // Overwrite one of the rows table.Insert(singleEntity).Execute(); // Get Value to remove int indexToRemove = 2; string[] valsToDelete = { singleEntity.ArrayType[indexToRemove] }; EntityWithArrayType expectedEntity = singleEntity.Clone(); tempList = expectedEntity.ArrayType.ToList(); tempList.RemoveAt(indexToRemove); expectedEntity.ArrayType = tempList.ToArray(); // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id).Select(t => new EntityWithArrayType { ArrayType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute(); // Validate final state of the data List <Row> rows = _session.Execute("SELECT * from " + table.Name + " where id='" + expectedEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); Assert.AreNotEqual(expectedEntity.ArrayType, singleEntity.ArrayType); Assert.AreEqual(expectedEntity.ArrayType, rows[0].GetValue <string[]>("arraytype")); }