Пример #1
0
        public void FindQueriesByNameOrderByName_Test()
        {
            // Arrange
            TestDbSet <SqlQuery> dbSet = new TestDbSet <SqlQuery>()
            {
                new SqlQuery()
                {
                    SqlQueryId          = 0,
                    SqlQueryName        = "Command sql",
                    SqlQueryContent     = "Simple sql command",
                    SqlQueryCreatedDate = DateTime.Today.AddDays(-3)
                },
                new SqlQuery()
                {
                    SqlQueryId          = 1,
                    SqlQueryName        = "Big query sql",
                    SqlQueryContent     = "Huge sql query",
                    SqlQueryCreatedDate = DateTime.Today.AddDays(-2)
                },
                new SqlQuery()
                {
                    SqlQueryId          = 2,
                    SqlQueryName        = "A first query",
                    SqlQueryContent     = "first query in set",
                    SqlQueryCreatedDate = DateTime.Today
                }
            };

            int QueriesWithSqlWordInName = dbSet
                                           .Where(q => q.SqlQueryName.Contains("sql"))
                                           .Count();
            IEnumerable <SqlQuery> queries = dbSet
                                             .Where(q => q.SqlQueryName.Contains("sql"))
                                             .Select(i => i)
                                             .OrderBy(q => q.SqlQueryName);

            Mock <IContext> mock = new Mock <IContext>();

            mock
            .Setup(q => q.SqlQueries)
            .Returns(dbSet);

            QueryRepository repository = new QueryRepository(mock.Object);

            // Act
            IEnumerable <SqlQuery> orderedQueries = repository
                                                    .FindQueriesByNameOrderByName("sql");

            // Assert
            Assert.AreEqual(QueriesWithSqlWordInName, orderedQueries.Count());
            Assert.AreEqual(
                queries.ToList().First().SqlQueryName,
                orderedQueries.ToList().First().SqlQueryName
                );
            Assert.AreEqual(
                queries.ToList().Last().SqlQueryId,
                orderedQueries.ToList().Last().SqlQueryId
                );
        }