public void TestInitialize()
        {
            var serviceCollection = new ServiceCollection()
                                    .AddLogging();

            serviceCollection.Add(new ServiceDescriptor(typeof(DatabaseContext),
                                                        UnitTestDatabaseContext.Get()));
            serviceCollection.Add(new ServiceDescriptor(typeof(DaoManager),
                                                        DaoManager.Get(UnitTestDatabaseContext.Get())));
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var factory         = serviceProvider.GetService <ILoggerFactory>();
            var logger          = factory.CreateLogger <OrderProductsController>();

            Controller = new OrderProductsController(logger)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext
                    {
                        RequestServices = serviceProvider
                    }
                }
            };
            var identity = new ClaimsIdentity();

            identity.AddClaim(new Claim(ClaimTypes.Sid, "3"));
            identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
            Controller.ControllerContext.HttpContext.User = new ClaimsPrincipal(identity);
        }
        public void ProcessDataReader_GivenAQuery_AndReturnsAListOfUsers()
        {
            var query = "SELECT * FROM `user` WHERE UserId = 5";

            List <User> queryResult;

            using (var connection = new MySqlConnection(UnitTestDatabaseContext.Get().ConnectionString))
            {
                connection.Open();
                using (var command = new MySqlCommand(query, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        queryResult = UserDao.ProcessDataReader(reader);
                        connection.Close();
                    }
                }
            }

            Assert.IsInstanceOfType(queryResult, typeof(List <User>));
        }
        public void ProcessDataReader_GivenAQuery_AndReturnsAUserWithId5()
        {
            var query = "SELECT * FROM `user` WHERE UserId = 5";

            List <User> queryResult;

            using (var connection = new MySqlConnection(UnitTestDatabaseContext.Get().ConnectionString))
            {
                connection.Open();
                using (var command = new MySqlCommand(query, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        queryResult = UserDao.ProcessDataReader(reader);
                    }

                    connection.Close();
                }
            }
            var foundUser = queryResult[0];

            Assert.AreEqual(foundUser.Id, 5);
        }