public void DeleteCacheEntryRemovesTheGivenBeacon() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(42, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyTwo, 1000L, "z"); target.AddEventData(keyOne, 1000L, "iii"); // when removing beacon with id 1 target.DeleteCacheEntry(keyOne); // then Assert.That(target.BeaconKeys, Is.EqualTo(new HashSet <BeaconKey> { keyTwo })); // and when removing beacon with id 42 target.DeleteCacheEntry(keyTwo); // then Assert.That(target.BeaconKeys, Is.Empty); }
public void DeleteCacheEntriesDoesNothingIfGivenBeaconIDIsNotInCache() { // given var target = new BeaconCache(); target.AddActionData(1, 1000L, "a"); target.AddActionData(42, 1000L, "z"); target.AddEventData(1, 1000L, "iii"); var notifyCount = 0; target.RecordAdded += (s, a) => { notifyCount += 1; }; var cachedSize = target.NumBytesInCache; // when target.DeleteCacheEntry(666); // then Assert.That(target.BeaconIDs, Is.EqualTo(new HashSet <int> { 1, 42 })); Assert.That(target.NumBytesInCache, Is.EqualTo(cachedSize)); Assert.That(notifyCount, Is.EqualTo(0)); }
public void DeleteCacheEntriesDoesNothingIfGivenBeaconIdIsNotInCache() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(42, 0); var keyThree = new BeaconKey(666, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyTwo, 1000L, "z"); target.AddEventData(keyOne, 1000L, "iii"); var notifyCount = 0; target.RecordAdded += (s, a) => { notifyCount += 1; }; var cachedSize = target.NumBytesInCache; // when target.DeleteCacheEntry(keyThree); // then Assert.That(target.BeaconKeys, Is.EqualTo(new HashSet <BeaconKey> { keyOne, keyTwo })); Assert.That(target.NumBytesInCache, Is.EqualTo(cachedSize)); Assert.That(notifyCount, Is.EqualTo(0)); }
public void DeleteCacheEntryDoesNotRaiseEvent() { // given var target = new BeaconCache(); target.AddActionData(1, 1000L, "a"); target.AddActionData(42, 1000L, "z"); target.AddEventData(1, 1000L, "iii"); var notifyCount = 0; target.RecordAdded += (s, a) => { notifyCount += 1; }; // when deleting both entries target.DeleteCacheEntry(1); target.DeleteCacheEntry(42); // then Assert.That(notifyCount, Is.EqualTo(0)); }
public void DeleteCacheEntryRemovesTheGivenBeacon() { // given var target = new BeaconCache(); target.AddActionData(1, 1000L, "a"); target.AddActionData(42, 1000L, "z"); target.AddEventData(1, 1000L, "iii"); // when removing beacon with id 1 target.DeleteCacheEntry(1); // then Assert.That(target.BeaconIDs, Is.EqualTo(new HashSet <int> { 42 })); // and when removing beacon with id 42 target.DeleteCacheEntry(42); // then Assert.That(target.BeaconIDs, Is.Empty); }
public void DeleteCacheEntryDecrementsCacheSize() { // given var target = new BeaconCache(); target.AddActionData(1, 1000L, "a"); target.AddActionData(42, 1000L, "z"); target.AddEventData(1, 1000L, "iii"); // when deleting entry with beacon id 42 target.DeleteCacheEntry(42); // then Assert.That(target.NumBytesInCache, Is.EqualTo(new BeaconCacheRecord(1000L, "a").DataSizeInBytes + new BeaconCacheRecord(1000L, "iii").DataSizeInBytes)); }