예제 #1
0
        public void ThenCanParseResultsFileAsSemicolonSeparatedList()
        {
            FileSystem.AddFile(@"c:\results1.xml", "<xml />");
            FileSystem.AddFile(@"c:\results2.xml", "<xml />");
            var args = new[] { @"-link-results-file=c:\results1.xml;c:\results2.xml" };

            var  configuration             = new Configuration();
            var  commandLineArgumentParser = new CommandLineArgumentParser(FileSystem);
            bool shouldContinue            = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null);

            Check.That(shouldContinue).IsTrue();
            Check.That(configuration.HasTestResults).IsTrue();
            Check.That(configuration.TestResultsFiles.First().FullName).IsEqualTo(@"c:\results1.xml");
            Check.That(configuration.TestResultsFiles.Skip(1).First().FullName).IsEqualTo(@"c:\results2.xml");
        }
예제 #2
0
        public void File_with_include_is_processed()
        {
            const string templateContents     = "<html><head><title>@Model.Title</title></head><body>@Raw(Model.Content)</body></html>";
            const string pageContents         = "<i>@Include(\"TestInclude\")</i>";
            const string layoutContents       = "<b>Included!</b>";
            const string expectedfileContents = "<html><head><title>My Web Site</title></head><body><i><b>Included!</b></i></body></html>";

            FileSystem.AddFile(@"C:\website\_includes\TestInclude.cshtml", new MockFileData(layoutContents));
            ProcessContents(templateContents, pageContents, new Dictionary <string, object> {
                { "title", "My Web Site" }
            });
            string output = FileSystem.File.ReadAllText(@"C:\website\_site\index.html");

            Assert.Equal(expectedfileContents, output);
        }
        protected void AddTestResultsToConfiguration()
        {
            foreach (var fileName in this.resultsFileNames)
            {
                // Write out the embedded test results file
                using (var input = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("PicklesDoc.Pickles.Test.TestFrameworks." + fileName)))
                {
                    FileSystem.AddFile(fileName, new MockFileData(input.ReadToEnd()));
                }
            }

            var configuration = Container.Resolve <Configuration>();

            configuration.AddTestResultFiles(this.resultsFileNames.Select(f => FileSystem.FileInfo.FromFileName(f)));
        }
        void GivenAnInstalledVersion()
        {
            _preUpdateVersion = new SemanticVersion(new Version(1, 0));
            _builder          = new AppUpdaterBuilder(TestConstants.AppPackageId)
                                .SetupWithTestValues(_preUpdateVersion);

            FileSystem = _builder.GetMockFileSystem();

            _appFiles = new[] { "app.exe", "app.exe.config", "nuget.dll", "data.db", "content\\logo.png" };

            foreach (var file in _appFiles)
            {
                FileSystem.AddFile(Path.Combine(AppDirectory, file), MockFileContent(file, _preUpdateVersion));
            }
        }
        public void CanAddFunctionWrapperAroundJson()
        {
            string filePath = @"d:\output\pickledFeatures.json";

            FileSystem.AddFile(filePath, "\r\n[]\r\n");

            var jsonTweaker = new JsonTweaker(FileSystem);

            jsonTweaker.AddJsonPWrapperTo(filePath);

            var expected = "jsonPWrapper (\r\n[]\r\n);";
            var actual   = FileSystem.File.ReadAllText(filePath);

            Check.That(actual).IsEqualTo(expected);
        }
