public void NewHistoryIsEmpty()
        {
            var history = new RuntimeSearchHistory();

            var entries = history.SearchedTerms();

            Assert.Empty(entries);
        }
        public void AddingEntryToHistoryWillYieldThisEntry()
        {
            var          history      = new RuntimeSearchHistory();
            const string expectedTerm = "anything";

            history.AddEntry(expectedTerm);

            var entries = history.SearchedTerms();

            Assert.Contains(entries, e => e.Equals(expectedTerm, StringComparison.Ordinal));
        }
        public void RemovingTermThatIsNotInListDoesNothing()
        {
            var          history  = new RuntimeSearchHistory();
            const string anything = nameof(anything);

            history.RemoveEntry(anything);

            var entries = history.SearchedTerms();

            Assert.Empty(entries);
        }
        public void TwiceAddedTermIsYieldedOnlyOnce()
        {
            var          history      = new RuntimeSearchHistory();
            const string expectedTerm = "anything";

            history.AddEntry(expectedTerm);
            history.AddEntry(expectedTerm);

            var entries = history.SearchedTerms();

            Assert.Single(entries);
        }
        public void RemovedTermIsNotYielded()
        {
            var          history      = new RuntimeSearchHistory();
            const string expectedTerm = "anything";

            history.AddEntry(expectedTerm);
            history.RemoveEntry(expectedTerm);

            var entries = history.SearchedTerms();

            Assert.Empty(entries);
        }
        public void ManuallyGivenDateIsRespected()
        {
            var          history = new RuntimeSearchHistory();
            const string oldTerm = nameof(oldTerm);
            const string newTerm = nameof(newTerm);

            history.AddEntry(oldTerm, DateTime.Now + TimeSpan.FromHours(1));
            history.AddEntry(newTerm);
            var inOrder = new[] { oldTerm, newTerm };

            var entries = history.SearchedTerms();

            Assert.Equal(inOrder, entries);
        }
        public void EntriesAreSortedByDateDescending()
        {
            var          history = new RuntimeSearchHistory();
            const string oldTerm = nameof(oldTerm);
            const string newTerm = nameof(newTerm);

            history.AddEntry(oldTerm);
            history.AddEntry(newTerm);
            var inOrder = new[] { newTerm, oldTerm };

            var entries = history.SearchedTerms();

            Assert.Equal(inOrder, entries);
        }
        public void EntryAddedAgainWillUpdateItsUsedTime()
        {
            var          history = new RuntimeSearchHistory();
            const string oldTerm = nameof(oldTerm);
            const string newTerm = nameof(newTerm);

            history.AddEntry(oldTerm);
            history.AddEntry(newTerm);
            history.AddEntry(oldTerm);

            var newestEntry = history.SearchedTerms().First();

            Assert.Equal(oldTerm, newestEntry);
        }
        public void AddingEntriesToHistoryWillYieldTheseEntries()
        {
            var history       = new RuntimeSearchHistory();
            var expectedTerms = new[] { "term1", "term2" };

            foreach (var term in expectedTerms)
            {
                history.AddEntry(term);
            }

            var entries = history.SearchedTerms();

            Assert.Equal(expectedTerms.Reverse(), entries.ToArray());
        }