Пример #1
0
        public void Forward_MoveInHistory()
        {
            var query = new[]
            {
                new Mock <IQuery>(),
                new Mock <IQuery>(),
                new Mock <IQuery>(),
                new Mock <IQuery>(),
            };

            for (var i = 0; i < query.Length; ++i)
            {
                query[i].Setup(mock => mock.Text).Returns(i.ToString());
            }

            IExecutableQuery current = null;
            var queryEvents          = new QueryHistory();

            queryEvents.QueryExecuted += (sender, args) => current = args.Query;

            Assert.IsNull(queryEvents.Current);

            queryEvents.ExecuteQuery(query[0].Object);
            Assert.AreEqual(query[0].Object, queryEvents.Current);
            Assert.AreEqual(query[0].Object, current);

            queryEvents.ExecuteQuery(query[1].Object);
            Assert.AreEqual(query[1].Object, queryEvents.Current);
            Assert.AreEqual(query[1].Object, current);

            queryEvents.ExecuteQuery(query[2].Object);
            Assert.AreEqual(query[2].Object, queryEvents.Current);
            Assert.AreEqual(query[2].Object, current);

            queryEvents.Forward();
            Assert.AreEqual(query[2].Object, queryEvents.Current);
            Assert.AreEqual(query[2].Object, current);

            queryEvents.Back();
            queryEvents.ExecuteQuery(query[3].Object);
            Assert.AreEqual(query[3].Object, queryEvents.Current);
            Assert.AreEqual(query[3].Object, current);

            queryEvents.Back();
            queryEvents.Back();
            Assert.AreEqual(query[0].Object, queryEvents.Current);
            Assert.AreEqual(query[0].Object, current);

            queryEvents.Forward();
            Assert.AreEqual(query[1].Object, queryEvents.Current);
            Assert.AreEqual(query[1].Object, current);

            queryEvents.Forward();
            Assert.AreEqual(query[3].Object, queryEvents.Current);
            Assert.AreEqual(query[3].Object, current);
        }
Пример #2
0
        public void Forward_EmptyHistory()
        {
            var executed    = false;
            var queryEvents = new QueryHistory();

            queryEvents.QueryExecuted += (sender, args) => executed = true;

            Assert.IsFalse(executed);
            Assert.IsNull(queryEvents.Current);

            queryEvents.Forward();

            Assert.IsFalse(executed);
            Assert.IsNull(queryEvents.Current);
        }