public void GetConfigurationFromXmlDocument_ShowsErrorForInvalidCacheAttributeValue()
        {
            // Arrange
            var document = BuildDocumentWithPackage("__invalid__");
            var wizard = new TestableVsTemplateWizard();

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() => wizard.GetConfigurationsFromXmlDocument(document,
                @"C:\Some\file.vstemplate").ToList());

            // Assert
            Assert.Equal(
                "The \"repository\" attribute of the package element has an invalid value: '__invalid__'. Valid values are: 'template' or 'extension'.",
                wizard.ErrorMessages.Single());
        }
        private static void InvalidPackageElementHelper(XElement[] content)
        {
            // Arrange
            var document = BuildDocument("template", content);
            var wizard = new TestableVsTemplateWizard();

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() => wizard.GetConfigurationsFromXmlDocument(document,
                @"C:\Some\file.vstemplate").ToList());

            // Assert
            Assert.Equal("The project template lists one or more packages with missing, empty, or invalid values for the \"id\" or \"version\" attributes. Both attributes are required and must have valid values.", wizard.ErrorMessages.Single());
        }
        public void GetConfigurationFromXmlDocument_ShowErrorForMissingRegistryKeyWhenInRegistryRepositoryMode()
        {
            // Arrange
            var registryPath = @"SOFTWARE\NuGet\Repository";
            var registryKeyName = @"ThisRegistryKeyDoesNotExist";
            var document = BuildDocumentWithPackage("registry", new XAttribute("keyName", registryKeyName));
            var wizard = new TestableVsTemplateWizard();

            var hkcu = new Mock<IRegistryKey>();
            hkcu.Setup(r => r.OpenSubKey(registryPath)).Returns<IRegistryKey>(null);

            var registryKey = new Mock<IRegistryKey>();
            registryKey.Setup(r => r.OpenSubKey(registryPath)).Returns<IRegistryKey>(null);

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() =>
                                                           wizard.GetConfigurationsFromXmlDocument(document,
                                                               @"C:\Some\file.vstemplate", registryKeys: new[] { hkcu.Object }).ToList());

            // Assert
            Assert.Equal(
                String.Format("The project template is configured to use a Registry-provided package repository but there was an error accessing Registry key '{0}'.", registryPath),
                wizard.ErrorMessages.Single());
        }
        public void GetConfigurationFromXmlDocument_ShowErrorForMissingRegistryValueWhenInRegistryRepositoryMode()
        {
            // Arrange
            var registryPath = @"SOFTWARE\NuGet\Repository";
            var registryKey = "ThisRegistryKeyDoesNotExist";
            var document = BuildDocumentWithPackage("registry", new XAttribute("keyName", registryKey));
            var wizard = new TestableVsTemplateWizard();

            var hkcu_repository = new Mock<IRegistryKey>();
            var hkcu = new Mock<IRegistryKey>();
            hkcu_repository.Setup(k => k.GetValue(registryKey)).Returns(null);
            hkcu.Setup(r => r.OpenSubKey(registryPath)).Returns(hkcu_repository.Object);

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() =>
                                                           wizard.GetConfigurationsFromXmlDocument(document,
                                                               registryPath, registryKeys: new[] { hkcu.Object }).ToList());

            // Assert
            Assert.Equal(
                String.Format("The project template has a reference to a missing Registry value. Could not find a Registry key with name '{0}' under '{1}'.", registryKey, registryPath),
                wizard.ErrorMessages.Single());
        }
        public void GetConfigurationFromXmlDocument_ShowErrorForMissingKeyNameAttributeWhenInRegistryRepositoryMode()
        {
            // Arrange
            var document = BuildDocumentWithPackage("registry");
            var wizard = new TestableVsTemplateWizard();

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() =>
                                                           wizard.GetConfigurationsFromXmlDocument(document,
                                                               @"C:\Some\file.vstemplate", registryKeys: Enumerable.Empty<IRegistryKey>()).ToList());

            // Assert
            Assert.Equal(
                "The project template is configured to use a Registry-provided package repository but the Registry value name has not been specified. Use the \"keyName\" attribute to specify the Registry value.",
                wizard.ErrorMessages.Single());
        }
        public void GetConfigurationFromXmlDocument_ShowErrorForInvalidRepositoryIdAttributeWhenInExtensionRepositoryMode()
        {
            // Arrange
            var document = BuildDocumentWithPackage("extension", new XAttribute("repositoryId", "myExtensionId"));
            var wizard = new TestableVsTemplateWizard();
            var extensionManagerMock = new Mock<IVsExtensionManager>();
            IInstalledExtension extension = null;
            extensionManagerMock.Setup(em => em.TryGetInstalledExtension("myExtensionId", out extension)).Returns(false);

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() => wizard.GetConfigurationsFromXmlDocument(document,
                @"C:\Some\file.vstemplate",
                vsExtensionManager: extensionManagerMock.Object).ToList());

            // Assert
            Assert.Equal(
                "The project template has a reference to a missing Extension. Could not find an Extension with ID 'myExtensionId'.",
                wizard.ErrorMessages.Single());
        }
        public void GetConfigurationFromXmlDocument_ShowErrorForMissingRepositoryIdAttributeWhenInExtensionRepositoryMode()
        {
            // Arrange
            var document = BuildDocumentWithPackage("extension");
            var wizard = new TestableVsTemplateWizard();

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() =>
                                                           wizard.GetConfigurationsFromXmlDocument(document,
                                                               @"C:\Some\file.vstemplate").ToList());

            // Assert
            Assert.Equal(
                "The project template is configured to use an Extension-specific package repository but the Extension ID has not been specified. Use the \"repositoryId\" attribute to specify the Extension ID.",
                wizard.ErrorMessages.Single());
        }
Esempio n. 8
0
        private static void InvalidPackageElementHelper(XElement[] content)
        {
            // Arrange
            var document = BuildDocument("template", content);
            var wizard = new TestableVsTemplateWizard();

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() => wizard.GetConfigurationsFromXmlDocument(document,
                @"C:\Some\file.vstemplate").ToList());

            // Assert
            Assert.Equal(
                VsResources.TemplateWizard_InvalidPackageElementAttributes,
                wizard.ErrorMessages.Single());
        }
Esempio n. 9
0
        public void GetConfigurationFromXmlDocument_ShowErrorForMissingKeyNameAttributeWhenInRegistryRepositoryMode()
        {
            // Arrange
            var document = BuildDocumentWithPackage("registry");
            var wizard = new TestableVsTemplateWizard();

            // Act
            // Use .ToList() to force enumeration of the yielded results
            ExceptionAssert.Throws<WizardBackoutException>(() =>
                                                           wizard.GetConfigurationsFromXmlDocument(document,
                                                               @"C:\Some\file.vstemplate", registryKeys: Enumerable.Empty<IRegistryKey>()).ToList());

            // Assert
            Assert.Equal(
                VsResources.TemplateWizard_MissingRegistryKeyName,
                wizard.ErrorMessages.Single());
        }