예제 #6
0
        private void ProcessContents(string layout, string content, Dictionary <string, object> bag)
        {
            FileSystem.AddFile(@"C:\website\_layouts\Test.cshtml", new MockFileData(layout));
            var context = new SiteContext {
                SourceFolder = @"C:\website\", OutputFolder = @"C:\website\_site", Title = "My Web Site"
            };

            bag.Add("layout", "Test");
            context.Posts.Add(new Page {
                File = "index.cshtml", Content = content, OutputFile = @"C:\website\_site\index.html", Bag = bag, Url = "/index.html"
            });
            FileSystem.AddFile(@"C:\website\index.cshtml", new MockFileData(layout));
            Subject.FileSystem = FileSystem;
            Subject.Process(context);
        }
        public string Setup()
        {
            const string OUTPUT_DIRECTORY   = FileSystemPrefix + @"JSONFeatureOutput";
            const string ROOT_PATH          = FileSystemPrefix + @"JSON\Features";
            const string testResultFilePath = FileSystemPrefix + @"JSON\results-example-failing-and-pasing-mstest.trx";

            string filePath = FileSystem.Path.Combine(OUTPUT_DIRECTORY, JSONDocumentationBuilder.JsonFileName);

            AddFakeFolderAndFiles("JSON", new[] { "results-example-failing-and-pasing-mstest.trx" });
            AddFakeFolderAndFiles(
                @"JSON\Features",
                new[]
            {
                "OneScenarioTransferingMoneyBetweenAccountsFailing.feature",
                "TransferBetweenAccounts_WithSuccess.feature",
                "TwoScenariosTransferingFundsOneFailingOneSuccess.feature",
                "TwoScenariosTransferingMoneyBetweenAccoutsWithSuccess.feature",
            });

            var resultFile = RetrieveContentOfFileFromResources(ResourcePrefix + "JSON.results-example-failing-and-pasing-mstest.trx");

            FileSystem.AddFile(testResultFilePath, resultFile);

            GeneralTree <INode> features = Container.Resolve <DirectoryTreeCrawler>().Crawl(ROOT_PATH);

            var outputDirectory = FileSystem.DirectoryInfo.FromDirectoryName(OUTPUT_DIRECTORY);

            if (!outputDirectory.Exists)
            {
                outputDirectory.Create();
            }

            var configuration = new Configuration
            {
                OutputFolder        = FileSystem.DirectoryInfo.FromDirectoryName(OUTPUT_DIRECTORY),
                DocumentationFormat = DocumentationFormat.JSON,
                TestResultsFiles    = new[] { FileSystem.FileInfo.FromFileName(testResultFilePath) },
                TestResultsFormat   = TestResultsFormat.MsTest
            };

            ITestResults testResults = new MsTestResults(configuration);
            var          jsonDocumentationBuilder = new JSONDocumentationBuilder(configuration, testResults, FileSystem);

            jsonDocumentationBuilder.Build(features);
            string content = FileSystem.File.ReadAllText(filePath);

            return(content);
        }
예제 #8
0
        void AndGivenAPreparedUpdateForANewerVersion()
        {
            _preparedUpdate = Substitute.For <IPreparedUpdate>();
            _newVersion     = new Version(1, 1);
            _preparedUpdate.Version.Returns(_newVersion);

            _newAppFiles = new[] { "app.exe", "app.exe.config", "nuget.dll", "app.core.dll", "content\\logo.png" };
            FileSystem.CreateDirectory(@"c:\app\.updates\1.1");

            foreach (var file in _newAppFiles)
            {
                FileSystem.AddFile(Path.Combine(PrepDir, file), MockFileContent(file, _newVersion));
            }

            _preparedUpdate.Files.Returns(_newAppFiles.Select(file => Path.Combine(PrepDir, file)));
        }
        public void should_skip_if_file_is_in_use_by_another_process()
        {
            GivenValidAuthor();

            foreach (var file in _audioFiles)
            {
                FileSystem.AddFile(file, new MockFileData("".PadRight(10))
                {
                    AllowedFileShare = FileShare.None
                });
            }

            Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory));

            VerifyNoImport();
        }
        public void ThenCanParseMultipleResultsFilesWithWildCardsAndSemicolonWhenSomeHaveNoMatch()
        {
            FileSystem.AddFile(@"c:\results_foo1.xml", "<xml />");
            FileSystem.AddFile(@"c:\results_foo2.xml", "<xml />");
            var args = new[] { @"-link-results-file=c:\results_foo*.xml;c:\results_bar*.xml" };

            var  configuration             = new Configuration();
            var  commandLineArgumentParser = new CommandLineArgumentParser(FileSystem);
            bool shouldContinue            = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null);

            Check.That(shouldContinue).IsTrue();
            Check.That(configuration.HasTestResults).IsTrue();
            Check.That(configuration.TestResultsFiles
                       .Select(trf => trf.FullName))
            .ContainsExactly(@"c:\results_foo1.xml", @"c:\results_foo2.xml");
        }
