public void Read_ThrowException_DirectoryIsNotSet()
        {
            //setup
            TestPackageHelper.CleanPackagesDefaultDirectory(PackagesFileHelper.GetDefaultPackagesFolderFullPath());
            var storageOptions            = new PackagesFileStorageOptions();
            var packageFileStorageService = new PackageFileStorageService(storageOptions, It.IsAny <IMapper>());

            // act + assert
            Assert.Throws <DirectoryNotFoundException>(() =>
                                                       packageFileStorageService.Read());
        }
        public async Task Save_ReturnsGetOSVersionPackage()
        {
            //setup
            TestPackageHelper.CleanPackagesDefaultDirectory(PackagesFileHelper.GetDefaultPackagesFolderFullPath());

            // Act
            var newPackage = await SaveTestPackageFile();

            // Assert
            Assert.NotNull(newPackage);
            Assert.Equal(newPackage.Id, TestPackageHelper.GetOSVersionPackageId, StringComparer.OrdinalIgnoreCase);
        }
        public void GetPackagesFolderPath_ReturnsPathAccordingWithInlineData(string path)
        {
            // Act
            var folderPath = PackagesFileHelper.GetPackagesFolderPath(path);

            // Assert
            if (!string.IsNullOrWhiteSpace(path))
            {
                Assert.Equal(path, folderPath);
            }
            else
            {
                Assert.Equal(folderPath, PackagesFileHelper.GetDefaultPackagesFolderFullPath());
            }
        }
        public async Task Save_ThrowsException_WhenStreamWasDisposedBefore()
        {
            //setup
            TestPackageHelper.CleanPackagesDefaultDirectory(PackagesFileHelper.GetDefaultPackagesFolderFullPath());

            // Act + assert
            using (var stream = new MemoryStream(File.ReadAllBytes(TestPackageHelper.GetOSVersionPackageFilePath())))
            {
                using (var reader = new PackageArchiveReader(stream))
                {
                    stream.Dispose();
                    await Assert.ThrowsAsync <ObjectDisposedException>(() => _packageFileStorageService.Save(reader.NuspecReader, stream));
                }
            }
        }
        public async Task Read_ReturnsGetOSVersionPackage()
        {
            //setup
            TestPackageHelper.CleanPackagesDefaultDirectory(PackagesFileHelper.GetDefaultPackagesFolderFullPath());

            // Act
            var packages = _packageFileStorageService.Read();

            // Assert 1
            Assert.False(packages.Any());

            // save package file
            var newPackage = await SaveTestPackageFile();

            // Assert 2
            Assert.NotNull(newPackage);

            packages = _packageFileStorageService.Read();

            Assert.True(packages.Any());
            Assert.Equal(packages.Single().Id, TestPackageHelper.GetOSVersionPackageId, StringComparer.OrdinalIgnoreCase);
            Assert.NotNull(packages.Single().PackageDependencies);
            Assert.True(packages.Single().PackageDependencies.Any());
        }