public void Constructor_FromEnumerable()
        {
            var lazy = new LazyCollection <int>(_Int32TestData);

            lazy.Should().NotBeNull();
            lazy.Count.Should().Be(5);
            lazy.IsReadOnly.Should().BeFalse();
        }
        public void Constructor_ThreadSafetyMode()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            var lazy = new LazyCollection <int>(LazyThreadSafetyMode.ExecutionAndPublication);

            lazy.Should().NotBeNull();
            lazy.Count.Should().Be(0);
            lazy.IsReadOnly.Should().BeFalse();
        }
        public void Constructor_FromFactory()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            var lazy = new LazyCollection <int>(() => _Int32TestData.ToList());

            lazy.Should().NotBeNull();
            lazy.Count.Should().Be(5);
            lazy.IsReadOnly.Should().BeFalse();
        }
        public void Constructor()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            var lazy = new LazyCollection <int>();

            lazy.Should().NotBeNull();
            lazy.Count.Should().Be(0);
            lazy.IsReadOnly.Should().BeFalse();
        }
        public void Contains()
        {
            // Arrange
            var lazy = new LazyCollection <int>(_Int32TestData);

            lazy.Should().NotBeNull();

            // Assert
            lazy.Contains(0).Should().BeTrue();
            lazy.Contains(101).Should().BeFalse();
        }
        public void EnumerableIsNotAccessedWhenListIsNotAccessed()
        {
            var host = new IntEnumerable();
            ICollection<int> collection = new LazyCollection<int>(
                host.GetElements());

            // Exercise
            var array = collection.ToArray();
            var array2 = collection.ToArray();
            // Validate
            Assert.That(host.AccessCount, Is.EqualTo(1));
        }
Пример #7
0
        private static bool GetRelatedAimeIds(ref LazyCollection <AimeId> __result)
        {
            NekoClient.Logging.Log.Info("AimeResult RelatedAimeIds");
            __result = new LazyCollection <AimeId>(() =>
            {
                return(0);
            },
                                                   (a) =>
            {
                return(AimeId.Zero);
            }, true);

            return(false);
        }
        public void CopyTo()
        {
            // Arrange
            var buffer = new int[5];

            var lazy = new LazyCollection <int>(_Int32TestData);

            lazy.Should().NotBeNull();

            // Act
            lazy.CopyTo(buffer, 0);

            buffer.Should().BeEquivalentTo(_Int32TestData);
        }
Пример #9
0
        private static bool GetUnits(ref LazyCollection <AimeUnit> __result)
        {
            NekoClient.Logging.Log.Info("GetUnits");

            __result = new LazyCollection <AimeUnit>(() =>
            {
                return(1);
            },
                                                     (a) =>
            {
                return((AimeUnit)Activator.CreateInstance(typeof(AimeUnit), (System.Reflection.BindingFlags) 62, null, new object[] { IntPtr.Zero }, null));
            }, true);

            return(false);
        }
        public void Constructor_Exceptions()
        {
            // Arrange
            LazyCollection <int> lazy = null;

            // Act
            Action act1 = () => lazy = new LazyCollection <int>((IEnumerable <int>)null);
            Action act2 = () => lazy = new LazyCollection <int>((Func <ICollection <int> >)null);

            // Assert
            act1.Should().Throw <ArgumentNullException>();
            lazy.Should().BeNull();

            act2.Should().Throw <ArgumentNullException>();
            lazy.Should().BeNull();
        }
        public void Enumerate()
        {
            // Arrange
            var list = new List <object>(8);

            var lazy = new LazyCollection <int>(_Int32TestData);

            lazy.Should().NotBeNull();

            foreach (var i in (IEnumerable)lazy)
            {
                list.Add(i);
            }

            list.OfType <int>().Count().Should().Be(5);
            list.OfType <int>().Should().BeEquivalentTo(_Int32TestData);
        }
        public void Add_Remove_Clear()
        {
            // Arrange
            var lazy = new LazyCollection <int>(_Int32TestData);

            lazy.Should().NotBeNull();
            lazy.Count.Should().Be(5);
            lazy.IsReadOnly.Should().BeFalse();

            lazy.Remove(Int32.MinValue);
            lazy.Count.Should().Be(4);

            lazy.Add(Int32.MinValue);
            lazy.Add(101);
            lazy.Count.Should().Be(6);

            lazy.Clear();
            lazy.Count.Should().Be(0);
        }
        public async Task PerformQuery(string searchQuery, bool dontSearchInBothDirections = false)
        {
            if (searchSuggestionCancellationTokenSource != null)
            {
                searchSuggestionCancellationTokenSource.Cancel();
            }

            try
            {
                await querySemaphore.WaitAsync();

                // it may happen that the AutoSuggestBox does not hide search suggestions automatically after
                // performing a query. For these cases, clear the suggestions manually
                SearchSuggestions.Clear();

                Task <List <DictionaryEntry> > searchTask = PerformQueryInner(searchQuery, dontSearchInBothDirections);

                Task animationDelayTask = Task.Delay(250);

                Task finishedTask = await Task.WhenAny(searchTask, animationDelayTask);

                if (finishedTask == animationDelayTask)
                {
                    IsSearchInProgress = true;
                    await searchTask;
                }

                SearchContext searchContext = new SearchContext(searchQuery, selectedDirection, dontSearchInBothDirections);

                List <DictionaryEntry> results = searchTask.Result;

                DictionaryEntries = new LazyCollection <DictionaryEntry, DictionaryEntryViewModel>(
                    results, entry => new DictionaryEntryViewModel(entry, searchContext));
            }
            finally
            {
                IsSearchInProgress = false;

                querySemaphore.Release();
            }
        }