public void NuGetModel_FindPackagesTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call var ran = new Random(DateTime.Now.Millisecond); IList <string> expected = new List <string>() { ran.Next().ToString(), ran.Next().ToString(), ran.Next().ToString(), ran.Next().ToString(), ran.Next().ToString(), }; packageManagerMock.FindPackagesFunc = (ids) => from id in ids select new IPackageMock(id); var result = model.FindPackages(expected).ToList(); Assert.Equal(expected.Count, result.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], result[i].Id); } }
public NuGetModelTests() { // Force clear of cache NuGetModel.ClearCache(); this.DescriptorStub = new Mock <INuGetGalleryDescriptor>(); this.DescriptorStub.Setup(d => d.GalleryId).Returns(0); }
public NuGetViewModelTests() { NuGetModel.ClearCache(); this.Descriptor = new Mock <INuGetGalleryDescriptor>(); // makes sure tests report a failure if an exception is caught by the view model this.Host = new Mock <IWebMatrixHost>(); this.Host .Setup(host => host.ShowExceptionMessage(null, null, null)) .Throws(new Exception("Test tried to report and error to the user")); this.ReadonlyDestination = Path.GetFullPath(@".\DO_NOT_WRITE_HERE\"); }
public void NuGetModel_GetPackagesWithUpdatesTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call string expected = new Random(DateTime.Now.Millisecond).Next().ToString(); packageManagerMock.GetPackagesWithUpdatesFunc = () => new List <IPackage>() { new IPackageMock(expected) }; var result = model.GetPackagesWithUpdates(); Assert.Equal(1, result.Count()); Assert.Equal(expected, result.First().Id); }
public void NuGetModel_IsPackageInstalledTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call bool expected = true; packageManagerMock.IsPackageInstalledFunc = (package) => expected; var result = model.IsPackageInstalled(new IPackageMock(string.Empty)); Assert.Equal(expected, result); expected = true; result = model.IsPackageInstalled(new IPackageMock(string.Empty)); Assert.Equal(expected, result); }
public void NuGetModel_UninstallPackageTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call string expected = new Random(DateTime.Now.Millisecond).Next().ToString(); packageManagerMock.UninstallPackageFunc = (package) => new List <string>() { package.Id }; var result = model.UninstallPackage(new IPackageMock(expected), false); Assert.Equal(1, result.Count()); Assert.Equal(expected, result.First()); }
public void NuGetModel_FindDependencyTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); string expected = "test"; // Setup the mock call packageManagerMock.FindDependenciesToBeInstalledFunc = (package) => new List <IPackage>() { new IPackageMock(expected) }; var result = model.FindDependenciesToBeInstalled(new IPackageMock(expected)).ToList(); Assert.Equal(1, result.Count); Assert.Equal(expected, result[0].Id); }
public void GetInstalledPackages() { string siteRoot = @"c:\"; IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel( this.Descriptor, new IWebMatrixHostMock(), this.DefaultFeedSource, siteRoot, packageManagerMock, TaskScheduler.Default); // Setup the mock call to FindPackages packageManagerMock.FindPackagesFunc = (ids) => Enumerable.Empty <IPackage>(); packageManagerMock.GetInstalledPackagesFunc = () => (from id in fakePackageIds select new IPackageMock(id)).AsQueryable(); Assert.Equal <int>(fakePackageIds.Count, model.GetInstalledPackages().Count()); }
public void NuGetModel_CachingTest() { FeedSource source = new FeedSource(@"c:\", "test"); string destination = @"c:\"; var model = NuGetModel.GetModel(this.Descriptor, new IWebMatrixHostMock(), source, destination, null, TaskScheduler.Default); Assert.False(model.FromCache); model = NuGetModel.GetModel(this.Descriptor, new IWebMatrixHostMock(), source, destination, null, TaskScheduler.Default); Assert.True(model.FromCache); model = null; NuGetModel.ClearCache(); model = NuGetModel.GetModel(this.Descriptor, new IWebMatrixHostMock(), source, destination, null, TaskScheduler.Default); Assert.False(model.FromCache); model = NuGetModel.GetModel(this.Descriptor, new IWebMatrixHostMock(), source, destination, null, TaskScheduler.Default); Assert.True(model.FromCache); }
public ButtonBarViewModelTests() { NuGetModel.ClearCache(); this.CloseCommand = new Mock <ICommand>().Object; this.Descriptor = new Mock <INuGetGalleryDescriptor>(); // makes sure tests report a failure if an exception is caught by the view model this.Host = new Mock <IWebMatrixHost>(); this.Host .Setup(host => host.ShowExceptionMessage(null, null, null)) .Throws(new Exception("Test tried to report and error to the user")); this.PackageManager = new InMemoryPackageManager(); var feedSource = new FeedSource("http://oo.com", "test source"); var feedSourceStore = new InMemoryFeedSourceStore(feedSource); this.PackageSourcesViewModel = new PackageSourcesViewModel(new PackageSourcesModel(feedSource, feedSourceStore)); this.ReadonlyDestination = Path.GetFullPath(@".\DO_NOT_WRITE_HERE\"); }
public void GetInstalledPackages() { string siteRoot = @"c:\"; IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel( this.Descriptor, new IWebMatrixHostMock(), this.DefaultFeedSource, siteRoot, packageManagerMock, TaskScheduler.Default); // Setup the mock call to FindPackages packageManagerMock.FindPackagesFunc = (ids) => Enumerable.Empty<IPackage>(); packageManagerMock.GetInstalledPackagesFunc = () => (from id in fakePackageIds select new IPackageMock(id)).AsQueryable(); Assert.Equal<int>(fakePackageIds.Count, model.GetInstalledPackages().Count()); }
public void NuGetModel_FindPackagesTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call var ran = new Random(DateTime.Now.Millisecond); IList<string> expected = new List<string>() { ran.Next().ToString(), ran.Next().ToString(), ran.Next().ToString(), ran.Next().ToString(), ran.Next().ToString(), }; packageManagerMock.FindPackagesFunc = (ids) => from id in ids select new IPackageMock(id); var result = model.FindPackages(expected).ToList(); Assert.Equal(expected.Count, result.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], result[i].Id); } }
public void NuGetModel_GetPackagesWithUpdatesTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call string expected = new Random(DateTime.Now.Millisecond).Next().ToString(); packageManagerMock.GetPackagesWithUpdatesFunc = () => new List<IPackage>() { new IPackageMock(expected) }; var result = model.GetPackagesWithUpdates(); Assert.Equal(1, result.Count()); Assert.Equal(expected, result.First().Id); }
public void NuGetModel_UninstallPackageTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); // Setup the mock call string expected = new Random(DateTime.Now.Millisecond).Next().ToString(); packageManagerMock.UninstallPackageFunc = (package) => new List<string>() { package.Id }; var result = model.UninstallPackage(new IPackageMock(expected), false); Assert.Equal(1, result.Count()); Assert.Equal(expected, result.First()); }
public void NuGetModel_FindDependencyTest() { IPackageManagerMock packageManagerMock = new IPackageManagerMock(); var model = new NuGetModel(this.Descriptor, new IWebMatrixHostMock(), this.FakeFeedSource, string.Empty, packageManagerMock, TaskScheduler.Default); string expected = "test"; // Setup the mock call packageManagerMock.FindDependenciesToBeInstalledFunc = (package) => new List<IPackage>() { new IPackageMock(expected) }; var result = model.FindDependenciesToBeInstalled(new IPackageMock(expected)).ToList(); Assert.Equal(1, result.Count); Assert.Equal(expected, result[0].Id); }