Beispiel #1
0
        private async Task <Site> Load(string sitePath, string outputPath, IEnumerable <string> renderedExtensions)
        {
            Site site;

            SiteConfig config;

            using (var capture = Statistics.Current.Start(StatisticTiming.LoadedConfiguration))
            {
                var command = new LoadSiteConfigCommand();
                command.ConfigPath = Path.Combine(sitePath, "site.config");
                command.OutputPath = outputPath;
                config             = await command.ExecuteAsync();
            }

            using (var capture = Statistics.Current.Start(StatisticTiming.LoadedSite))
            {
                // Load documents.
                IEnumerable <DocumentFile> documents;
                {
                    var load = new LoadDocumentsCommand();
                    load.Author             = config.Author;
                    load.OutputRootPath     = config.OutputPath;
                    load.RenderedExtensions = renderedExtensions;
                    load.DocumentsPath      = config.DocumentsPath;
                    load.RootUrl            = config.RootUrl;
                    load.ApplicationUrl     = config.Url;
                    documents = await load.ExecuteAsync();
                }

                // Load files.
                IEnumerable <StaticFile> files;
                {
                    var load = new LoadFilesCommand();
                    load.OutputPath = config.OutputPath;
                    load.FilesPath  = config.FilesPath;
                    load.RootUrl    = config.RootUrl;
                    load.Url        = config.Url;
                    files           = load.Execute();
                }

                // Load layouts.
                IEnumerable <LayoutFile> layouts;
                {
                    var load = new LoadLayoutsCommand();
                    load.LayoutsPath = config.LayoutsPath;
                    layouts          = await load.ExecuteAsync();
                }

                site = new Site(config, documents, files, layouts);
            }

            Statistics.Current.SiteFiles = site.Documents.Count + site.Files.Count + site.Layouts.Count;

            return(site);
        }
Beispiel #2
0
        public void Handle_GivenInvalidPostId_ThrowsException()
        {
            var command = new LoadFilesCommand
            {
                PostId = 1009,
                Files  = CreateDefaultFormFiles()
            };

            var handler = GetNewHandler();

            Assert.ThrowsAsync <ValidationException>(async() =>
                                                     await handler.Handle(command, CancellationToken.None));
        }
Beispiel #3
0
        public async Task Handle_ShouldBeLoadFiles()
        {
            var command = new LoadFilesCommand
            {
                PostId = DefaultPostId,
                Files  = CreateDefaultFormFiles()
            };

            var handler = GetNewHandler();

            var result = await handler.Handle(command, CancellationToken.None);

            Assert.That(result.Files, IsNotNullOrEmpty);
            result.Files.ForEach(f =>
            {
                Assert.That(f.Id > 0);
                Assert.That(DateTimeService.NowUtc > f.LoadedUtc);
                Assert.That(f.Name, IsNotNullOrEmpty);
            });
            Assert.That(Context.PostFiles
                        .Count(f => f.PostId == command.PostId) >= command.Files.Count);
        }
        public void IsValid_GivenInvalidPhotos_ShouldHaveValidationError()
        {
            var validator = GetNewValidator();

            var files   = CreateDefaultFormFiles();
            var command = new LoadFilesCommand {
                Files = files
            };

            var longString = Guid.NewGuid().ToString();

            for (var i = 0; i < 10; i++)
            {
                longString += Guid.NewGuid().ToString();
            }

            files[0].Length.Returns(20000000);
            files[1].FileName.Returns(longString);

            var result = validator.TestValidate(command);

            result.ShouldHaveValidationErrorFor("Files[0]");
            result.ShouldHaveValidationErrorFor("Files[1]");
        }
Beispiel #5
0
 public async Task <ActionResult <LoadFilesResponseDto> > LoadFiles(
     [FromForm] LoadFilesCommand command)
 {
     return(await Mediator.Send(command));
 }