public void QueuePush_Returns_Success_When_Adding_Item_To_New_Queue_With_CreateQueue_True() { Setup(true); const string key = "QueuePush_Returns_Success_When_Adding_Item_To_New_Queue_With_CreateQueue_True"; _bucket.Remove(key); var bob = new Poco1 { Name = "Bob", Items = new List <string> { "Red", "Orange" } }; var result = _bucket.QueuePush(key, bob, true); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var queue = _bucket.Get <List <Poco1> >(key); Assert.IsNotNull(queue.Value); Assert.AreEqual(1, queue.Value.Count); var item = queue.Value.First(); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); }
public async Task QueuePushAsync_Returns_Success_When_Adding_Item_To_Existing_Queue() { Setup(true); const string key = "QueuePushAsync_Returns_Success_When_Adding_Item_To_Existing_Queue"; await _bucket.UpsertAsync(key, new List <Poco1>()); var bob = new Poco1 { Name = "Bob", Items = new List <string> { "Red", "Orange" } }; var result = await _bucket.QueuePushAsync(key, bob, true); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var queue = await _bucket.GetAsync <List <Poco1> >(key); Assert.IsNotNull(queue.Value); Assert.AreEqual(1, queue.Value.Count); var item = queue.Value.First(); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); }
public void Test_Integer_Encryption_RoundTrip() { var settings = GetSettings(); var pocoPlain = new Poco1 { Foo = 2 }; var json = JsonConvert.SerializeObject(pocoPlain, settings); Assert.Contains("__encrypt", json);; var poco = JsonConvert.DeserializeObject <Poco1>(json, settings); Assert.Equal(2, poco.Foo); }
public async Task QueuePopAsync_Returns_Item_From_Front_Of_Queue() { Setup(true); const string key = "QueuePopAsync_Returns_Item_From_Front_Of_Queue"; var bob = new Poco1 { Name = "Bob", Items = new List <string> { "Red", "Orange" } }; var mary = new Poco1 { Name = "Mary", Items = new List <string> { "Pink", "Purple" } }; await _bucket.UpsertAsync(key, new List <Poco1> { bob, mary }); // Ensure there are two items var queue = await _bucket.GetAsync <List <Poco1> >(key); Assert.IsNotNull(queue); Assert.AreEqual(2, queue.Value.Count); var result = await _bucket.QueuePopAsync <Poco1>(key); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var item = result.Value; Assert.IsNotNull(item); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); // Now there should be two items queue = await _bucket.GetAsync <List <Poco1> >(key); Assert.IsNotNull(queue); Assert.AreEqual(1, queue.Value.Count); }
public async Task QueuePushAsync_Returns_Failure_When_Adding_Item_To_New_Queue_With_CreateQueue_False() { const string key = "QueuePushAsync_Returns_Failure_When_Adding_Item_To_New_Queue_With_CreateQueue_False"; await _bucket.RemoveAsync(key); var bob = new Poco1 { Name = "Bob", Items = new List <string> { "Red", "Orange" } }; var result = await _bucket.QueuePushAsync(key, bob, false); Assert.IsNotNull(result); Assert.IsFalse(result.Success); var queue = await _bucket.GetAsync <List <Poco1> >(key); Assert.IsFalse(queue.Success); Assert.IsNull(queue.Value); }
public void QueuePop_Returns_Item_From_Front_Of_Queue() { const string key = "QueuePop_Returns_Item_From_Front_Of_Queue"; var bob = new Poco1 { Name = "Bob", Items = new List <string> { "Red", "Orange" } }; var mary = new Poco1 { Name = "Mary", Items = new List <string> { "Pink", "Purple" } }; _bucket.Upsert(key, new List <Poco1> { bob, mary }); // Ensure there are two items var queue = _bucket.Get <List <Poco1> >(key).Value; Assert.IsNotNull(queue); Assert.AreEqual(2, queue.Count); var result = _bucket.QueuePop <Poco1>(key); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var item = result.Value; Assert.IsNotNull(item); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); // Now there should be one item queue = _bucket.Get <List <Poco1> >(key).Value; Assert.IsNotNull(queue); Assert.AreEqual(1, queue.Count); Assert.AreEqual(mary.Name, queue[0].Name); }
public void QueuePush_Returns_Failure_When_Adding_Item_To_New_Queue_With_CreateQueue_False() { Setup(true); const string key = "QueuePush_Returns_Failure_When_Adding_Item_To_New_Queue_With_CreateQueue_False"; _bucket.Remove(key); var bob = new Poco1 { Name = "Bob", Items = new List <string> { "Red", "Orange" } }; var result = _bucket.QueuePush(key, bob, false); Assert.IsNotNull(result); Assert.IsFalse(result.Success); var queue = _bucket.Get <List <Poco1> >(key); Assert.IsFalse(queue.Success); Assert.IsNull(queue.Value); }
public void QueuePop_Returns_Item_From_Front_Of_Queue() { Setup(true); const string key = "QueuePop_Returns_Item_From_Front_Of_Queue"; var bob = new Poco1 { Name = "Bob", Items = new List<string> { "Red", "Orange" } }; var mary = new Poco1 { Name = "Mary", Items = new List<string> { "Pink", "Purple" } }; _bucket.Upsert(key, new List<Poco1> { bob, mary }); // Ensure there are two items var queue = _bucket.Get<List<Poco1>>(key).Value; Assert.IsNotNull(queue); Assert.AreEqual(2, queue.Count); var result = _bucket.QueuePop<Poco1>(key); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var item = result.Value; Assert.IsNotNull(item); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); // Now there should be two items queue = _bucket.Get<List<Poco1>>(key).Value; Assert.IsNotNull(queue); Assert.AreEqual(1, queue.Count); }
public void QueuePush_Returns_Failure_When_Adding_Item_To_New_Queue_With_CreateQueue_False() { Setup(true); const string key = "QueuePush_Returns_Failure_When_Adding_Item_To_New_Queue_With_CreateQueue_False"; _bucket.Remove(key); var bob = new Poco1 { Name = "Bob", Items = new List<string> { "Red", "Orange" } }; var result = _bucket.QueuePush(key, bob, false); Assert.IsNotNull(result); Assert.IsFalse(result.Success); var queue = _bucket.Get<List<Poco1>>(key); Assert.IsFalse(queue.Success); Assert.IsNull(queue.Value); }
public void QueuePush_Returns_Success_When_Adding_Item_To_New_Queue_With_CreateQueue_True() { Setup(true); const string key = "QueuePush_Returns_Success_When_Adding_Item_To_New_Queue_With_CreateQueue_True"; _bucket.Remove(key); var bob = new Poco1 { Name = "Bob", Items = new List<string> { "Red", "Orange" } }; var result = _bucket.QueuePush(key, bob, true); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var queue = _bucket.Get<List<Poco1>>(key); Assert.IsNotNull(queue.Value); Assert.AreEqual(1, queue.Value.Count); var item = queue.Value.First(); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); }
public async Task QueuePushAsync_Returns_Success_When_Adding_Item_To_Existing_Queue() { Setup(true); const string key = "QueuePushAsync_Returns_Success_When_Adding_Item_To_Existing_Queue"; await _bucket.UpsertAsync(key, new List<Poco1>()); var bob = new Poco1 {Name = "Bob", Items = new List<string> {"Red", "Orange"}}; var result = await _bucket.QueuePushAsync(key, bob, true); Assert.IsNotNull(result); Assert.IsTrue(result.Success); var queue = await _bucket.GetAsync<List<Poco1>>(key); Assert.IsNotNull(queue.Value); Assert.AreEqual(1, queue.Value.Count); var item = queue.Value.First(); Assert.AreEqual(bob.Name, item.Name); CollectionAssert.AreEqual(bob.Items, item.Items); }
public void CqlClient_TwoInstancesBasedOnSameSession() { // Setup MappingConfiguration config1 = new MappingConfiguration(); config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco1), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco1))); var table1 = new Table <Poco1>(_session, config1); table1.Create(); string cqlSelectAll1 = "SELECT * from " + table1.Name; MappingConfiguration config2 = new MappingConfiguration(); config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco2), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco2))); var table2 = new Table <Poco2>(_session, config2); table2.Create(); string cqlSelectAll2 = "SELECT * from " + table2.Name; // Now re-instantiate the cqlClient, but with mapping rule that resolves the missing key issue var cqlClient1 = new Mapper(_session, new MappingConfiguration().Define(new Poco1Mapping())); var cqlClient2 = new Mapper(_session, new MappingConfiguration().Define(new Poco2Mapping())); // insert new record into two separate tables Poco1 poco1 = new Poco1(); poco1.SomeString1 += "1"; cqlClient1.Insert(poco1); Poco2 poco2 = new Poco2(); poco2.SomeString2 += "1"; cqlClient2.Insert(poco2); // Select Values from each table List <Poco1> poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); List <Poco2> poco2s = cqlClient2.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); // Try that again poco1s.Clear(); Assert.AreEqual(0, poco1s.Count); poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); poco2s.Clear(); Assert.AreEqual(0, poco2s.Count); poco2s = cqlClient1.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); }
public void CqlClient_TwoInstancesBasedOnSameSession() { // Setup MappingConfiguration config1 = new MappingConfiguration(); config1.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco1), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco1))); var table1 = new Table <Poco1>(Session, config1); string cqlSelectAll1 = "SELECT * from " + table1.Name; MappingConfiguration config2 = new MappingConfiguration(); config2.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Poco2), () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Poco2))); var table2 = new Table <Poco2>(Session, config2); string cqlSelectAll2 = "SELECT * from " + table2.Name; // Now re-instantiate the cqlClient, but with mapping rule that resolves the missing key issue var cqlClient1 = new Mapper(Session, new MappingConfiguration().Define(new Poco1Mapping())); var cqlClient2 = new Mapper(Session, new MappingConfiguration().Define(new Poco2Mapping())); // insert new record into two separate tables Poco1 poco1 = new Poco1(); poco1.SomeString1 += "1"; cqlClient1.Insert(poco1); VerifyBoundStatement( "INSERT INTO poco1 (SomeDouble1, somestring1) VALUES (?, ?)", 1, poco1.SomeDouble1, poco1.SomeString1); Poco2 poco2 = new Poco2(); poco2.SomeString2 += "1"; cqlClient2.Insert(poco2); VerifyBoundStatement( "INSERT INTO poco2 (SomeDouble2, somestring2) VALUES (?, ?)", 1, poco2.SomeDouble2, poco2.SomeString2); // Select Values from each table TestCluster.PrimeFluent( b => b.WhenQuery("SELECT * from poco1") .ThenRowsSuccess(new[] { "SomeDouble1", "somestring1" }, r => r.WithRow(poco1.SomeDouble1, poco1.SomeString1))); List <Poco1> poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); TestCluster.PrimeFluent( b => b.WhenQuery("SELECT * from poco2") .ThenRowsSuccess(new[] { "SomeDouble2", "somestring2" }, r => r.WithRow(poco2.SomeDouble2, poco2.SomeString2))); List <Poco2> poco2s = cqlClient2.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); // Try that again poco1s.Clear(); Assert.AreEqual(0, poco1s.Count); poco1s = cqlClient1.Fetch <Poco1>(cqlSelectAll1).ToList(); Assert.AreEqual(1, poco1s.Count); Assert.AreEqual(poco1.SomeString1, poco1s[0].SomeString1); Assert.AreEqual(poco1.SomeDouble1, poco1s[0].SomeDouble1); poco2s.Clear(); Assert.AreEqual(0, poco2s.Count); poco2s = cqlClient1.Fetch <Poco2>(cqlSelectAll2).ToList(); Assert.AreEqual(1, poco2s.Count); Assert.AreEqual(poco2.SomeString2, poco2s[0].SomeString2); Assert.AreEqual(poco2.SomeDouble2, poco2s[0].SomeDouble2); }