public void TestRepositoryCacheBuilt() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2" } }); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "2.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); PackagesController packages = new PackagesController() { LocalRepository = localRepository, Cache = cache }; packages.Poke(); Assert.IsNotNull(packages.Cache.Repositories.First(repository => repository.Uri == "localhost")); Assert.AreEqual("A", packages.Cache.Repositories.First(repository => repository.Uri == "localhost").Packages.First().Id); Assert.AreEqual(PackageState.UpdateAvailable, packages.Cache.Repositories.First(repository => repository.Uri == "localhost").Packages.First().State); }
public void TestResultAlreadyExists() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); cache.Build(localRepository); PackagesController packages = new PackagesController() { Cache = cache }; ICommandResult result = packages.Tunnel(CommandBuilder.PackagesUninstallPackage("A").SetOrigin(CommandOrigin.Local)); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.AlreadyExists, result.CommandResultType); }
public void TestExceptionOnCacheBuildAttachedToRepositoryModel() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockExceptionPackageRepository()); // Now successfully build the repository.. cache.Build(localRepository); Assert.AreEqual("GetPackages Exception", cache.Repositories.First(repository => repository.IsOrphanage == false).CacheError); }
public void TestRepositoryCacheBuiltEventLogged() { EventsController events = new EventsController(); var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2" } }); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "2.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); PackagesController packages = new PackagesController() { LocalRepository = localRepository, Cache = cache }; packages.Shared.Events = events; packages.Poke(); Assert.IsNotEmpty(events.LoggedEvents); Assert.AreEqual("PackagesCacheRebuilt", events.LoggedEvents.First().Name); Assert.AreEqual("A", events.LoggedEvents.First().Now.Repositories.First(repository => repository.Uri == "localhost").Packages.First().Id); Assert.AreEqual(PackageState.UpdateAvailable, events.LoggedEvents.First().Now.Repositories.First(repository => repository.Uri == "localhost").Packages.First().State); }
public void TestLastCacheBuildErrorNulled() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); cache.Repositories.First(repository => repository.IsOrphanage == false).CacheError = "Error!!"; // Now successfully build the repository.. cache.Build(localRepository); Assert.IsNull(cache.Repositories.First(repository => repository.IsOrphanage == false).CacheError); }
public void TestCacheClearSingleRepositoryListMaintainOrphanedRepository() { var cache = new RepositoryCache(); cache.Add("localhost"); cache.Clear(); Assert.IsNotEmpty(cache.Repositories); Assert.IsNotNull(cache.Repositories.First(repository => repository.IsOrphanage == true)); }
public void TestCacheBuildSingleRemoteRepositoryUpdateAvailableLocalRepository() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2" } }); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "2.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); cache.Build(localRepository); Assert.IsNotEmpty(cache.Repositories.SelectMany(repository => repository.Packages)); Assert.AreEqual("A", cache.Repositories.SelectMany(repository => repository.Packages).First().Id); Assert.AreEqual(PackageState.UpdateAvailable, cache.Repositories.SelectMany(repository => repository.Packages).First().State); }
public void TestIgnoreMissingPotatoTag() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Tag1 Tag2", IsLatestVersion = true }, new DataServicePackage() { Id = "B", Version = "1.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true }, new DataServicePackage() { Id = "C", Version = "1.0.0", Tags = "Tag1 Tag2", IsLatestVersion = true } })); cache.Build(localRepository); Assert.AreEqual(1, cache.Repositories.SelectMany(repository => repository.Packages).Count()); Assert.AreEqual("B", cache.Repositories.SelectMany(repository => repository.Packages).First().Id); }
public void TestLastCacheBuildStampSet() { var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); // Now successfully build the repository.. cache.Build(localRepository); Assert.Greater(cache.Repositories.First(repository => repository.IsOrphanage == false).CacheStamp, DateTime.Now.AddSeconds(-5)); }