public TestableApiController(MockBehavior behavior = MockBehavior.Default)
        {
            OwinContext               = Fakes.CreateOwinContext();
            EntitiesContext           = (MockEntitiesContext = new Mock <IEntitiesContext>()).Object;
            PackageService            = (MockPackageService = new Mock <IPackageService>(behavior)).Object;
            UserService               = (MockUserService = new Mock <IUserService>(behavior)).Object;
            NugetExeDownloaderService = (MockNuGetExeDownloaderService = new Mock <INuGetExeDownloaderService>(MockBehavior.Strict)).Object;
            ContentService            = (MockContentService = new Mock <IContentService>()).Object;
            StatisticsService         = (MockStatisticsService = new Mock <IStatisticsService>()).Object;
            IndexingService           = (MockIndexingService = new Mock <IIndexingService>()).Object;
            AutoCuratePackage         = (MockAutoCuratePackage = new Mock <IAutomaticallyCuratePackageCommand>()).Object;

            MockPackageFileService = new Mock <IPackageFileService>(MockBehavior.Strict);
            MockPackageFileService.Setup(p => p.SavePackageFileAsync(It.IsAny <Package>(), It.IsAny <Stream>()))
            .Returns(Task.CompletedTask);
            PackageFileService = MockPackageFileService.Object;

            MessageService = (MockMessageService = new Mock <IMessageService>()).Object;

            MockConfigurationService = new Mock <IGalleryConfigurationService>();
            MockConfigurationService.SetupGet(s => s.Features.TrackPackageDownloadCountInLocalDatabase)
            .Returns(false);
            ConfigurationService = MockConfigurationService.Object;

            AuditingService = new TestAuditingService();

            TestUtility.SetupHttpContextMockForUrlGeneration(new Mock <HttpContextBase>(), this);
        }
Esempio n. 2
0
            public TestableCuratedFeedsController()
            {
                Fakes = new Fakes();

                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubCuratedFeedService = new Mock <ICuratedFeedService>();

                SetOwinContextOverride(Fakes.CreateOwinContext());

                StubCuratedFeedService
                .Setup(stub => stub.GetFeedByName(It.IsAny <string>(), It.IsAny <bool>()))
                .Returns(StubCuratedFeed);

                CuratedFeedService = StubCuratedFeedService.Object;

                StubSearchService = new Mock <ISearchService>();
                SearchService     = StubSearchService.Object;

                var httpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);

                this.SetCurrentUser(Fakes.User);
            }
            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"
                };

                SetOwinContextOverride(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);
            }
        private static UsersController CreateController(
            GallerySetting settings           = null,
            Mock <IUserService> userSvc       = null,
            Mock <IMessageService> messageSvc = null,
            Mock <IPrincipal> currentUser     = null)
        {
            userSvc = userSvc ?? new Mock <IUserService>();
            var packageService = new Mock <IPackageService>();

            messageSvc = messageSvc ?? new Mock <IMessageService>();
            settings   = settings ?? new GallerySetting();

            if (currentUser == null)
            {
                currentUser = new Mock <IPrincipal>();
                currentUser.Setup(u => u.Identity.Name).Returns((string)null);
            }

            var controller = new UsersController(
                userSvc.Object,
                packageService.Object,
                messageSvc.Object,
                settings,
                currentUser.Object);

            TestUtility.SetupHttpContextMockForUrlGeneration(new Mock <HttpContextBase>(), controller);
            return(controller);
        }
Esempio n. 5
0
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };
                StubPackage = new Package
                {
                    Key = 34,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version = "1.0.0"
                };
                StubLatestPackage = new Package
                {
                    Key = 42,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version      = "2.0.1-alpha",
                    IsLatest     = true,
                    IsPrerelease = true
                };
                StubLatestStablePackage = new Package
                {
                    Key = 41,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version        = "2.0.0",
                    IsLatestStable = true
                };

                OwinContext = Fakes.CreateOwinContext();

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                StubPackageRegistration.Packages.Add(StubPackage);
                StubPackageRegistration.Packages.Add(StubLatestPackage);
                StubPackageRegistration.Packages.Add(StubLatestStablePackage);

                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);
            }
            public void WillSearchForAPackage()
            {
                var controller = new TestableCuratedFeedsController();

                var redPill = new PackageRegistration
                {
                    Id            = "RedPill",
                    Key           = 2,
                    DownloadCount = 0,
                    Packages      = new []
                    {
                        new Package
                        {
                            Key = 89932,
                        }
                    },
                    Owners = new []
                    {
                        new User
                        {
                            Key      = 66,
                            Username = "******",
                        }
                    }
                };

                redPill.Packages.ElementAt(0).PackageRegistration = redPill;

                var mockPackageRegistrations = new [] { redPill }.AsQueryable();
                var mockPackages = new[] { redPill.Packages.ElementAt(0) }.AsQueryable();

                controller.StubCuratedFeedService
                .Setup(stub => stub.GetKey("TheMatrix"))
                .Returns(2);

                int totalHits;

                controller.StubSearchService
                .Setup(stub => stub.Search(It.IsAny <SearchFilter>(), out totalHits))
                .Returns(mockPackages);

                var mockHttpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(mockHttpContext, controller);

                // Act
                var result = controller.ListPackages("TheMatrix", "");

                Assert.IsType <ViewResult>(result);
                Assert.IsType <PackageListViewModel>(((ViewResult)result).Model);
                var model = (result as ViewResult).Model as PackageListViewModel;

                Assert.Equal(1, model.Items.Count());
            }
            public TestableUsersController()
            {
                FeedsQuery     = (MockFeedsQuery = new Mock <ICuratedFeedsByManagerQuery>()).Object;
                CurrentUser    = (MockCurrentUser = new Mock <IPrincipal>()).Object;
                MessageService = (MockMessageService = new Mock <IMessageService>()).Object;
                PackageService = (MockPackageService = new Mock <IPackageService>()).Object;
                Config         = (MockConfig = new Mock <IConfiguration>()).Object;
                UserService    = (MockUserService = new Mock <IUserService>()).Object;

                MockCurrentIdentity = new Mock <IIdentity>();
                MockCurrentUser.Setup(u => u.Identity).Returns(MockCurrentIdentity.Object);

                var mockContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(mockContext, this);
            }
Esempio n. 8
0
        public TestableApiController(MockBehavior behavior = MockBehavior.Default)
        {
            OwinContext               = Fakes.CreateOwinContext();
            EntitiesContext           = (MockEntitiesContext = new Mock <IEntitiesContext>()).Object;
            PackageService            = (MockPackageService = new Mock <IPackageService>(behavior)).Object;
            UserService               = (MockUserService = new Mock <IUserService>(behavior)).Object;
            NugetExeDownloaderService = (MockNuGetExeDownloaderService = new Mock <INuGetExeDownloaderService>(MockBehavior.Strict)).Object;
            ContentService            = (MockContentService = new Mock <IContentService>()).Object;
            StatisticsService         = (MockStatisticsService = new Mock <IStatisticsService>()).Object;
            IndexingService           = (MockIndexingService = new Mock <IIndexingService>()).Object;

            MockPackageFileService = new Mock <IPackageFileService>(MockBehavior.Strict);
            MockPackageFileService.Setup(p => p.SavePackageFileAsync(It.IsAny <Package>(), It.IsAny <Stream>())).Returns(Task.FromResult(0));
            PackageFileService = MockPackageFileService.Object;

            TestUtility.SetupHttpContextMockForUrlGeneration(new Mock <HttpContextBase>(), this);
        }