Inheritance: IPackageConfigurationAccessor
コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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());
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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());
        }
コード例 #11
0
        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);
        }