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_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.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); string[] actualArr = rows[0].GetValue <string[]>("arraytype"); Assert.AreEqual(expectedEntity.ArrayType, actualArr); }
public void Prepend_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(); // 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 var entityList = table.Where(m => m.Id == singleEntity.Id).ExecuteAsync().Result.ToList(); Assert.AreEqual(1, entityList.Count); CollectionAssert.AreEqual(arrToAdd.Concat(singleEntity.ArrayType).OrderBy(v => v), entityList[0].ArrayType.OrderBy(v => v)); }
public void SubtractAssign_FromArray_EmptyArray() { Tuple <Table <EntityWithArrayType>, List <EntityWithArrayType> > tupleArrayType = EntityWithArrayType.SetupDefaultTable(_session); Table <EntityWithArrayType> table = tupleArrayType.Item1; List <EntityWithArrayType> expectedEntities = tupleArrayType.Item2; EntityWithArrayType singleEntity = expectedEntities.First(); string[] valsToDelete = { }; // 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='" + singleEntity.Id + "'").GetRows().ToList(); Assert.AreEqual(1, rows.Count); object actualArr = rows[0].GetValue <object>("arraytype"); Assert.AreEqual(singleEntity.ArrayType, actualArr); }
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")); }
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); }