상속: IPackageConfigurationAccessor
        public void AddOrUpdate_PackageInfoParameterIsNull_ArgumentNullExceptionIsThrown()
        {
            // Arrange
            PackageInfo packageInfo = null;

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            packageConfigurationAccessor.AddOrUpdate(packageInfo);
        }
        public void AddOrUpdate_PackageInfoIsInvalid_ResultIsFalse()
        {
            // Arrange
            var packageInfo = new PackageInfo();

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            var result = packageConfigurationAccessor.AddOrUpdate(packageInfo);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Failure);
        }
        public void AddOrUpdate_PackageListIsEmpty_AddNewPackage_OnePackageIsSaved()
        {
            // Arrange
            var packageInfo = new PackageInfo { Id = "Package.A", Version = "1.0.0.0" };

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packages = new PackageInfo[] { };
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            packageConfigurationAccessor.AddOrUpdate(packageInfo);

            // Assert
            packageInfoFilesystemPersistence.Verify(
                p => p.Save(It.Is<PackageInfo[]>(packageList => packageList.Count() == 1 && packageList.Contains(packageInfo)), It.IsAny<string>()),
                Times.Once());
        }
        public void Remove_PackageListIsEmpty_ResultIsFalse()
        {
            // Arrange
            string packageId = "Package.A";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packages = new PackageInfo[] { };
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            var result = packageConfigurationAccessor.Remove(packageId);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Failure);
        }
        public void Remove_PackageListContainsSuppliedPackageId_SaveSucceeds_ResultIsTrue()
        {
            // Arrange
            string packageId = "Package.A";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packages = new[]
                {
                    new PackageInfo { Id = "Package.A", Version = "1.0.0.0" }
                };
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            packageInfoFilesystemPersistence.Setup(p => p.Save(It.IsAny<PackageInfo[]>(), It.IsAny<string>())).Returns(true);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            var result = packageConfigurationAccessor.Remove(packageId);

            // Assert
            Assert.AreEqual(result.Status, ServiceResultType.Success);
        }
        public void Remove_PackageListContainsSuppliedPackageId_EmptyListIsSaved()
        {
            // Arrange
            string packageId = "Package.A";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packages = new[]
                {
                    new PackageInfo { Id = "Package.A", Version = "1.0.0.0" }
                };
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            packageConfigurationAccessor.Remove(packageId);

            // Assert
            packageInfoFilesystemPersistence.Verify(p => p.Save(It.Is<PackageInfo[]>(packageList => !packageList.Any()), It.IsAny<string>()), Times.Once());
        }
        public void Remove_PackageIdIsInvalid_ArgumentExceptionIsThrown(string packageId)
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            packageConfigurationAccessor.Remove(packageId);
        }
        public void GetInstalledPackages_ListIsEmpty_ResultIsEmptyList()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            PackageInfo[] packages = null;
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            var result = packageConfigurationAccessor.GetInstalledPackages();

            // Assert
            Assert.AreEqual(0, result.Count());
        }
        public void GetInstalledPackages_ListContainsUnsortedPackages_ResultIsSorted()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packages = new[]
                {
                    new PackageInfo { Id = "Z", Version = "1.0.0.0" },
                    new PackageInfo { Id = "J", Version = "1.0.0.0" },
                    new PackageInfo { Id = "G", Version = "1.0.0.0" },
                    new PackageInfo { Id = "C", Version = "1.0.0.0" },
                    new PackageInfo { Id = "B", Version = "1.0.0.0" },
                    new PackageInfo { Id = "A", Version = "1.0.0.0" }
                };
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            var result = packageConfigurationAccessor.GetInstalledPackages();

            // Assert
            Assert.AreEqual("A", result.First().Id);
            Assert.AreEqual("Z", result.Last().Id);
        }
        public void GetInstalledPackages_ListContainsTwoIdenticalPackages_ResultContainsOnlyOneEntry()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            var packages = new[]
                {
                    new PackageInfo { Id = "Package.A", Version = "1.0.0.0" },
                    new PackageInfo { Id = "Package.A", Version = "1.0.0.0" }
                };
            packageInfoFilesystemPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(packages);

            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Act
            var result = packageConfigurationAccessor.GetInstalledPackages();

            // Assert
            Assert.AreEqual(1, result.Count());
        }
        public void Constructor_AllParametersAreSet_ObjectIsInstantiated()
        {
            // Arrange
            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var packageInfoFilesystemPersistence = new Mock<IFilesystemPersistence<PackageInfo[]>>();

            // Act
            var packageConfigurationAccessor = new PackageConfigurationAccessor(applicationInformation, packageInfoFilesystemPersistence.Object);

            // Assert
            Assert.IsNotNull(packageConfigurationAccessor);
        }