internal static void DisplayCredits() { Console.Write(ProgramAssemblyUtility.GetAssemblyInfo(Assembly.GetExecutingAssembly(), true)); Console.WriteLine(string.Empty); Console.WriteLine("Activities Assembly:"); Console.Write(ProgramAssemblyUtility.GetAssemblyInfo(typeof(PublicationsActivitiesGetter).Assembly, true)); }
public void GetCompressed11tyIndexArgs_Test(string settingsFile, string presentationRoot) { presentationRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, presentationRoot); var args = new ProgramArgs(new[] { ProgramArgs.SettingsFile, settingsFile, ProgramArgs.BasePath, presentationRoot }); var(presentationInfo, settingsInfo) = args.ToPresentationAndSettingsInfo(); Assert.True(presentationInfo.Exists); Assert.True(settingsInfo.Exists); var jO = JObject.Parse(File.ReadAllText(settingsInfo.FullName)); var(entryRootInfo, indexRootInfo, indexFileName) = jO.GetCompressed11tyIndexArgs(presentationInfo); Assert.True(entryRootInfo.Exists); Assert.True(indexRootInfo.Exists); Assert.False(string.IsNullOrWhiteSpace(indexFileName)); indexRootInfo.FindFile(indexFileName); var commandName = jO.GetPublicationCommand(); Assert.Equal(nameof(SearchIndexActivity.GenerateCompressed11tySearchIndex), commandName); }
public void GetExpandUrisArgs_Test(string settingsFile, string presentationRoot) { presentationRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, presentationRoot); var args = new ProgramArgs(new[] { ProgramArgs.SettingsFile, settingsFile, ProgramArgs.BasePath, presentationRoot }); var(presentationInfo, settingsInfo) = args.ToPresentationAndSettingsInfo(); Assert.True(presentationInfo.Exists); Assert.True(settingsInfo.Exists); var jO = JObject.Parse(File.ReadAllText(settingsInfo.FullName)); var(entryPath, collapsedHost) = jO.GetExpandUrisArgs(presentationInfo); Assert.True(File.Exists(entryPath)); Assert.False(string.IsNullOrEmpty(collapsedHost)); var commandName = jO.GetPublicationCommand(); Assert.Equal(nameof(MarkdownEntryActivity.ExpandUris), commandName); }
public void GetFindChangeArgs_Test(string settingsFile, string presentationRoot) { presentationRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, presentationRoot); var args = new ProgramArgs(new[] { ProgramArgs.SettingsFile, settingsFile, ProgramArgs.BasePath, presentationRoot }); var(presentationInfo, settingsInfo) = args.ToPresentationAndSettingsInfo(); Assert.True(presentationInfo.Exists); Assert.True(settingsInfo.Exists); var jO = JObject.Parse(File.ReadAllText(settingsInfo.FullName)); var(input, pattern, replacement, useRegex, outputPath) = jO.GetFindChangeArgs(presentationInfo); Assert.False(string.IsNullOrEmpty(input)); Assert.False(string.IsNullOrEmpty(pattern)); Assert.False(string.IsNullOrEmpty(replacement)); Assert.True(useRegex); Assert.False(string.IsNullOrEmpty(outputPath)); var inputPath = jO.GetValue <string>("inputPath"); this._testOutputHelper.WriteLine($"{nameof(inputPath)}: {inputPath}"); this._testOutputHelper.WriteLine($"{nameof(input)}: {input.Substring(0, 16)}..."); this._testOutputHelper.WriteLine($"{nameof(pattern)}: {pattern}"); this._testOutputHelper.WriteLine($"{nameof(replacement)}: {replacement}"); this._testOutputHelper.WriteLine($"{nameof(useRegex)}: {useRegex}"); this._testOutputHelper.WriteLine($"{nameof(outputPath)}: {outputPath}"); }
public ContactsControllerTests(ITestOutputHelper helper) { this.testOutputHelper = helper; var basePath = "../../../Songhay.ContentNegotiation"; basePath = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, basePath); builder = Program.CreateHostBuilder(args: null); Assert.NotNull(builder); builder .ConfigureWebHost(hostBuilder => { hostBuilder.UseTestServer(); }) .ConfigureAppConfiguration((builderContext, configBuilder) => { Assert.NotNull(builderContext); var env = builderContext.HostingEnvironment; Assert.NotNull(env); env.ContentRootPath = $"{basePath}{Path.DirectorySeparatorChar}wwwroot"; env.EnvironmentName = "Development"; }); }
public void GetAddEntryExtractArg_Test(string settingsFile, string presentationRoot) { presentationRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, presentationRoot); var args = new ProgramArgs(new[] { ProgramArgs.SettingsFile, settingsFile, ProgramArgs.BasePath, presentationRoot }); var(presentationInfo, settingsInfo) = args.ToPresentationAndSettingsInfo(); Assert.True(presentationInfo.Exists); Assert.True(settingsInfo.Exists); var jO = JObject.Parse(File.ReadAllText(settingsInfo.FullName)); var entryPath = jO.GetAddEntryExtractArg(presentationInfo); Assert.True(File.Exists(entryPath)); var commandName = jO.GetPublicationCommand(); Assert.Equal(nameof(MarkdownEntryActivity.AddEntryExtract), commandName); }
public void GenerateEntryFor11ty_Test(string entryRoot, string title) { entryRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, entryRoot); var entry = MarkdownEntryUtility.GenerateEntryFor11ty(entryRoot, title); Assert.NotNull(entry); Assert.True(File.Exists(ProgramFileUtility.GetCombinedPath(entryRoot, $"{entry.FrontMatter.GetValue<string>("clientId")}.md"))); }
public void PublishEntryFor11ty_Test(string entryRoot, string presentationRoot, string fileName) { entryRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, entryRoot); presentationRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, presentationRoot); var path = MarkdownEntryUtility.PublishEntryFor11ty(entryRoot, presentationRoot, fileName); Assert.True(File.Exists(path)); }
public void CompressSearchIndex_Test(string indexFile) { indexFile = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, indexFile); var indexFileInfo = new FileInfo(indexFile); Assert.True(indexFileInfo.Exists); var compressedIndexFileInfo = SearchIndexActivity.CompressSearchIndex(indexFileInfo); Assert.True(compressedIndexFileInfo?.Exists); }
public void ShouldEditEntryDates(string entryRoot) { entryRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, entryRoot); this._testOutputHelper.WriteLine($"loading entries from `{entryRoot}`"); var entriesRootInfo = new DirectoryInfo(entryRoot); foreach (var entryInfo in entriesRootInfo.GetFiles("*.md")) { this._testOutputHelper.WriteLine($"reading `{entryInfo.Name}`..."); var lines = File.ReadLines(entryInfo.FullName); var mdFrontMatterLines = lines.TakeWhile(i => !i.EqualsInvariant("---")); var frontMatterJson = mdFrontMatterLines .Where(i => !i.Contains("---json")) .Aggregate((a, i) => $"{a}{i}") .Trim(); var jO = JObject.Parse(frontMatterJson); string getUtcDate(string propertyName) { var date = jO[propertyName]?.Value <DateTime>(); Assert.NotNull(date); var utcDate = date.Value .ToUniversalTime() .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"); return(utcDate); } new [] { "date", "modificationDate" }.ForEachInEnumerable(i => jO[i] = getUtcDate(i)); frontMatterJson = jO.ToString(); var frontMatter = $@"---json{Environment.NewLine}{frontMatterJson}{Environment.NewLine}---"; this._testOutputHelper.WriteLine($"{nameof(frontMatter)}:{Environment.NewLine}{frontMatter}"); var builder = new StringBuilder(); builder.AppendLine(frontMatter); builder.AppendLine(lines .SkipWhile(i => !i.EqualsInvariant("---")) .Skip(1) .Aggregate((a, i) => $"{a}{Environment.NewLine}{i}")); File.WriteAllText(entryInfo.FullName, builder.ToString()); } }
public void ShouldGetStarted(string databaseFile) { var projectFolder = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, "../../../"); var projectFolderInfo = new DirectoryInfo(projectFolder); Assert.True(projectFolderInfo.Exists); // Open database (or create if doesn't exist) using var db = new LiteDatabase(projectFolderInfo.ToCombinedPath(databaseFile)); // Get a collection (or create, if doesn't exist) var col = db.GetCollection <Customer>("customers"); // Create your new customer instance var customer = new Customer { Name = "John Doe", Phones = new string[] { "8000-0000", "9000-0000" }, IsActive = true }; // Insert new customer document (Id will be auto-incremented) col.Insert(customer); // Update a document inside a collection customer.Name = "Jane Doe"; col.Update(customer); // Index document using document Name property col.EnsureIndex(x => x.Name); // Use LINQ to query documents (filter, sort, transform) var results = col.Query() .Where(x => x.Name.StartsWith("J")) .OrderBy(x => x.Name) .Select(x => new { x.Name, NameUpper = x.Name.ToUpper() }) .Limit(10) .ToList(); // Let's create an index in phone numbers (using expression). It's a multikey index col.EnsureIndex(x => x.Phones); // and now we can query phones var r = col.FindOne(x => x.Phones.Contains("8888-5555")); Assert.Null(r); }
public void GenerateSearchIndexFrom11tyEntries_Test(string entryRoot, string indexRoot, string indexFileName) { entryRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, entryRoot); indexRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, indexRoot); var entryRootInfo = new DirectoryInfo(entryRoot); Assert.True(entryRootInfo.Exists); var indexRootInfo = new DirectoryInfo(indexRoot); Assert.True(indexRootInfo.Exists); var indices = SearchIndexActivity.GenerateSearchIndexFrom11tyEntries(entryRootInfo, indexRootInfo, indexFileName); Assert.True(indices?.Any()); }
public void ShouldSortGroupsByInceptDate(string groupRoot) { groupRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, groupRoot); this._testOutputHelper.WriteLine($"loading entries from `{groupRoot}`"); var groupRootInfo = new DirectoryInfo(groupRoot); foreach (var groupInfo in groupRootInfo.GetFiles("*.json")) { var jO = JObject.Parse(File.ReadAllText(groupInfo.FullName)); var jA = jO["Documents"]?.Value <JArray>(); Assert.NotNull(jA); Assert.True(jA.Any()); jO["Documents"] = JArray.FromObject(jA.OrderByDescending(i => i["CreateDate"].Value <DateTime>())); File.WriteAllText(groupInfo.FullName, jO.ToString()); } }
public async Task CreateHostBuilder_Test(string basePath, string testResponse) { basePath = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, basePath); var builder = Program.CreateHostBuilder(args: null); Assert.NotNull(builder); builder .ConfigureWebHost(hostBuilder => { hostBuilder.UseTestServer(); hostBuilder.Configure(appBuilder => appBuilder.Run(async ctx => await ctx.Response.WriteAsync(testResponse))); }) .ConfigureAppConfiguration((builderContext, configBuilder) => { Assert.NotNull(builderContext); var env = builderContext.HostingEnvironment; Assert.NotNull(env); env.ContentRootPath = $"{basePath}{Path.DirectorySeparatorChar}wwwroot"; env.EnvironmentName = "Development"; }); var host = await builder.StartAsync(); var client = host.GetTestClient(); var response = await client.GetAsync("/"); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); Assert.Equal(testResponse, responseString); }
public void ShouldLoadEntries(string entriesRoot, string postsRoot) { entriesRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, entriesRoot); this._testOutputHelper.WriteLine($"loading entries from `{entriesRoot}`"); postsRoot = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, postsRoot); this._testOutputHelper.WriteLine($"writing entries to `{postsRoot}`"); var entriesRootInfo = new DirectoryInfo(entriesRoot); foreach (var entryInfo in entriesRootInfo.GetFiles("*.json")) { this._testOutputHelper.WriteLine($"reading {entryInfo.Name}..."); var jsonString = GetJsonString(File.ReadAllText(entryInfo.FullName)); var jO = JObject.Parse(jsonString); var md = GetMarkdown(jO); var mdPath = ProgramFileUtility.GetCombinedPath(postsRoot, entryInfo.Name.Replace(".json", ".md")); this._testOutputHelper.WriteLine($"writing `{mdPath}`..."); File.WriteAllText(mdPath, md); } }
public ActivitiesTests(ITestOutputHelper helper) { this._testOutputHelper = helper; this._projectPath = ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, "../../../"); }
string GetBasePath(string relativePath) => ProgramAssemblyUtility.GetPathFromAssembly(this.GetType().Assembly, relativePath);