protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <TestAuditingService>()
            .As <AuditingService>();

            builder.Register(_ =>
            {
                var mockContext = new Mock <HttpContextBase>();
                mockContext.Setup(c => c.Request.Url).Returns(new Uri("https://nuget.local/"));
                mockContext.Setup(c => c.Request.ApplicationPath).Returns("/");
                mockContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);
                return(mockContext.Object);
            })
            .As <HttpContextBase>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock <IPackageService>();
                mockService
                .Setup(p => p.FindPackageRegistrationById(Fakes.Package.Id))
                .Returns(Fakes.Package);
                return(mockService.Object);
            })
            .As <IPackageService>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock <IUserService>();
                mockService.Setup(u => u.FindByUsername(Fakes.User.Username)).Returns(Fakes.User);
                mockService.Setup(u => u.FindByUsername(Fakes.Owner.Username)).Returns(Fakes.Owner);
                mockService.Setup(u => u.FindByUsername(Fakes.Admin.Username)).Returns(Fakes.Admin);
                return(mockService.Object);
            })
            .As <IUserService>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var ctxt = new FakeEntitiesContext();
                Fakes.ConfigureEntitiesContext(ctxt);
                return(ctxt);
            })
            .As <IEntitiesContext>()
            .SingleInstance();

            builder.Register(_ => Fakes.CreateOwinContext())
            .As <IOwinContext>()
            .SingleInstance();
        }
        public override void Load()
        {
            Bind <AuditingService>()
            .ToConstant(new TestAuditingService());

            Bind <HttpContextBase>()
            .ToMethod(_ =>
            {
                var mockContext = new Mock <HttpContextBase>();
                mockContext.Setup(c => c.Request.Url).Returns(new Uri("https://nuget.local/"));
                mockContext.Setup(c => c.Request.ApplicationPath).Returns("/");
                mockContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);
                return(mockContext.Object);
            })
            .InSingletonScope();

            Bind <IPackageService>()
            .ToMethod(_ =>
            {
                var mockService = new Mock <IPackageService>();
                mockService
                .Setup(p => p.FindPackageRegistrationById(Fakes.Package.Id))
                .Returns(Fakes.Package);
                return(mockService.Object);
            })
            .InSingletonScope();

            Bind <IUserService>()
            .ToMethod(_ =>
            {
                var mockService = new Mock <IUserService>();
                mockService.Setup(u => u.FindByUsername(Fakes.User.Username)).Returns(Fakes.User);
                mockService.Setup(u => u.FindByUsername(Fakes.Owner.Username)).Returns(Fakes.Owner);
                mockService.Setup(u => u.FindByUsername(Fakes.Admin.Username)).Returns(Fakes.Admin);
                return(mockService.Object);
            })
            .InSingletonScope();

            Bind <IEntitiesContext>()
            .ToMethod(_ =>
            {
                var ctxt = new FakeEntitiesContext();
                Fakes.ConfigureEntitiesContext(ctxt);
                return(ctxt);
            })
            .InSingletonScope();

            Bind <IOwinContext>()
            .ToMethod(_ => Fakes.CreateOwinContext())
            .InSingletonScope();
        }
        protected override void Load(ContainerBuilder builder)
        {
            var fakes = new Fakes();

            builder.RegisterInstance(fakes)
            .As <Fakes>()
            .SingleInstance();

            builder.RegisterType <TestAuditingService>()
            .As <IAuditingService>();

            builder.Register(_ =>
            {
                var mockContext = new Mock <HttpContextBase>();
                mockContext.Setup(c => c.Request.Url).Returns(new Uri(TestUtility.GallerySiteRootHttps));
                mockContext.Setup(c => c.Request.IsSecureConnection).Returns(true);
                mockContext.Setup(c => c.Request.ApplicationPath).Returns("/");
                mockContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);
                return(mockContext.Object);
            })
            .As <HttpContextBase>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock <IPackageService>();
                mockService
                .Setup(p => p.FindPackageRegistrationById(fakes.Package.Id))
                .Returns(fakes.Package);
                return(mockService.Object);
            })
            .As <IPackageService>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock <IUserService>();
                mockService.Setup(u => u.FindByUsername(fakes.User.Username)).Returns(fakes.User);
                mockService.Setup(u => u.FindByUsername(fakes.Owner.Username)).Returns(fakes.Owner);
                mockService.Setup(u => u.FindByUsername(fakes.Admin.Username)).Returns(fakes.Admin);
                return(mockService.Object);
            }).As <IUserService>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var ctxt = new FakeEntitiesContext();
                fakes.ConfigureEntitiesContext(ctxt);
                return(ctxt);
            })
            .As <IEntitiesContext>()
            .SingleInstance();

            builder.Register(_ => Fakes.CreateOwinContext())
            .As <IOwinContext>()
            .SingleInstance();

            var configurationService = CreateTestConfigurationService();

            UrlExtensions.SetConfigurationService(configurationService);

            builder.Register(_ => configurationService)
            .As <IGalleryConfigurationService>()
            .SingleInstance();

            builder.Register(_ => configurationService.Current)
            .As <IAppConfiguration>()
            .SingleInstance();

            builder.RegisterType <CredentialBuilder>().As <ICredentialBuilder>().SingleInstance();
            builder.RegisterType <CredentialValidator>().As <ICredentialValidator>().SingleInstance();
            builder.RegisterType <DateTimeProvider>().As <IDateTimeProvider>().SingleInstance();
        }
