Esempio n. 1
0
        public void Setup()
        {
            // Builds webhost and gets service providers from web host
            var webHost = WebHost.CreateDefaultBuilder()
                          .UseStartup <Startup>()
                          .Build();

            _serviceProvider = new ServiceDependencyResolver(webHost);

            // Resets database to inital state so all tests are isolated and repeatable
            _context = new FlatManagementContext();
            _context.Database.EnsureDeleted();
            _context.Database.EnsureCreated();

            var testDataGenerator = new DevelopmentDatabaseSetup(_context);

            testDataGenerator.SetupDevelopmentDataSet();

            _flatController = new FlatController(_context);

            //Creates a new httpContext and adds a user identity to it, imitating being already logged in.
            DefaultHttpContext httpContext = new DefaultHttpContext();
            GenericIdentity    MyIdentity  = new GenericIdentity("YinWang");
            ClaimsIdentity     objClaim    = new ClaimsIdentity(new List <Claim> {
                new Claim(ClaimTypes.NameIdentifier, "1")
            });

            _flatController.ControllerContext             = new ControllerContext();
            _flatController.ControllerContext.HttpContext = httpContext;
            httpContext.User = new ClaimsPrincipal(objClaim);
        }
        public void Setup()
        {
            _dbSetUpHelper   = new DatabaseSetUpHelper();
            _serviceProvider = _dbSetUpHelper.GetServiceDependencyResolver();
            _context         = _dbSetUpHelper.GetContext();

            _userController = new UserController(_serviceProvider.GetService <IOptions <AppSettings> >(), _context);
        }
Esempio n. 3
0
        public void Setup()
        {
            _dbSetUpHelper   = new DatabaseSetUpHelper();
            _serviceProvider = _dbSetUpHelper.GetServiceDependencyResolver();
            _context         = _dbSetUpHelper.GetContext();

            _paymentsRepository     = new PaymentsRepository(_context);
            _userPaymentsRepository = new UserPaymentsRepository(_context);
            _flatRepository         = new FlatRepository(_context);
            _userRepository         = new UserRepository(_context);

            // ISSUE: controller takes in IMapper, but no way of instantiating
            _paymentsController = new PaymentsController(_paymentsRepository, _userPaymentsRepository, _flatRepository, _userRepository, null);
        }
Esempio n. 4
0
        public void Setup()
        {
            // Builds webhost and gets service providers from web host
            var webHost = WebHost.CreateDefaultBuilder()
                          .UseStartup <Startup>()
                          .Build();

            _serviceProvider = new ServiceDependencyResolver(webHost);

            // Resets database to inital state so all tests are isolated and repeatable
            _context = new FlatManagementContext();
            _context.Database.EnsureDeleted();
            _context.Database.EnsureCreated();

            var testDataGenerator = new DevelopmentDatabaseSetup(_context);

            testDataGenerator.SetupDevelopmentDataSet();
        }
        public void Setup()
        {
            _dbSetUpHelper   = new DatabaseSetUpHelper();
            _serviceProvider = _dbSetUpHelper.GetServiceDependencyResolver();
            _context         = _dbSetUpHelper.GetContext();

            _httpContextHelper = new HttpContextHelper();
            var httpContext = _httpContextHelper.GetHttpContext();
            var objClaim    = _httpContextHelper.GetClaimsIdentity();

            _userController = new UserController(_serviceProvider.GetService <IOptions <AppSettings> >(), _context)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext
                }
            };
            httpContext.User = new ClaimsPrincipal(objClaim);
        }
 public void Setup()
 {
     _dbSetUpHelper   = new DatabaseSetUpHelper();
     _serviceProvider = _dbSetUpHelper.GetServiceDependencyResolver();
     _context         = _dbSetUpHelper.GetContext();
 }