Example #1
0
        public void GetSources_WhenUnknownExceptionIsThrown_ThrowsKnownException()
        {
            // Arrange
            var sourceRepositoryProvider = new Mock <ISourceRepositoryProvider>();
            var packageSourceProvider    = new Mock <IPackageSourceProvider>();
            var telemetryProvider        = new Mock <INuGetTelemetryProvider>();

            sourceRepositoryProvider.SetupGet(x => x.PackageSourceProvider)
            .Returns(packageSourceProvider.Object);

            var originalException = new NuGetConfigurationException("a");

            packageSourceProvider.Setup(x => x.LoadPackageSources())
            .Throws(originalException);

            // Act
            VsPackageSourceProvider vsPackageSourceProvider = CreateTarget(sourceRepositoryProvider: sourceRepositoryProvider.Object, telemetryProvider: telemetryProvider.Object);
            var actualException = Assert.Throws <InvalidOperationException>(() => vsPackageSourceProvider.GetSources(includeUnOfficial: true, includeDisabled: true));

            // Assert
            telemetryProvider.Verify(p => p.PostFault(originalException, typeof(VsPackageSourceProvider).FullName, nameof(VsPackageSourceProvider.GetSources), It.IsAny <IDictionary <string, object> >()));

            Assert.Equal(originalException.Message, actualException.Message);
            Assert.Same(originalException, actualException.InnerException);
        }
Example #2
0
        public void GetSources_WhenKnownExceptionIsThrown_ThrowsThatException(Type exceptionType)
        {
            var sourceRepositoryProvider = new Mock <ISourceRepositoryProvider>();
            var packageSourceProvider    = new Mock <IPackageSourceProvider>();

            sourceRepositoryProvider.SetupGet(x => x.PackageSourceProvider)
            .Returns(packageSourceProvider.Object);

            var expectedException = (Exception)Activator.CreateInstance(exceptionType);

            packageSourceProvider.Setup(x => x.LoadPackageSources())
            .Throws(expectedException);

            var vsPackageSourceProvider = new VsPackageSourceProvider(sourceRepositoryProvider.Object);

            Assert.Throws(exceptionType, () => vsPackageSourceProvider.GetSources(includeUnOfficial: true, includeDisabled: true));
        }
Example #3
0
        public void GetSources_WhenUnknownExceptionIsThrown_ThrowsKnownException()
        {
            var sourceRepositoryProvider = new Mock <ISourceRepositoryProvider>();
            var packageSourceProvider    = new Mock <IPackageSourceProvider>();

            sourceRepositoryProvider.SetupGet(x => x.PackageSourceProvider)
            .Returns(packageSourceProvider.Object);

            var originalException = new NuGetConfigurationException("a");

            packageSourceProvider.Setup(x => x.LoadPackageSources())
            .Throws(originalException);

            var vsPackageSourceProvider = new VsPackageSourceProvider(sourceRepositoryProvider.Object);

            var actualException = Assert.Throws <InvalidOperationException>(() => vsPackageSourceProvider.GetSources(includeUnOfficial: true, includeDisabled: true));

            Assert.Equal(originalException.Message, actualException.Message);
            Assert.Same(originalException, actualException.InnerException);
        }