public void SubtractAssign_FromList_OneValueOfMany_IndexZero() { var(table, expectedEntities) = EntityWithListType.GetDefaultTable(Session, _tableName); var singleEntity = expectedEntities.First(); singleEntity.ListType.AddRange(new[] { 999, 9999, 99999, 999999 }); // Get value to remove var indexToRemove = 0; var valsToDelete = new List <int>() { singleEntity.ListType[indexToRemove] }; var expectedEntity = singleEntity.Clone(); expectedEntity.ListType.RemoveAt(indexToRemove); // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ListType - ? WHERE Id = ?", 1, valsToDelete, singleEntity.Id); }
public void Prepend_ToList_StartsOutEmpty() { var(table, expectedEntities) = EntityWithListType.GetDefaultTable(Session, _tableName); // overwrite the row we're querying with empty list var singleEntity = expectedEntities.First(); singleEntity.ListType.Clear(); table.Insert(singleEntity).Execute(); var listToAdd = new List <int> { -1, 0, 5, 6 }; var listReversed = new List <int>(listToAdd); listReversed.Reverse(); var expectedEntity = singleEntity.Clone(); expectedEntity.ListType.InsertRange(0, listReversed); // Append the values table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.Prepend(listToAdd) }) .Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ? + ListType WHERE Id = ?", 1, listToAdd, singleEntity.Id); }
public void SubtractAssign_FromList_Duplicates() { var(table, expectedEntities) = EntityWithListType.GetDefaultTable(Session, _tableName); var singleEntity = expectedEntities.First(); Assert.AreEqual(1, singleEntity.ListType.Count); // make sure there's only one value in the list var indexToRemove = 0; singleEntity.ListType.AddRange(new[] { singleEntity.ListType[indexToRemove], singleEntity.ListType[indexToRemove], singleEntity.ListType[indexToRemove] }); // Get single value to remove var valsToDelete = new List <int>() { singleEntity.ListType[indexToRemove] }; // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ListType - ? WHERE Id = ?", 1, valsToDelete, singleEntity.Id); }
public void SubtractAssign_FromList_ValNotInList() { var tupleListType = EntityWithListType.GetDefaultTable(Session, _tableName); var table = tupleListType.Item1; var expectedEntities = tupleListType.Item2; var singleEntity = expectedEntities.First(); var valsToDelete = new List <int>() { 9999 }; // make sure this value is not in the list Assert.IsFalse(singleEntity.ListType.Contains(valsToDelete.First())); // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ListType - ? WHERE Id = ?", 1, valsToDelete, singleEntity.Id); }
public void Prepend_ToList_PrependEmptyList() { var(table, expectedEntities) = EntityWithListType.GetDefaultTable(Session, _tableName); var listToAdd = new List <int>(); var singleEntity = expectedEntities.First(); table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.Prepend(listToAdd) }) .Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ? + ListType WHERE Id = ?", 1, listToAdd, singleEntity.Id); }
public void SubtractAssign_FromList_EmptyList() { var(table, expectedEntities) = EntityWithListType.GetDefaultTable(Session, _tableName); var singleEntity = expectedEntities.First(); var valsToDelete = new List <int>(); // SubstractAssign the values table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.SubstractAssign(valsToDelete) }).Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ListType - ? WHERE Id = ?", 1, valsToDelete, singleEntity.Id); }
public void Append_ToList() { var(table, expectedEntities) = EntityWithListType.GetDefaultTable(Session, _tableName); var listToAdd = new List <int> { -1, 0, 5, 6 }; var singleEntity = expectedEntities.First(); var expectedEntity = singleEntity.Clone(); expectedEntity.ListType.AddRange(listToAdd); // Append the values table.Where(t => t.Id == singleEntity.Id) .Select(t => new EntityWithListType { ListType = CqlOperator.Append(listToAdd) }) .Update().Execute(); VerifyBoundStatement( $"UPDATE {_tableName} SET ListType = ListType + ? WHERE Id = ?", 1, listToAdd, singleEntity.Id); }