Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            services.AddDbContext <GamayunDbContext>(opts => opts.UseSqlServer(Configuration["ConnectionStrings:Gamayun"]));
            services.AddIdentity <AppUser, IdentityRole>()
            .AddEntityFrameworkStores <GamayunDbContext>()
            .AddDefaultTokenProviders()
            .AddClaimsPrincipalFactory <AppUserClaimsPrincipalFactory>();

            services.AddSingleton <ISettings, Settings>();
            services.AddScoped <ICommandRunner, CommandRunner>();
            services.AddScoped <IGridQueryRunner, GridQueryRunner>();
            services.AddScoped <ICommandHandler <CreateUserCommandHandler.AdminCommand>, CreateUserCommandHandler>();
            services.AddScoped <ICommandHandler <CreateUserCommandHandler.StudentCommand>, CreateUserCommandHandler>();
            services.AddScoped <ICommandHandler <CreateUserCommandHandler.TeacherCommand>, CreateUserCommandHandler>();
            services.AddScoped <ICommandHandler <EditUserCommandHandler.AdminCommand>, EditUserCommandHandler>();
            services.AddScoped <ICommandHandler <EditUserCommandHandler.StudentCommand>, EditUserCommandHandler>();
            services.AddScoped <ICommandHandler <EditUserCommandHandler.TeacherCommand>, EditUserCommandHandler>();
            services.AddScoped <ICommandHandler <CreateSemesterCommandHandler.Command>, CreateSemesterCommandHandler>();
            services.AddScoped <ICommandHandler <EditSemesterCommandHandler.Command>, EditSemesterCommandHandler>();
            services.AddScoped <ICommandHandler <CreateTopicCommandHandler.Command>, CreateTopicCommandHandler>();
            services.AddScoped <ICommandHandler <EditTopicCommandHandler.Command>, EditTopicCommandHandler>();
            services.AddScoped <ICommandHandler <CreateSectionCommandHandler.Command>, CreateSectionCommandHandler>();
            services.AddScoped <ICommandHandler <EditSectionCommandHandler.Command>, EditSectionCommandHandler>();
            services.AddScoped <ICommandHandler <UpdateSectionPresencesCommandHandler.Command>, UpdateSectionPresencesCommandHandler>();

            services.AddScoped <IGridQueryHandler <UserRM, TeachersQueryHandler.Query>, TeachersQueryHandler>();
            services.AddScoped <IGridQueryHandler <UserRM, AdminsQueryHandler.Query>, AdminsQueryHandler>();
            services.AddScoped <IGridQueryHandler <UserRM, StudentsQueryHandler.Query>, StudentsQueryHandler>();
            services.AddScoped <IGridQueryHandler <SemesterRM, SemestersQueryHandler.Query>, SemestersQueryHandler>();
            services.AddScoped <IGridQueryHandler <TopicRM, TopicsQueryHandler.Query>, TopicsQueryHandler>();
            services.AddScoped <IGridQueryHandler <SectionRM, SectionsQueryHandler.Query>, SectionsQueryHandler>();
            services.AddScoped <IGridQueryHandler <UserRM, StudentsForSectionQueryHandler.Query>, StudentsForSectionQueryHandler>();
            services.AddScoped <IGridQueryHandler <UserRM, StudentsForSectionQueryHandler.Query>, StudentsForSectionQueryHandler>();
            services.AddScoped <IGridQueryHandler <SectionRM, MySectionsQueryHandler.Query>, MySectionsQueryHandler>();
            services.AddScoped <IGridQueryHandler <SectionRM, FindSectionsQueryHandler.Query>, FindSectionsQueryHandler>();

            var autoMapperConfig = AutomapperService.Initialize();

            services.AddSingleton(autoMapperConfig);

            services.ConfigureApplicationCookie(opt =>
            {
                opt.LoginPath        = "/Account/Login";
                opt.AccessDeniedPath = "/Account/AccessDenied";
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Esempio n. 2
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <GamayunDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestDB")
                          .Options;

            _dbContext = new GamayunDbContext(options);
            _dbContext.Users.AddRange(new[] { user1, user2, user3, user4, user5 });
            _dbContext.Teachers.AddRange(new Teacher[] { _teacher1, _teacher2, _teacher3, _teacher4, _teacher5 });
            _dbContext.SaveChanges();
            _mapperConfig = AutomapperService.Initialize();
            _queryHandler = new TeachersQueryHandler(_dbContext, _mapperConfig);
        }