예제 #11
0
            public override void When()
            {
                FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents));
                FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents));

                for (var i = 1; i <= 7; i++)
                {
                    FileSystem.AddFile(String.Format(@"C:\website\_posts\2012-02-0{0}-p{0}.md", i), new MockFileData(PostContents));
                }

                var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty <IContentTransform>());
                var context   = generator.BuildContext(@"C:\website\", false);

                Subject.FileSystem = FileSystem;
                Subject.Process(context);
            }
예제 #12
0
        public override void When()
        {
            FileSystem.AddFile(@"C:\website\_layouts\default.cshtml", new MockFileData(TemplateContents));
            FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents));

            for (var i = 1; i <= 7; i++)
            {
                FileSystem.AddFile(String.Format(@"C:\website\_posts\2012-02-0{0}-p{0}.md", i), new MockFileData(String.Format(PostContents, i)));
            }

            var generator = new SiteContextGenerator(FileSystem, new LinkHelper(), new Configuration());
            var context   = generator.BuildContext(@"C:\website\", @"C:\website\_site", false);

            Subject.FileSystem = FileSystem;
            Subject.Process(context);
        }
예제 #13
0
        public void RemoveLock_Should_Remove_Current_Lock()
        {
            // create valid lock that shouldn't get removed
            var validLock = $"{TestFileName}.{Guid.NewGuid()}.launchlock";

            FileSystem.AddFile(validLock, new Mocks().GetLaunchLockJson(validLock));

            // create current lock that should get removed
            LockBuilder.Build();
            LockWriter.Write();

            GetCurrentLauchLocks();

            Unlocker.RemoveLock();

            GetCurrentLauchLocks().Count().Should().Be(1);
        }
        private void SaveDocument(XDocument document)
        {
            // Sort the elements by path
            var repositoryElements = (from e in GetRepositoryElements(document)
                                      let path = e.GetOptionalAttributeValue("path")
                                                 where !String.IsNullOrEmpty(path)
                                                 orderby path.ToUpperInvariant()
                                                 select e).ToList();

            // Remove all elements
            document.Root.RemoveAll();

            // Re-add them sorted
            repositoryElements.ForEach(e => document.Root.Add(e));

            FileSystem.AddFile(StoreFilePath, document.Save);
        }
예제 #15
0
        public void should_update_fields_for_updated_files()
        {
            var files = new List <string>
            {
                Path.Combine(_artist.Path, "Season 1", "file1.mobi"),
            };

            GivenKnownFiles(files);

            FileSystem.AddFile(files[0], new MockFileData("".PadRight(100))
            {
                LastWriteTime = new DateTime(2019, 2, 1)
            });

            var localTrack = Builder <LocalBook> .CreateNew()
                             .With(x => x.Path          = files[0])
                             .With(x => x.Modified      = new DateTime(2019, 2, 1))
                             .With(x => x.Size          = 100)
                             .With(x => x.Quality       = new QualityModel(Quality.MOBI))
                             .With(x => x.FileTrackInfo = new ParsedTrackInfo
            {
                MediaInfo = Builder <MediaInfoModel> .CreateNew().Build()
            })
                             .Build();

            Mocker.GetMock <IMakeImportDecision>()
            .Setup(x => x.GetImportDecisions(It.IsAny <List <IFileInfo> >(), It.IsAny <IdentificationOverrides>(), It.IsAny <ImportDecisionMakerInfo>(), It.IsAny <ImportDecisionMakerConfig>()))
            .Returns(new List <ImportDecision <LocalBook> > {
                new ImportDecision <LocalBook>(localTrack, new Rejection("Reject"))
            });

            Subject.Scan(new List <string> {
                _artist.Path
            });

            Mocker.GetMock <IMediaFileService>()
            .Verify(x => x.Update(It.Is <List <BookFile> >(
                                      l => l.Count == 1 &&
                                      l[0].Path == localTrack.Path &&
                                      l[0].Modified == localTrack.Modified &&
                                      l[0].Size == localTrack.Size &&
                                      l[0].Quality.Equals(localTrack.Quality) &&
                                      l[0].MediaInfo.AudioFormat == localTrack.FileTrackInfo.MediaInfo.AudioFormat)),
                    Times.Once());
        }
