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]); }
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 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]); }