Exemplo n.º 1
0
        public void GetYearTest()
        {
            using (var cursor = Substitute.For <ICursor>())
            {
                cursor.GetInt(0).Returns(1999);
                cursor.GetInt(1).Returns(7);
                cursor.GetColumnIndex("year").Returns(0);
                cursor.GetColumnIndex("count").Returns(1);

                using (var dataAccess = Substitute.For <IDataAccess>())
                {
                    dataAccess.ExecuteQueryWithParametersAsync(Arg.Any <string>(), Arg.Any <List <SQLiteParameter> >()).Returns(cursor);

                    using (var statisticsController = new StatisticsController(dataAccess))
                    {
                        var countAlbumsPerYear = statisticsController.GetCountofAlbumsPerYearAsync().Result;
                        Assert.IsNotNull(countAlbumsPerYear);
                        Assert.IsInstanceOf <Dictionary <int, int> >(countAlbumsPerYear);
                        Assert.AreEqual(1, countAlbumsPerYear.Count);
                        Assert.IsTrue(countAlbumsPerYear.ContainsKey(1999));
                        Assert.AreEqual(7, countAlbumsPerYear[1999]);
                    }
                }
            }
        }