public void TestAddKey() { Assert.IsFalse(_target.IsDirty, "Dirty flag set prematurely"); Assert.AreEqual(0, _target.NextKey, "Next key is incorrect."); _target.AddKeyAsync(_models[0].Key).Wait(); Assert.IsTrue(_target.IsDirty, "Dirty flag not set on add."); Assert.AreEqual(1, _target.NextKey, "Next key not advanced."); }
public void TestAddDuplicateKey() { Assert.False(_target.IsDirty); //Dirty flag set prematurely"); Assert.Equal(0, _target.NextKey); //Next key is incorrect initialized."); _target.AddKeyAsync(_models[0].Key).Wait(); Assert.True(_target.IsDirty); //Dirty flag not set on add."); Assert.Equal(1, _target.NextKey); //Next key not advanced."); _target.AddKeyAsync(_models[0].Key).Wait(); Assert.Equal(1, _target.NextKey); //Next key advanced on duplicate add."); Assert.Single(_target.Query); //Key list count is incorrect."); }
public void TestSerialization() { _target.AddKeyAsync(_models[0].Key).Wait(); _target.AddKeyAsync(_models[1].Key).Wait(); Assert.IsTrue(_target.IsDirty, "Dirty flag not set."); _target.FlushAsync().Wait(); Assert.IsFalse(_target.IsDirty, "Dirty flag not reset on flush."); var secondTarget = new KeyCollection <TestModel, int>(_driver, _GetTestModelByKey); // are we able to grab things? Assert.AreEqual(2, secondTarget.Query.Count(), "Key count is incorrect."); Assert.AreEqual(0, _testAccessCount, "Lazy loader was accessed prematurely."); var testKey = (from k in secondTarget.Query where k.Key.Equals(_models[1].Key) select k).FirstOrDefault(); Assert.IsNotNull(testKey, "Test key not retrieved."); Assert.AreEqual(_models[1].Key, testKey.Key, "Key mismatch."); Assert.AreEqual(0, _testAccessCount, "Lazy loader was accessed prematurely."); var testModel = testKey.LazyValue.Value; Assert.AreSame(_models[1], testModel, "Model does not match."); Assert.AreEqual(1, _testAccessCount, "Lazy loader access count is incorrect."); // now let's test refresh secondTarget.AddKeyAsync(_models[2].Key).Wait(); secondTarget.FlushAsync().Wait(); Assert.AreEqual(2, _target.Query.Count(), "Unexpected key count in original collection."); _target.RefreshAsync().Wait(); Assert.AreEqual(3, _target.Query.Count(), "Refresh failed."); }
public void TestSerialization() { _target.AddKeyAsync(_models[0].Key).Wait(); _target.AddKeyAsync(_models[1].Key).Wait(); Assert.IsTrue(_target.IsDirty, "Dirty flag not set."); _target.FlushAsync().Wait(); Assert.IsFalse(_target.IsDirty, "Dirty flag not reset on flush."); var secondTarget = new KeyCollection<TestModel, int>(_driver, _GetTestModelByKey); // are we able to grab things? Assert.AreEqual(2, secondTarget.Query.Count(), "Key count is incorrect."); Assert.AreEqual(0, _testAccessCount, "Lazy loader was accessed prematurely."); var testKey = (from k in secondTarget.Query where k.Key.Equals(_models[1].Key) select k).FirstOrDefault(); Assert.IsNotNull(testKey, "Test key not retrieved."); Assert.AreEqual(_models[1].Key, testKey.Key, "Key mismatch."); Assert.AreEqual(0, _testAccessCount, "Lazy loader was accessed prematurely."); var testModel = testKey.LazyValue.Value; Assert.AreSame(_models[1], testModel, "Model does not match."); Assert.AreEqual(1, _testAccessCount, "Lazy loader access count is incorrect."); // now let's test refresh secondTarget.AddKeyAsync(_models[2].Key).Wait(); secondTarget.FlushAsync().Wait(); Assert.AreEqual(2, _target.Query.Count(), "Unexpected key count in original collection."); _target.RefreshAsync().Wait(); Assert.AreEqual(3, _target.Query.Count(), "Refresh failed."); }