コード例 #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);
        }