public TestableCuratedPackagesController() { Fakes = new Fakes(); StubCuratedFeed = new CuratedFeed { Key = 0, Name = "aFeedName", Managers = new HashSet<User>(new[] { Fakes.User }) }; StubPackageRegistration = new PackageRegistration { Key = 0, Id = "anId" }; OwinContext = Fakes.CreateOwinContext(); EntitiesContext = new FakeEntitiesContext(); EntitiesContext.CuratedFeeds.Add(StubCuratedFeed); EntitiesContext.PackageRegistrations.Add(StubPackageRegistration); var curatedFeedRepository = new EntityRepository<CuratedFeed>( EntitiesContext); var curatedPackageRepository = new EntityRepository<CuratedPackage>( EntitiesContext); base.CuratedFeedService = new CuratedFeedService( curatedFeedRepository, curatedPackageRepository); var httpContext = new Mock<HttpContextBase>(); TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this); }
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(); }
public TheAuthenticateMethod() { _fakes = Get<Fakes>(); _dateTimeProviderMock = GetMock<IDateTimeProvider>(); _authenticationService = Get<AuthenticationService>(); }