Exemplo n.º 1
0
        public void should_allocate_and_remove_next_available_id()
        {
            var idPool = new IdPool(10, 10);
            var id     = idPool.AllocateInstance();

            Assert.InRange(id, 1, 10);
            Assert.DoesNotContain(id, idPool.AvailableIds);
        }
Exemplo n.º 2
0
        public int GetId(int?id = null)
        {
            if (false == id.HasValue)
            {
                return(IdPool.AllocateInstance());
            }

            IdPool.AllocateSpecificId(id.Value);

            return(id.Value);
        }
Exemplo n.º 3
0
        public void should_correctly_keep_expanding_when_continually_allocating()
        {
            var expectedSize        = 5000;
            var idPool              = new IdPool();
            var expectedAllocations = Enumerable.Range(1, expectedSize).ToList();
            var actualAllocations   = new List <int>();

            for (var i = 0; i < expectedSize; i++)
            {
                var allocation = idPool.AllocateInstance();
                actualAllocations.Add(allocation);
            }

            Assert.Equal(expectedSize, actualAllocations.Count);
            Assert.All(actualAllocations, x => expectedAllocations.Contains(x));
        }
Exemplo n.º 4
0
        public void should_expand_and_allocate_and_remove_next_available_id_when_empty()
        {
            var defaultExpansionAmount = 30;
            var originalSize           = 10;
            var expectedSize           = defaultExpansionAmount + originalSize;
            var idPool = new IdPool(defaultExpansionAmount, originalSize);

            idPool.AvailableIds.Clear();
            var id = idPool.AllocateInstance();

            var expectedIdEntries = Enumerable.Range(1, expectedSize - 1).ToList();

            Assert.InRange(id, 1, expectedSize);
            Assert.DoesNotContain(id, idPool.AvailableIds);
            Assert.All(idPool.AvailableIds, x => expectedIdEntries.Contains(x));
        }