예제 #16
0
        public override void DoHandleMedia(Media media, PostedMediaFile postedFile, BusinessLogic.User user)
        {
            // Get Image object, width and height
            var image      = System.Drawing.Image.FromStream(postedFile.InputStream);
            var fileWidth  = image.Width;
            var fileHeight = image.Height;

            // Get umbracoFile property
            var propertyId = media.getProperty("umbracoFile").Id;

            // Get paths
            var destFilePath = FileSystem.GetRelativePath(propertyId, postedFile.FileName);
            var ext          = Path.GetExtension(destFilePath).Substring(1);

            // Set media properties
            media.getProperty("umbracoFile").Value   = FileSystem.GetUrl(destFilePath);
            media.getProperty("umbracoWidth").Value  = fileWidth;
            media.getProperty("umbracoHeight").Value = fileHeight;
            media.getProperty("umbracoBytes").Value  = postedFile.ContentLength;

            if (media.getProperty("umbracoExtension") != null)
            {
                media.getProperty("umbracoExtension").Value = ext;
            }

            if (media.getProperty("umbracoExtensio") != null)
            {
                media.getProperty("umbracoExtensio").Value = ext;
            }

            // Generate thumbnail
            var thumbDestFilePath = Path.Combine(Path.GetDirectoryName(destFilePath), Path.GetFileNameWithoutExtension(destFilePath) + "_thumb");

            GenerateThumbnail(image, 100, fileWidth, fileHeight, ext, thumbDestFilePath + ".jpg");

            // Generate additional thumbnails based on PreValues set in DataTypeDefinition uploadField
            GenerateAdditionalThumbnails(image, fileWidth, fileHeight, ext, thumbDestFilePath);

            image.Dispose();

            FileSystem.AddFile(destFilePath, postedFile.InputStream, postedFile.ReplaceExisting);

            // Save media
            media.Save();
        }
예제 #17
0
        public void ThenCanResolveAsSingletonWhenTestResultsAreMsTest()
        {
            FileSystem.AddFile("results-example-mstest.trx", RetrieveContentOfFileFromResources(TestResultsResourcePrefix + "MsTest.results-example-mstest.trx"));

            var configuration = Container.Resolve <IConfiguration>();

            configuration.TestResultsFormat = TestResultsFormat.MsTest;
            configuration.AddTestResultFiles(new[] { FileSystem.FileInfo.FromFileName("results-example-mstest.trx") });

            var item1 = Container.Resolve <ITestResults>();
            var item2 = Container.Resolve <ITestResults>();

            Check.That(item1).IsNotNull();
            Check.That(item1).IsInstanceOf <MsTestResults>();
            Check.That(item2).IsNotNull();
            Check.That(item2).IsInstanceOf <MsTestResults>();
            Check.That(item1).IsSameReferenceAs(item2);
        }
예제 #18
0
        public void ThenCanResolveAsSingletonWhenTestResultsArexUnit()
        {
            FileSystem.AddFile("results-example-xunit.xml", RetrieveContentOfFileFromResources(TestResultsResourcePrefix + "results-example-xunit.xml"));

            var configuration = Container.Resolve <Configuration>();

            configuration.TestResultsFormat = TestResultsFormat.xUnit;
            configuration.AddTestResultFile(FileSystem.FileInfo.FromFileName("results-example-xunit.xml"));

            var item1 = Container.Resolve <ITestResults>();
            var item2 = Container.Resolve <ITestResults>();

            Check.That(item1).IsNotNull();
            Check.That(item1).IsInstanceOf <XUnitResults>();
            Check.That(item2).IsNotNull();
            Check.That(item2).IsInstanceOf <XUnitResults>();
            Check.That(item1).IsSameReferenceThan(item2);
        }
