예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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());
        }
예제 #10
0
        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();
        }
예제 #11
0
        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());
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
        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);
        }