public void ThrowWithTheProperSettingNameIfTitleIsNotSupplied() { String rootPath = $"c:\\{string.Empty.GetRandom()}\\"; var xml = new SettingsFileBuilder().UseRandomValues() .RemoveTitle().Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(xml.ToString()); Entities.SiteSettings actual; String expected = nameof(actual.Title); var target = (null as IContentRepository).Create(fileSystem.Object, rootPath); try { actual = target.GetSiteSettings(); Assert.False(true, "SettingNotFoundException not thrown"); } catch (SettingNotFoundException ex) { Assert.Equal(expected, ex.SettingName); } }
public void ReturnTheCorrectSiteVariable() { var siteVariables = (null as IEnumerable <SiteVariable>) .CreateRandom(1); var fileData = new SettingsFileBuilder() .UseRandomValues() .Variables(siteVariables) .RemoveTheme() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(fileData.ToString()); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); var expectedVariable = siteVariables.Single(); var actualVariable = actual.Variables.Single(); Assert.Equal(expectedVariable.Name, actualVariable.Name); Assert.Equal(expectedVariable.Value, actualVariable.Value); }
public void ReturnTheCorrectAdditionalFilePaths() { int expectedCount = 10.GetRandom(3); var expected = new List <String>(); for (int i = 0; i < expectedCount; i++) { expected.Add(string.Empty.GetRandom()); } var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .AdditionalFilePaths(expected) .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected.AsHash(), actual.AdditionalFilePaths.AsHash()); }
public void ReturnTheCorrectSiteVariableEvenIfItContainsAColon() { var siteVariableName = String.Empty.GetRandom(); var siteVariableValue = $"{string.Empty.GetRandom()}:{string.Empty.GetRandom()}"; var siteVariables = new List <SiteVariable>() { new SiteVariable() { Name = siteVariableName, Value = siteVariableValue } }; var fileData = new SettingsFileBuilder() .UseRandomValues() .Variables(siteVariables) .RemoveTheme() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(fileData.ToString()); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); var expectedVariable = siteVariables.Single(); var actualVariable = actual.Variables.Single(); Assert.Equal(expectedVariable.Name, actualVariable.Name); Assert.Equal(expectedVariable.Value, actualVariable.Value); }
public void ReturnAnEmptyStringIfThemeIsNotSupplied() { var xml = new SettingsFileBuilder().UseRandomValues() .RemoveTheme().Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(xml.ToString()); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(string.Empty, actual.Theme); }
public void ReturnTheDefaultValueIfPostsPerFeedIsNotSupplied() { var xml = new SettingsFileBuilder().UseRandomValues() .RemovePostsPerFeed().Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(xml); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(_defaultPostsPerFeed, actual.PostsPerFeed); }
public void ReturnAnEmptyStringIfDescriptionIsNotSupplied() { var xml = new SettingsFileBuilder().UseRandomValues() .RemoveDescription().Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(xml); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.True(string.IsNullOrWhiteSpace(actual.Description)); }
public void ReturnTheProperValueForTitle() { String expected = string.Empty.GetRandom(); String xml = new SettingsFileBuilder().UseRandomValues() .Title(expected).Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(xml); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.Title); }
public void ThrowSettingNotFoundExceptionIfTitleIsNotSupplied() { var xml = new SettingsFileBuilder() .UseRandomValues() .RemoveTitle() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(xml); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); Assert.Throws <SettingNotFoundException>(() => target.GetSiteSettings()); }
public void ReadTheProperFileFromTheFileSystem() { String rootPath = $"c:\\{string.Empty.GetRandom()}\\"; String expectedPath = System.IO.Path.Combine(rootPath, _dataFolder, "SiteSettings.md"); String fileContents = new SettingsFileBuilder().UseRandomValues().Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.Is <string>(p => p == expectedPath))) .Returns(fileContents).Verifiable(); var target = (null as IContentRepository).Create(fileSystem.Object, rootPath); var actual = target.GetSiteSettings(); fileSystem.VerifyAll(); }
public void ReturnAnEmptyListIfNoAdditionalFilePathsProvided() { var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .RemoveAdditionalFilePaths() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.False(actual.AdditionalFilePaths.Any()); }
public void ReturnTheProperValueForDisplayTitleInNavbar(bool expected) { var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .DisplayTitleInNavbar(expected) .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.DisplayTitleInNavbar); }
public void ReturnTheProperValueForDateFormatSpecifier() { String expected = $"yyyyMMdd {string.Empty.GetRandom(3)}"; var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .DateFormatSpecifier(expected) .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.DateFormatSpecifier); }
public void ReturnTheProperValueForAdditionalPagesDropdownLabel() { String expected = string.Empty.GetRandom(); var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .AdditionalPagesDropdownLabel(expected) .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.AdditionalPagesDropdownLabel); }
public void ReturnDefaultValueForDateTimeFormatSpecifierIfNoneSpecified() { string expected = "yyyy-MM-dd H:mm UTC"; var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .RemoveDateTimeFormatSpecifier() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.DateTimeFormatSpecifier); }
public void ReturnTheDefaultValueForUseAdditionalPagesDropdownIfNoneSpecified() { var expected = false; var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .RemoveUseAdditionalPagesDropdown() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.UseAdditionalPagesDropdown); }
public void ReturnTheDefaultValueForOutputFileExtensionIfNoneSpecified() { string expected = "html"; var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .RemoveOutputFileExtension() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.OutputFileExtension); }
public void ReturnAnEmptyValueForItemSeparatorIfNoneSpecified() { string expected = String.Empty; var settingsFileData = new SettingsFileBuilder() .UseRandomValues() .RemoveItemSeparator() .Build(); var fileSystem = new Mock <IFile>(); fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())) .Returns(settingsFileData); var target = (null as IContentRepository).Create(fileSystem.Object, "c:\\"); var actual = target.GetSiteSettings(); Assert.Equal(expected, actual.ItemSeparator); }