예제 #19
0
        public void CanRenameJsonFile()
        {
            string oldfilePath = @"d:\output\pickledFeatures.json";
            string newFilePath = @"d:\output\pickledFeatures.js";

            FileSystem.AddFile(oldfilePath, "test data");

            var jsonTweaker = new JsonTweaker(FileSystem);

            jsonTweaker.RenameFileTo(oldfilePath, newFilePath);

            var doesNewPathExist = FileSystem.File.Exists(newFilePath);

            Check.That(doesNewPathExist).IsTrue();
            var doesOldPathExist = FileSystem.File.Exists(oldfilePath);

            Check.That(doesOldPathExist).IsFalse();
        }
예제 #20
0
        public void ThenCanResolveAsSingletonWhenTestResultsAreCucumberJson()
        {
            FileSystem.AddFile("results-example-json.json", RetrieveContentOfFileFromResources(TestResultsResourcePrefix + "CucumberJson.results-example-json.json"));

            var configuration = Container.Resolve <IConfiguration>();

            configuration.TestResultsFormat = TestResultsFormat.CucumberJson;
            configuration.AddTestResultFile(FileSystem.FileInfo.FromFileName("results-example-json.json"));

            var item1 = Container.Resolve <ITestResults>();
            var item2 = Container.Resolve <ITestResults>();

            Check.That(item1).IsNotNull();
            Check.That(item1).IsInstanceOf <CucumberJsonResults>();
            Check.That(item2).IsNotNull();
            Check.That(item2).IsInstanceOf <CucumberJsonResults>();
            Check.That(item1).IsSameReferenceAs(item2);
        }
예제 #21
0
        public void ThenCanResolveAsSingletonWhenTestResultsAreCucumberJson()
        {
            FileSystem.AddFile("results-example-json.json", RetrieveContentOfFileFromResources(TestResultsResourcePrefix + "results-example-json.json"));

            var configuration = Container.Resolve <Configuration>();

            configuration.TestResultsFormat = TestResultsFormat.CucumberJson;
            configuration.TestResultsFiles  = new[] { FileSystem.FileInfo.FromFileName("results-example-json.json") };

            var item1 = Container.Resolve <ITestResults>();
            var item2 = Container.Resolve <ITestResults>();

            item1.ShouldNotBeNull();
            item1.ShouldBeType <CucumberJsonResults>();
            item2.ShouldNotBeNull();
            item2.ShouldBeType <CucumberJsonResults>();
            item1.ShouldBeSameAs(item2);
        }
예제 #22
0
        public override void When()
        {
            FileSystem.AddFile(@"C:\website\_layouts\default.cshtml", new MockFileData(TemplateContents));
            FileSystem.AddFile(@"C:\website\index.cshtml", new MockFileData(PageContents));
            var context = new SiteContext {
                SourceFolder = @"C:\website\", Title = "My Web Site"
            };
            var dictionary = new Dictionary <string, object>
            {
                { "layout", "default" }
            };

            context.Posts.Add(new Page {
                File = "index.cshtml", Content = PageContents, OutputFile = @"C:\website\_site\index.html", Bag = dictionary
            });
            Subject.FileSystem = FileSystem;
            Subject.Process(context);
        }
예제 #23
0
        private List <IFileInfo> GivenFiles(IEnumerable <string> files, DateTimeOffset?lastWrite = null)
        {
            if (lastWrite == null)
            {
                TestLogger.Debug("Using default lastWrite");
                lastWrite = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            }

            foreach (var file in files)
            {
                FileSystem.AddFile(file, new MockFileData(string.Empty)
                {
                    LastWriteTime = lastWrite.Value
                });
            }

            return(files.Select(x => DiskProvider.GetFileInfo(x)).ToList());
        }
예제 #24
0
        public void ThenCanResolveWhenTestResultsAreSpecrun()
        {
            const string resultsFilename = "results-example-specrun.html";

            using (var input = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("PicklesDoc.Pickles.Test." + resultsFilename)))
            {
                FileSystem.AddFile(resultsFilename, new MockFileData(input.ReadToEnd()));
            }

            var configuration = Container.Resolve <Configuration>();

            configuration.TestResultsFormat = TestResultsFormat.SpecRun;
            configuration.TestResultsFiles  = new[] { FileSystem.FileInfo.FromFileName(resultsFilename) };

            var item = Container.Resolve <ITestResults>();

            Assert.NotNull(item);
            Assert.IsInstanceOf <SpecRunResults>(item);
        }
