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(); }
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)).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(); 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(); }