public void PopulateRegistry_PopulatesRegistry()
        {
            // Arrange
            var containerConfig = new ContainerConfiguration(
                typeof(ServiceProvisioningInitializerUnitTests).Assembly,
                "Mmu");

            var registry = new ServiceRegistry();

            // Act
            ServiceProvisioningInitializer.PopulateRegistry(containerConfig, registry);

            // Assert
            Assert.That(registry, Is.Not.Empty);
        }
Пример #2
0
        public void ConfigureContainer(ServiceRegistry registry)
        {
            var containerConfig = ContainerConfiguration.CreateFromAssembly(typeof(Startup).Assembly);

            ServiceProvisioningInitializer.PopulateRegistry(containerConfig, registry);

            var dropboxLocator = new Container(registry).GetService <IDropboxLocator>();
            var dropboxPath    = dropboxLocator.LocateDropboxPath();

            var completePath = Path.Combine(dropboxPath, "Apps", "LinkedInPoc", "Secrets.txt");
            var textLines    = File.ReadAllLines(completePath);

            registry.AddAuthentication(
                options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = "LinkedIn";
            })
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddLinkedIn("LinkedIn", options =>
            {
                options.ClientId     = textLines[0];
                options.ClientSecret = textLines[1];
                options.CallbackPath = new PathString("/signin-linkedin");

                options.SaveTokens = true;
                options.Scope.Clear();
                options.Scope.Add("r_liteprofile");
                options.Scope.Add("r_emailaddress");
                options.Scope.Add("w_member_social");

                options.Events.OnCreatingTicket = ticket =>
                {
                    // For some reason, HttpContext.GetTokenAsync("access_token") doesn't work;
                    LinkedInAccessTokenSingleton.Value = ticket.AccessToken;
                    return(Task.CompletedTask);
                };
            });

            registry.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            registry.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();
            registry.AddControllersWithViews();
            registry.AddRazorPages();
        }