コード例 #1
0
        public void RemoveOldestRecordsComparesTopActionAndEventDataAndRemovesOldest()
        {
            // given
            var dataOne   = new BeaconCacheRecord(1000, "One");
            var dataTwo   = new BeaconCacheRecord(1100L, "Two");
            var dataThree = new BeaconCacheRecord(950L, "Three");
            var dataFour  = new BeaconCacheRecord(1200L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);
            target.AddEventData(dataFour);

            // when
            var obtained = target.RemoveOldestRecords(1);

            // then
            Assert.That(obtained, Is.EqualTo(1));
            Assert.That(target.ActionData, Is.EqualTo(new[] { dataTwo, dataThree }));
            Assert.That(target.EventData, Is.EqualTo(new[] { dataFour }));

            // when removing the next two
            obtained = target.RemoveOldestRecords(2);

            // then
            Assert.That(obtained, Is.EqualTo(2));
            Assert.That(target.ActionData, Is.Empty);
            Assert.That(target.EventData, Is.EqualTo(new[] { dataFour }));
        }
コード例 #2
0
        public void RemoveOldestRecordsDoesNotRemoveAnythingFromEventAndActionsBeingSent()
        {
            // given
            var dataOne   = new BeaconCacheRecord(1000L, "One");
            var dataTwo   = new BeaconCacheRecord(1500L, "Two");
            var dataThree = new BeaconCacheRecord(2000L, "Three");
            var dataFour  = new BeaconCacheRecord(2500L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataFour);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);

            target.CopyDataForSending();

            // when
            var obtained = target.RemoveOldestRecords(10000);

            // then
            Assert.That(obtained, Is.EqualTo(0));
            Assert.That(target.EventDataBeingSent, Is.EqualTo(new[] { dataOne, dataFour }));
            Assert.That(target.ActionDataBeingSent, Is.EqualTo(new[] { dataTwo, dataThree }));
        }
コード例 #3
0
        public void RemoveOldestRecordsRemovesNothingIfEntryIsEmpty()
        {
            // given
            var target = new BeaconCacheEntry();

            // when
            var obtained = target.RemoveOldestRecords(1);

            // then
            Assert.That(obtained, Is.EqualTo(0));
        }
コード例 #4
0
        public void RemoveOldestRecordsRemovesEventDataIfActionDataIsEmpty()
        {
            // given
            var dataOne   = new BeaconCacheRecord(4000L, "One");
            var dataTwo   = new BeaconCacheRecord(3000L, "Two");
            var dataThree = new BeaconCacheRecord(2000L, "Three");
            var dataFour  = new BeaconCacheRecord(1000L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataTwo);
            target.AddEventData(dataThree);
            target.AddEventData(dataFour);

            // when
            var obtained = target.RemoveOldestRecords(2);

            // then
            Assert.That(obtained, Is.EqualTo(2)); // two were removed
            Assert.That(target.EventData, Is.EqualTo(new[] { dataThree, dataFour }));
        }
コード例 #5
0
        public void RemoveOldestRecordsStopsIfListsAreEmpty()
        {
            // given
            var dataOne   = new BeaconCacheRecord(4000L, "One");
            var dataTwo   = new BeaconCacheRecord(3000L, "Two");
            var dataThree = new BeaconCacheRecord(2000L, "Three");
            var dataFour  = new BeaconCacheRecord(1000L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataTwo);
            target.AddEventData(dataThree);
            target.AddEventData(dataFour);

            // when
            var obtained = target.RemoveOldestRecords(100);

            // then
            Assert.That(obtained, Is.EqualTo(4));
            Assert.That(target.EventData, Is.Empty);
            Assert.That(target.ActionData, Is.Empty);
        }
コード例 #6
0
        public void RemoveOldestRecordsRemovesEventDataIfTopEventDataAndActionDataHaveSameTimestamp()
        {
            // given
            var dataOne   = new BeaconCacheRecord(1000, "One");
            var dataTwo   = new BeaconCacheRecord(1100L, "Two");
            var dataThree = new BeaconCacheRecord(dataOne.Timestamp, "Three");
            var dataFour  = new BeaconCacheRecord(dataTwo.Timestamp, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataTwo);
            target.AddActionData(dataThree);
            target.AddActionData(dataFour);

            // when
            var obtained = target.RemoveOldestRecords(1);

            // then
            Assert.That(obtained, Is.EqualTo(1));
            Assert.That(target.ActionData, Is.EqualTo(new[] { dataThree, dataFour }));
            Assert.That(target.EventData, Is.EqualTo(new[] { dataTwo }));
        }