Esempio n. 4
0
        protected override void Load(ContainerBuilder builder)
        {
            var fakes = new Fakes();

            builder.RegisterInstance(fakes)
                .As<Fakes>()
                .SingleInstance();

            builder.RegisterType<TestAuditingService>()
                .As<AuditingService>();

            builder.Register(_ =>
            {
                var mockContext = new Mock<HttpContextBase>();
                mockContext.Setup(c => c.Request.Url).Returns(new Uri("https://nuget.local/"));
                mockContext.Setup(c => c.Request.ApplicationPath).Returns("/");
                mockContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);
                return mockContext.Object;
            })
                .As<HttpContextBase>()
                .SingleInstance();

            builder.Register(_ =>
                    {
                        var mockService = new Mock<IPackageService>();
                        mockService
                            .Setup(p => p.FindPackageRegistrationById(fakes.Package.Id))
                            .Returns(fakes.Package);
                        return mockService.Object;
                    })
                .As<IPackageService>()
                .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock<IUserService>();
                mockService.Setup(u => u.FindByUsername(fakes.User.Username)).Returns(fakes.User);
                mockService.Setup(u => u.FindByUsername(fakes.Owner.Username)).Returns(fakes.Owner);
                mockService.Setup(u => u.FindByUsername(fakes.Admin.Username)).Returns(fakes.Admin);
                return mockService.Object;
            }).As<IUserService>()
              .SingleInstance();

            builder.Register(_ =>
                    {
                        var ctxt = new FakeEntitiesContext();
                        fakes.ConfigureEntitiesContext(ctxt);
                        return ctxt;
                    })
                .As<IEntitiesContext>()
                .SingleInstance();

            builder.Register(_ => Fakes.CreateOwinContext())
                .As<IOwinContext>()
                .SingleInstance();

            builder.Register(_ => new TestGalleryConfigurationService())
                .As<IGalleryConfigurationService>()
                .SingleInstance();

            builder.RegisterType<CredentialBuilder>().As<ICredentialBuilder>().SingleInstance();
            builder.RegisterType<CredentialValidator>().As<ICredentialValidator>().SingleInstance();
            builder.RegisterType<DateTimeProvider>().As<IDateTimeProvider>().SingleInstance();
        }
Esempio n. 5
0
        protected override void Load(ContainerBuilder builder)
        {
            var fakes = new Fakes();

            builder.RegisterInstance(fakes)
            .As <Fakes>()
            .SingleInstance();

            builder.RegisterType <TestAuditingService>()
            .As <IAuditingService>();

            builder.Register(_ =>
            {
                var mockContext = new Mock <HttpContextBase>();
                mockContext.Setup(c => c.Request.Url).Returns(new Uri(TestUtility.GallerySiteRootHttps));
                mockContext.Setup(c => c.Request.IsSecureConnection).Returns(true);
                mockContext.Setup(c => c.Request.ApplicationPath).Returns("/");
                mockContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s);
                return(mockContext.Object);
            })
            .As <HttpContextBase>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock <IPackageService>();

                foreach (var packageRegistration in fakes.PackageRegistrations)
                {
                    mockService
                    .Setup(p => p.FindPackageRegistrationById(packageRegistration.Id))
                    .Returns(packageRegistration);

                    foreach (var package in packageRegistration.Packages)
                    {
                        mockService
                        .Setup(p => p.FindPackageByIdAndVersion(
                                   packageRegistration.Id,
                                   package.Version,
                                   It.Is <int?>(x => package.SemVerLevelKey == null || package.SemVerLevelKey == SemVerLevelKey.Unknown || (x != null && package.SemVerLevelKey <= x)),
                                   It.Is <bool>(x => x || !package.IsPrerelease)))
                        .Returns(package);
                    }
                }
                return(mockService.Object);
            })
            .As <IPackageService>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var mockService = new Mock <IUserService>();

                foreach (var user in fakes.Users)
                {
                    mockService.Setup(u => u.FindByUsername(user.Username, false)).Returns(user);
                }

                return(mockService.Object);
            }).As <IUserService>()
            .SingleInstance();

            builder.Register(_ =>
            {
                var ctxt = new FakeEntitiesContext();
                fakes.ConfigureEntitiesContext(ctxt);
                return(ctxt);
            })
            .As <IEntitiesContext>()
            .SingleInstance();

            builder.Register(_ => Fakes.CreateOwinContext())
            .As <IOwinContext>()
            .SingleInstance();

            var configurationService = CreateTestConfigurationService();

            UrlHelperExtensions.SetConfigurationService(configurationService);

            builder.Register(_ => configurationService)
            .As <IGalleryConfigurationService>()
            .SingleInstance();

            builder.Register(_ => configurationService.Current)
            .As <IAppConfiguration>()
            .SingleInstance();

            builder.RegisterType <CredentialBuilder>().As <ICredentialBuilder>().SingleInstance();
            builder.RegisterType <CredentialValidator>().As <ICredentialValidator>().SingleInstance();
            builder.RegisterType <DateTimeProvider>().As <IDateTimeProvider>().SingleInstance();

            builder.RegisterType <AutocompleteCveIdsQuery>()
            .As <IAutocompleteCveIdsQuery>()
            .InstancePerLifetimeScope();

            builder.RegisterType <AutocompleteCweIdsQuery>()
            .As <IAutocompleteCweIdsQuery>()
            .InstancePerLifetimeScope();

            builder.RegisterType <VulnerabilityAutocompleteService>()
            .As <IVulnerabilityAutocompleteService>()
            .InstancePerLifetimeScope();
        }