Esempio n. 1
0
        public static IServiceCollection AddPlanningPokerClient(this IServiceCollection services, IConfigurationRoot configuration)
        {
            services.Configure <PokerConnectionSettings>(options => configuration.GetSection("PokerConnectionSettings").Bind(options));

            var validatedConfiguration = IServiceCollectionExtension.ValidateAndRetrieveConfiguration(configuration);

            var connectionSettings = new PokerConnectionSettings(
                validatedConfiguration.PlanningSocketUri,
                validatedConfiguration.PlanningApiUri,
                validatedConfiguration.PlanningApiKey
                );
            var connectionSettingsOptions = Options.Create(connectionSettings);

            var messageParser = new MessageParser();

            services.AddSingleton(typeof(MessageParser), messageParser);

            var responseMessageFactories = new List <IResponseMessageFactory>();

            responseMessageFactories.Add(new NewSessionResponseMessageFactory(messageParser));
            responseMessageFactories.Add(new SubscribeSessionResponseMessageFactory(messageParser));
            responseMessageFactories.Add(new JoinSessionResponseMessageFactory(messageParser));
            responseMessageFactories.Add(new RefreshSessionMessageFactory(messageParser));
            responseMessageFactories.Add(new EndSessionClientMessageFactory(messageParser));

            var responseMessageParser = new ResponseMessageParser(messageParser, responseMessageFactories);

            services.AddSingleton(typeof(IResponseMessageParser), responseMessageParser);

            var planningPokerSocket = new PlanningPokerSocket(connectionSettingsOptions);

            services.AddSingleton(typeof(IPokerConnection), planningPokerSocket);

            var userCacheProvider = new UserCacheProvider();

            services.AddSingleton(typeof(UserCacheProvider), userCacheProvider);

            var httpClient = new HttpClient();

            services.AddSingleton(typeof(HttpClient), httpClient);
            var planningPokerApiService = new PlanningPokerApiService(httpClient, connectionSettingsOptions);

            services.AddSingleton(typeof(IPlanningPokerService), planningPokerApiService);

            var planningPokerConnectionFactory = new PlanningConnectionFactory(connectionSettingsOptions,
                                                                               responseMessageParser, planningPokerSocket, userCacheProvider, planningPokerApiService);

            services.AddSingleton(typeof(IPlanningConnectionFactory), planningPokerConnectionFactory);
            services = AddResponseMessageFactories(services);

            return(services);
        }
        public GetSessionDetailsTests()
        {
            _connectionSettings = new Mock <PokerConnectionSettings>();
            _connectionSettings.Setup(x => x.PlanningApiUri).Returns(new Uri(_serviceUri));
            _connectionSettings.Setup(x => x.ApiKey).Returns(_apiKey);
            _options = new Mock <IOptions <PokerConnectionSettings> >();
            _options.Setup(x => x.Value).Returns(_connectionSettings.Object);
            _fakeHttpMessageHandler = new Mock <FakeHttpMessageHandler> {
                CallBase = true
            };
            _httpClient = new HttpClient(_fakeHttpMessageHandler.Object);

            _planningPokerApiService = new PlanningPokerApiService(_httpClient, _options.Object);
        }