public void Log_and_rethrow() { var context = new ContextFor <NuPlugPackageManager>(); var sut = context.BuildSut(); var foo = "foo".CreatePackage("0.1.0"); var expExc = new InvalidOperationException("test"); context.For <IPackageRepository>(nameof(sut.LocalRepository)) .GetPackages() .Returns(x => { throw expExc; }); using (var tl = new TestTraceListener()) { sut.Logger = new TraceLogger(); try { sut.InstallPackage(foo, true, false); } catch (Exception ex) { ex.Should().Be(expExc); } tl.MessagesFor(TraceLevel.Warning) .Single() .Should() .StartWith($"Could not install '{foo.Id} {foo.Version}': "); } }
private static void AssertCatch(Exception ex) { var throwingTypeFilter = (Func <Type, bool>)(type => { throw ex; #pragma warning disable 162 return(true); #pragma warning restore 162 }); var assembly = Assembly.GetExecutingAssembly(); using (var ttl = new TestTraceListener { ActiveTraceLevel = TraceLevel.Verbose }) { using (new SafeDirectoryCatalog(assembly.GetDirectory(), throwingTypeFilter)) ttl.MessagesFor(TraceLevel.Verbose).Should().OnlyContain(msg => msg.StartsWith("Could not load '")); ttl.MessagesFor(TraceLevel.Info).Should().BeEmpty("should only log at Verbose level"); } }
public void Log_to_trace() { var sut = new TraceLogger(); using (var traceListener = new TestTraceListener { ActiveTraceLevel = TraceLevel.Verbose }) { foreach (MessageLevel messageLevel in Enum.GetValues(typeof(MessageLevel))) { var traceLevel = messageLevel.ToTraceLevel(); var message = $"message: {messageLevel} - {traceLevel}"; sut.Log(messageLevel, message); traceListener.MessagesFor(traceLevel).Should().Contain(message); } } }
public void Only_install_dependencies_matching_target_framework(string thisGroup, string otherGroup) { var context = new ContextFor <NuPlugPackageManager>(); var sut = context.BuildSut(); var targetFramework = VersionUtility.ParseFrameworkName(thisGroup); var otherFramework = VersionUtility.ParseFrameworkName(otherGroup); var package = "foo".CreatePackage("0.1.0"); var dependency = "bar".CreatePackage("0.1.1"); var otherDependency = "buzz".CreatePackage("0.1.2"); var deps = new[] { new PackageDependencySet(targetFramework, new[] { new PackageDependency(dependency.Id) }), new PackageDependencySet(otherFramework, new[] { new PackageDependency(otherDependency.Id) }) }; package.DependencySets.Returns(deps); var localPackages = Enumerable.Empty <IPackage>(); sut.LocalRepository.GetPackages().Returns(localPackages.AsQueryable()); var remotePackages = new[] { package, dependency, otherDependency }; sut.SourceRepository.GetPackages().Returns(remotePackages.AsQueryable()); //repo sut.Logger = new TraceLogger(); using (var ttl = new TestTraceListener()) { sut.InstallPackage(package, false, false); var infos = ttl.MessagesFor(TraceLevel.Info); infos.Should().BeEquivalentTo( $"Attempting to resolve dependency '{dependency.Id}'.", $"Installing '{dependency.Id} {dependency.Version}'.", $"Successfully installed '{dependency.Id} {dependency.Version}'.", $"Installing '{package.Id} {package.Version}'.", $"Successfully installed '{package.Id} {package.Version}'."); } package.Received().GetCompatiblePackageDependencies(targetFramework); sut.SourceRepository.Received().GetPackages(); }
public void Ignore_Walk_info_by_default() { var context = new ContextFor <NuPlugPackageManager>(); var sut = context.BuildSut(); sut.DisableWalkInfo.Should().BeTrue(); var package = "foo".CreatePackage("0.1.0"); sut.Logger = new TraceLogger(); using (var tl = new TestTraceListener()) { sut.InstallPackage(package, false, true); var infos = tl.MessagesFor(TraceLevel.Info); infos.Should().BeEquivalentTo( $"Installing '{package.Id} {package.Version}'.", $"Successfully installed '{package.Id} {package.Version}'."); } }
public void Ignore_AlreadyInstalled_Packages() { var context = new ContextFor <NuPlugPackageManager>(); var packageLookup = Substitute.For <IPackageLookup>(); var packageRegistry = new NuPlugPackageRegistry(); var localRepo = new NuPlugPackageRepository(packageLookup, packageRegistry); var sut = context.BuildSut(); var foo = "foo".CreatePackage("0.1.0"); var bar = "bar".CreatePackage("2.9.0"); var versionSpec = new VersionSpec(SemanticVersion.Parse("2.6.0")) { MaxVersion = null }; var deps = new[] { new PackageDependencySet(sut.TargetFramework, new[] { new PackageDependency(bar.Id, versionSpec) }) }; foo.DependencySets.Returns(deps); localRepo.AddPackage(new NullPackage(bar.Id, bar.Version)); var remotePackages = new[] { foo }; sut.SourceRepository.GetPackages().Returns(remotePackages.AsQueryable()); sut.SetLocalRepository(localRepo); sut.Logger = new TraceLogger(); using (var tl = new TestTraceListener()) { sut.InstallPackage(foo, false, true); var infos = tl.MessagesFor(TraceLevel.Info); infos.Should().BeEquivalentTo( $"Attempting to resolve dependency '{bar.Id} (≥ {versionSpec.MinVersion})'.", //$"{bar.Id} already installed.", $"Installing '{foo.Id} {foo.Version}'.", $"Successfully installed '{foo.Id} {foo.Version}'." ); } }
public void Resolve_assemblies(Type typeToResolve) { using (var sut = new AssemblyResolver { TraceAlways = true }) using (var ttl = new TestTraceListener { ActiveTraceLevel = TraceLevel.Verbose }) { var assembly = typeToResolve.Assembly; var dir = assembly.GetDirectory(); sut.Directories.Add(dir); var requesting = typeof(AssemblyResolver_Should).Assembly; var aName = assembly.GetName(); var resolvedAssembly = sut.ResolveAssembly(this, new ResolveEventArgs(aName.Name, requesting)); resolvedAssembly.GetName().Name.Should().Be(aName.Name); var msgs = ttl.MessagesFor(TraceLevel.Verbose).ToArray(); msgs[0].Should().Be($"Requested to load '{aName.Name}' by '{requesting.FullName}'."); msgs[1].Should().StartWith($"Resolved '{aName.Name}, {aName.Version}' from '{assembly.GetLocation()}"); } }