public void should_allocate_in_bulk_when_needing_more_instances() { var mockViewHandler = Substitute.For <IViewHandler>(); var pool = new ViewPool(5, mockViewHandler); pool.AllocateInstance(); mockViewHandler.Received(5).CreateView(); Assert.Equal(5, pool.PooledObjects.Count); Assert.Equal(4, pool.PooledObjects.Count(x => x.IsInUse == false)); Assert.Equal(1, pool.PooledObjects.Count(x => x.IsInUse)); }
public void should_not_allocate_in_bulk_when_views_not_in_use() { var mockViewHandler = Substitute.For <IViewHandler>(); var pool = new ViewPool(5, mockViewHandler); var viewObject = new ViewObjectContainer(null); pool.PooledObjects.Add(viewObject); pool.AllocateInstance(); mockViewHandler.Received(0).CreateView(); mockViewHandler.Received(1).SetActiveState(Arg.Any <object>(), true); Assert.Equal(1, pool.PooledObjects.Count); Assert.Equal(1, pool.PooledObjects.Count(x => x.IsInUse)); }