Inheritance: ISourceRepositoryProvider
        public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            // Act
            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Assert
            Assert.IsNotNull(configFileSourceRepositoryProvider);
        }
        public void Delete_RepositoryDoesNotExist_FailureResultIsReturned()
        {
            // Arrange
            string repositoryName = "Some Repository";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(new SourceRepositoryConfiguration[] { });

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.DeleteRepositoryConfiguration(repositoryName);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void Delete_RepositoryDoesNotExist_FailureResultMessageContainsRepositoryName(string repositoryName)
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(new SourceRepositoryConfiguration[] { });

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.DeleteRepositoryConfiguration(repositoryName);

            // Assert
            Assert.IsTrue(result.Message.Contains(repositoryName), "The failure result should contain the name of the repository that shall be deleted.");
        }
        public void Save_RepositoryObjectCannotBeCreated_FailureResultIsReturned()
        {
            // Arrange
            string repositoryName = "does not matter here";
            string repositoryUrl = "does not matter either";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            SourceRepositoryConfiguration repositoryConfiguration = null;
            sourceRepositoryConfigurationFactory.Setup(s => s.GetSourceRepositoryConfiguration(repositoryName, repositoryUrl)).Returns(repositoryConfiguration);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.SaveRepositoryConfiguration(repositoryName, repositoryUrl);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void Save_RepositoryExists_SaveSucceeds_SuccessResultIsReturned()
        {
            // Arrange
            string repositoryName = "Nuget Gallery";
            string repositoryUrl = "http://www.nuget.org/api/v2";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            sourceRepositoryConfigurationFactory.Setup(s => s.GetSourceRepositoryConfiguration(repositoryName, repositoryUrl)).Returns(
                new SourceRepositoryConfiguration { Name = repositoryName, Url = new Uri(repositoryUrl) });

            var reposotories = new[] { new SourceRepositoryConfiguration { Name = "Nuget Gallery", Url = new Uri("http://www.nuget.org/api/v2") } };
            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(reposotories);
            filesystemPersistence.Setup(f => f.Save(It.IsAny<SourceRepositoryConfiguration[]>(), It.IsAny<string>())).Returns(true);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.SaveRepositoryConfiguration(repositoryName, repositoryUrl);

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
        }
        public void Save_RepositoryExists_OneRepositoryIsSaved()
        {
            // Arrange
            string repositoryName = "Nuget Gallery";
            string repositoryUrl = "http://www.nuget.org/api/v2";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            sourceRepositoryConfigurationFactory.Setup(s => s.GetSourceRepositoryConfiguration(repositoryName, repositoryUrl)).Returns(
                new SourceRepositoryConfiguration { Name = repositoryName, Url = new Uri(repositoryUrl) });

            var reposotories = new[] { new SourceRepositoryConfiguration { Name = repositoryName, Url = new Uri("http://www.nuget.org/api/v3") } };
            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(reposotories);
            filesystemPersistence.Setup(f => f.Save(It.IsAny<SourceRepositoryConfiguration[]>(), It.IsAny<string>())).Returns(true);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            configFileSourceRepositoryProvider.SaveRepositoryConfiguration(repositoryName, repositoryUrl);

            // Assert
            filesystemPersistence.Verify(
                f => f.Save(It.Is<SourceRepositoryConfiguration[]>(configurations => configurations.Length == 1), It.IsAny<string>()), Times.Once());
        }
        public void Reset_SaveSucceeds_SuccessResultIsReturned()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            filesystemPersistence.Setup(f => f.Save(It.IsAny<SourceRepositoryConfiguration[]>(), It.IsAny<string>())).Returns(true);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.ResetRepositoryConfiguration();

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
        }
        public void Reset_DefaultRepositoryIsSaved()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            filesystemPersistence.Setup(f => f.Save(It.IsAny<SourceRepositoryConfiguration[]>(), It.IsAny<string>())).Returns(true);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            configFileSourceRepositoryProvider.ResetRepositoryConfiguration();

            // Assert
            filesystemPersistence.Verify(
                f =>
                f.Save(
                    It.Is<SourceRepositoryConfiguration[]>(
                        configurations => configurations.Length == 1 && configurations.First().Name == ConfigFileSourceRepositoryProvider.DefaultRepositoryName),
                    It.IsAny<string>()),
                Times.Once());
        }
        public void Get_AllRepositoriesThatAreReturnedByTheFilesystemPersistence_AreReturned()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            var reposotories = new[] { new SourceRepositoryConfiguration { Name = "Nuget Gallery", Url = new Uri("http://www.nuget.org/api/v3") } };
            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(reposotories);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.GetRepositoryConfigurations();

            // Assert
            Assert.AreEqual(reposotories, result);
        }
        public void Delete_RepositoryNameIsInvalid_ArgumentExceptionIsThrown(string repositoryName)
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            configFileSourceRepositoryProvider.DeleteRepositoryConfiguration(repositoryName);
        }
        public void Delete_RepositoryExists_TheSpecificRepostoryIsExcludedFromTheRepositoryList_CaseIsIgnored(string repositoryName)
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            var existingRepositories = new[]
                {
                    new SourceRepositoryConfiguration { Name = "Repo A", Url = new Uri("http://1.example.com/api/v2") },
                    new SourceRepositoryConfiguration { Name = "Repo B", Url = new Uri("http://2.example.com/api/v2") }
                };

            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(existingRepositories);
            filesystemPersistence.Setup(f => f.Save(It.IsAny<SourceRepositoryConfiguration[]>(), It.IsAny<string>())).Returns(true);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            configFileSourceRepositoryProvider.DeleteRepositoryConfiguration(repositoryName);

            // Assert
            filesystemPersistence.Verify(
                f =>
                f.Save(
                    It.Is<SourceRepositoryConfiguration[]>(configurations => configurations.Length == 1 && configurations.First().Name == "Repo A"),
                    It.IsAny<string>()),
                Times.Once());
        }
        public void Delete_RepositoryExists_SaveSucceeds_SuccessResultIsReturned()
        {
            // Arrange
            string repositoryName = "Repo B";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var sourceRepositoryConfigurationFactory = new Mock<ISourceRepositoryConfigurationFactory>();
            var filesystemPersistence = new Mock<IFilesystemPersistence<SourceRepositoryConfiguration[]>>();

            var existingRepositories = new[]
                {
                    new SourceRepositoryConfiguration { Name = "Repo A", Url = new Uri("http://1.example.com/api/v2") },
                    new SourceRepositoryConfiguration { Name = "Repo B", Url = new Uri("http://2.example.com/api/v2") }
                };

            filesystemPersistence.Setup(f => f.Load(It.IsAny<string>())).Returns(existingRepositories);
            filesystemPersistence.Setup(f => f.Save(It.IsAny<SourceRepositoryConfiguration[]>(), It.IsAny<string>())).Returns(true);

            var configFileSourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(
                applicationInformation, sourceRepositoryConfigurationFactory.Object, filesystemPersistence.Object);

            // Act
            var result = configFileSourceRepositoryProvider.DeleteRepositoryConfiguration(repositoryName);

            // Assert
            Assert.AreEqual(ServiceResultType.Success, result.Status);
        }
        public void Setup()
        {
            var applicationInformation = ApplicationInformationProvider.GetApplicationInformation();

            var encodingProvider = new DefaultFileEncodingProvider();
            var sourceRepositoryConfigurationFactory = new SourceRepositoryConfigurationFactory();
            var objectSerializer = new JSONObjectSerializer<SourceRepositoryConfiguration[]>();
            var filesystemAccessor = new PhysicalFilesystemAccessor(encodingProvider);
            var filesystemPersistence = new FilesystemPersistence<SourceRepositoryConfiguration[]>(filesystemAccessor, objectSerializer);

            this.sourceRepositoryProvider = new ConfigFileSourceRepositoryProvider(applicationInformation, sourceRepositoryConfigurationFactory, filesystemPersistence);
        }