예제 #25
0
        public void RemoveObsoleteLocks_Should_Remove_Old_User_Lock()
        {
            // create valid lock that shouldn't get removed
            var validLock = $"{TestFileName}.{Guid.NewGuid()}.launchlock";

            FileSystem.AddFile(validLock, new Mocks().GetLaunchLockJson(validLock));

            // create old lock that should be removed
            var invalidLock = $"{TestFileName}.{Guid.NewGuid()}.launchlock";

            FileSystem.AddFile(invalidLock, new Mocks().GetLaunchLockJson(validLock, true));

            GetCurrentLauchLocks();

            Unlocker.RemoveObsoleteLocks();

            LockFinder.DoesLockExist();

            GetCurrentLauchLocks().Count().Should().Be(1);
        }
        public void Execute_Should_Launch_File_When_Only_User_Lock_Present()
        {
            FileSystem.AddFile(TestFileName, new Bogus.Faker().Lorem.Paragraphs(3));

            var launchLock = new Library.LaunchLock()
            {
                IsValid  = true,
                FileName = $"{TestFileName}.{Guid.NewGuid()}.launchlock",
                Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name,
                LockTime = DateTime.Now
            };

            var launchLockJson = JsonOperations.Serialize(launchLock);

            FileSystem.AddFile(launchLock.FileName, launchLockJson);

            LaunchLockProcess.Execute(new string[] { TestFileName });

            Communicator.Messages.Should().Contain("Launching file.");
        }
예제 #27
0
        static void Main(System.String[] args)
        {
            var fs = new FileSystem(
                bytesPerSector: 512,
                sectorsPerCluster: 1,
                reservedSectors: 1,
                numberOfFATs: 2,
                sectorsPerRootDirectory: 1,
                totalSectors: 16 * 1024 * 1024 / 512,
                sectorsPerFat: 128,
                hiddenSectors: 0,
                volumeSerialNumber: Convert.ToUInt32(DateTime.Now.Subtract(new DateTime(2000, 1, 1)).TotalSeconds),
                volumeLabel: "MYDEVICE");

            fs.AddFile(@"r:\DOCUMENT.PDF");

            using (var stream = new FileStream(@"R:\image-fat16.img", FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) {
                var array = fs.GetBytes().ToArray();
                stream.Write(array, 0, array.Length);
            }
        }
예제 #28
0
        public override void AddPackage(IPackage package)
        {
            // If we exceed the package count then clear the cache.
            var files = GetPackageFiles().ToList();

            if (files.Count >= MaxPackages)
            {
                // It's expensive to hit the file system to get the last accessed date for files
                // To reduce this cost from occuring frequently, we'll purge packages in batches allowing for a 20% buffer.
                var filesToDelete = files.OrderBy(FileSystem.GetLastAccessed)
                                    .Take(files.Count - (int)(0.8 * MaxPackages))
                                    .ToList();
                TryClear(filesToDelete);
            }

            string path = GetPackageFilePath(package);

            using (var stream = package.GetStream())
            {
                TryAct(() => FileSystem.AddFile(path, stream));
            }
        }
예제 #29
0
        public override void AddPackage(IPackage package)
        {
            string fileName = PathResolver.GetPackageFileName(package);

            if (FileSystem.FileExists(fileName) && !AllowOverrideExistingPackageOnPush)
            {
                throw new InvalidOperationException(String.Format(NuGetResources.Error_PackageAlreadyExists, package));
            }

            _cacheLock.EnterWriteLock();
            try
            {
                _derivedDataLookup.Remove(package);
            }
            finally
            {
                _cacheLock.ExitWriteLock();
            }

            using (Stream stream = package.GetStream())
            {
                FileSystem.AddFile(fileName, stream);
            }
        }
 public void SetFileContent(string filepath, Stream content)
 {
     FileSystem.AddFile(filepath, content, true);
 }