Exemple #1
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddIdentityServer()
     .AddTemporarySigningCredential()
     .AddInMemoryApiResources(ApiResources.GetApiResources())
     .AddInMemoryClients(Clients.GetClients())
     .AddTestUsers(TestUsers.GetUsers());
 }
Exemple #2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddIdentityServer()
     .AddTestUsers(TestUsers.GetUsers())
     .AddInMemoryClients(Clients.GetClients())
     .AddInMemoryApiResources()
     .AddInMemoryPersistedGrants();
 }
        public ExternalController(
            IIdentityServerInteractionService interaction,
            IClientStore clientStore,
            IEventService events,
            TestUserStore users = null)
        {
            // if the TestUserStore is not in DI, then we'll just use the global users collection
            // this is where you would plug in your own custom identity management library (e.g. ASP.NET Identity)
            _users = users ?? new TestUserStore(TestUsers.GetUsers());

            _interaction = interaction;
            _clientStore = clientStore;
            _events      = events;
        }
Exemple #4
0
        public string GetUserFullName(long userId)
        {
            var user = TestUsers.GetUsers().First(a => a.SubjectId == userId.ToString());

            return(user.Claims.First(a => a.Type == JwtClaimTypes.Name).Value);
        }
        public void Initialize()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            // var memoryCache = new MemoryCache(new MemoryCacheOptions());
            //
            // ICollectionOptions inMemoryCollectionOptions = new InMemoryDatabaseOptions();
            // UnitOfWork = new NoActionUnitOfWork(memoryCache, LoggerFactory, inMemoryCollectionOptions);

            var services = new ServiceCollection();

            Directory.Delete("quiz", true);
            Directory.CreateDirectory("quiz");
            services
            .AddLogging(builder => builder.AddConsole())
            .AddMemoryCache()
            .AddSingleton(_ => new QuizrSettings
            {
                BaseUrl     = "https://localhost:5001",
                WebRootPath = "",
                ContentPath = "quiz"
            })
            .AddSingleton <ICollectionOptions, InMemoryDatabaseOptions>()
            .AddScoped <IUnitOfWork, NoActionUnitOfWork>();

            AddDI(services);
            AddMediatr(_container, typeof(TeamRegistered).Assembly);
            _container.Collection.Register(typeof(IRequestPreProcessor <>),
                                           new[]
            {
                typeof(RequestValidationPreProcessor <>)
            });

            var serviceProvider = services.BuildServiceProvider();

            serviceProvider.UseSimpleInjector(_container);

            _container.Verify();

            _scope = AsyncScopedLifestyle.BeginScope(_container);

            LoggerFactory = _container.GetInstance <ILoggerFactory>();
            UnitOfWork    = _container.GetInstance <IUnitOfWork>();
            Mediator      = _container.GetInstance <IMediator>();
            QuizrSettings = _container.GetInstance <QuizrSettings>();

            var quizCollection     = UnitOfWork.GetCollection <Quiz>();
            var userCollection     = UnitOfWork.GetCollection <User>();
            var teamCollection     = UnitOfWork.GetCollection <Team>();
            var gameCollection     = UnitOfWork.GetCollection <Game>();
            var questionCollection = UnitOfWork.GetCollection <QuizItem>();

            Users = TestUsers.GetUsers();
            Quiz  = TestQuiz.GetQuiz();
            Game  = TestGame.GetGame(Users.Where(u => u.UserName == "Quiz master 1").Select(u => u.Id), Quiz);
            Users.First(u => u.UserName == "Quiz master 1").GameIds.Add(Game.Id);
            Users.First(u => u.UserName == "Quiz master 1").QuizIds.Add(Quiz.Id);
            Teams           = TestTeams.GetTeams(teamCollection, Game.Id);
            Game.QuizId     = Quiz.Id;
            Game.TeamIds    = Teams.Select(t => t.Id).ToList();
            QuestionsInQuiz = TestQuiz.GetQuizItems();
            OtherQuestions  = new List <QuizItem> {
                new QuizItem(), new QuizItem(), new QuizItem()
            };
            Task.WaitAll(
                quizCollection.AddAsync(Quiz),
                QuestionsInQuiz.ToAsyncEnumerable().ForEachAsync(q => questionCollection.AddAsync(q)),
                OtherQuestions.ToAsyncEnumerable().ForEachAsync(q => questionCollection.AddAsync(q)),
                Teams.ToAsyncEnumerable().ForEachAsync(t => teamCollection.AddAsync(t)),
                Users.ToAsyncEnumerable().ForEachAsync(u => userCollection.AddAsync(u)),
                gameCollection.AddAsync(Game));
        }