public void AddActionDataAddsBeaconIdToCache() { // given var target = new BeaconCache(logger); var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(2, 0); // when adding beacon with id 1 target.AddActionData(keyOne, 1000L, "a"); // then Assert.That(target.BeaconKeys, Is.EqualTo(new HashSet <BeaconKey> { keyOne })); Assert.That(target.GetActions(keyOne), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a") })); // and when adding beacon with id 2 target.AddActionData(keyTwo, 1100L, "b"); // then Assert.That(target.BeaconKeys, Is.EqualTo(new HashSet <BeaconKey> { keyOne, keyTwo })); Assert.That(target.GetActions(keyOne), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a") })); Assert.That(target.GetActions(keyTwo), Is.EqualTo(new [] { new BeaconCacheRecord(1100L, "b") })); }
public void ResetChunkedRestoresData() { // given var target = new BeaconCache(); target.AddActionData(1, 1000L, "a"); target.AddActionData(1, 1001L, "iii"); target.AddEventData(1, 1000L, "b"); target.AddEventData(1, 1001L, "jjj"); // do same step we'd do when we send the target.GetNextBeaconChunk(1, "prefix", 10, '&'); // data has been copied, but still add some new event & action data target.AddActionData(1, 6666L, "123"); target.AddEventData(1, 6666L, "987"); // and when resetting the previously copied data target.ResetChunkedData(1); // then Assert.That(target.GetActionsBeingSent(1), Is.Null); Assert.That(target.GetEventsBeingSent(1), Is.Null); Assert.That(target.GetActions(1), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1001L, "iii"), new BeaconCacheRecord(6666L, "123") })); Assert.That(target.GetEvents(1), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "b"), new BeaconCacheRecord(1001L, "jjj"), new BeaconCacheRecord(6666L, "987") })); }
public void GetNextBeaconChunkDoesNotCopyDataForSending() { // 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(keyOne, 1001L, "iii"); target.AddActionData(keyTwo, 2000L, "z"); target.AddEventData(keyOne, 1000L, "b"); target.AddEventData(keyOne, 1001L, "jjj"); // when var obtained = target.GetNextBeaconChunk(keyOne, "prefix", 0, '&'); // then Assert.That(obtained, Is.Empty); Assert.That(target.GetActions(keyOne), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1001L, "iii") })); Assert.That(target.GetEvents(keyOne), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "b"), new BeaconCacheRecord(1001L, "jjj") })); Assert.That(target.GetActionsBeingSent(keyOne), Is.Null); Assert.That(target.GetEventsBeingSent(keyOne), Is.Null); }
public void AddActionDataAddsDataToAlreadyExistingBeaconId() { // given var target = new BeaconCache(); // when adding beacon with id 1 target.AddActionData(1, 1000L, "a"); // then Assert.That(target.BeaconIDs, Is.EqualTo(new HashSet <int> { 1 })); Assert.That(target.GetActions(1), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a") })); // and when adding other data with beacon id 1 target.AddActionData(1, 1100L, "bc"); // then Assert.That(target.BeaconIDs, Is.EqualTo(new HashSet <int> { 1 })); Assert.That(target.GetActions(1), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1100L, "bc") })); }
public void AddActionDataAddsBeaconIdToCache() { // given var target = new BeaconCache(); // when adding beacon with id 1 target.AddActionData(1, 1000L, "a"); // then Assert.That(target.BeaconIDs, Is.EqualTo(new HashSet <int> { 1 })); Assert.That(target.GetActions(1), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a") })); // and when adding beacon with id 2 target.AddActionData(2, 1100L, "b"); // then Assert.That(target.BeaconIDs, Is.EqualTo(new HashSet <int> { 1, 2 })); Assert.That(target.GetActions(1), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a") })); Assert.That(target.GetActions(2), Is.EqualTo(new [] { new BeaconCacheRecord(1100L, "b") })); }
public void AddActionDataAddsDataToAlreadyExistingBeaconId() { // given var target = new BeaconCache(logger); var key = new BeaconKey(1, 0); // when adding beacon with id 1 target.AddActionData(key, 1000L, "a"); // then Assert.That(target.BeaconKeys, Is.EqualTo(new HashSet <BeaconKey> { key })); Assert.That(target.GetActions(key), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a") })); // and when adding other data with beacon id 1 target.AddActionData(key, 1100L, "bc"); // then Assert.That(target.BeaconKeys, Is.EqualTo(new HashSet <BeaconKey> { key })); Assert.That(target.GetActions(key), Is.EqualTo(new [] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1100L, "bc") })); }
public void GetNextBeaconChunkCopiesDataForSending() { // given var target = new BeaconCache(); target.AddActionData(1, 1000L, "a"); target.AddActionData(1, 1001L, "iii"); target.AddActionData(42, 2000L, "z"); target.AddEventData(1, 1000L, "b"); target.AddEventData(1, 1001L, "jjj"); // when var obtained = target.GetNextBeaconChunk(1, "prefix", 0, '&'); // then Assert.That(obtained, Is.EqualTo("prefix")); Assert.That(target.GetActions(1), Is.Empty); Assert.That(target.GetEvents(1), Is.Empty); Assert.That(target.GetActionsBeingSent(1), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1001L, "iii") })); Assert.That(target.GetEventsBeingSent(1), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "b"), new BeaconCacheRecord(1001L, "jjj") })); }