Skip to content

Commit

Permalink
Merge pull request #75 from ernado-x/net8
Browse files Browse the repository at this point in the history
Add support for .NET 8
  • Loading branch information
ernado-x authored Jan 15, 2024
2 parents f626a82 + 685342d commit b1c0a21
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 226 deletions.
5 changes: 4 additions & 1 deletion src/X.Web.Sitemap.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using X.Web.Sitemap.Example;
using X.Web.Sitemap;
using X.Web.Sitemap.Example;
using X.Web.Sitemap.Example.Examples;

Console.WriteLine("OK");

Sitemap.DefaultMaxNumberOfUrlsPerSitemap = 50000;

IExample example1 = new SitemapGenerationWithSitemapIndexExample();
example1.Run();

Expand Down
2 changes: 1 addition & 1 deletion src/X.Web.Sitemap.Example/X.Web.Sitemap.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/X.Web.Sitemap/Sitemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace X.Web.Sitemap;
[XmlRoot(ElementName = "urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public class Sitemap : List<Url>, ISitemap
{
public static int DefaultMaxNumberOfUrlsPerSitemap = 50000;
public static int DefaultMaxNumberOfUrlsPerSitemap { get; set; } = 5000;

public Sitemap()
{
Expand Down
10 changes: 5 additions & 5 deletions src/X.Web.Sitemap/X.Web.Sitemap.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.9.2</Version>
<Version>2.9.3</Version>
<Description>This library allows you quickly and easily generate sitemap files.</Description>
<Copyright>Andrew Gubskiy</Copyright>
<PackageProjectUrl>https://github.com/ernado-x/X.Web.Sitemap</PackageProjectUrl>
Expand All @@ -12,13 +12,13 @@
<PackageId>xsitemap</PackageId>
<Authors>Andrew Gubskiy</Authors>
<PackageTags>sitemap, web, asp.net, sitemap.xml</PackageTags>
<PackageVersion>2.9.2</PackageVersion>
<PackageVersion>2.9.3</PackageVersion>
<Title>X.Sitemap</Title>
<AssemblyVersion>2.9.2.0</AssemblyVersion>
<FileVersion>2.9.2.0</FileVersion>
<AssemblyVersion>2.9.3.0</AssemblyVersion>
<FileVersion>2.9.3.0</FileVersion>
<LangVersion>default</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;net7.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Xunit;

namespace X.Web.Sitemap.Tests.IntegrationTests.SitemapGeneratorIntegrationTests;

[TestFixture]
public class GenerateSitemapsIntegrationTests
public class GenerateSitemapsIntegrationTests : IDisposable
{
private SitemapGenerator _sitemapGenerator;
private readonly string _sitemapLocation = Path.GetTempPath();

[SetUp]
public void SetUp()
public GenerateSitemapsIntegrationTests()
{
_sitemapGenerator = new SitemapGenerator();
}

[Test]
public void Dispose()
{
// Cleanup code if needed
}

[Fact]
public void It_Only_Saves_One_Sitemap_If_There_Are_Less_Than_50001_Urls()
{
//--arrange
var maxNumberOfUrlsForOneSitemap = Sitemap.DefaultMaxNumberOfUrlsPerSitemap;
var urls = new List<Url>(maxNumberOfUrlsForOneSitemap);
var now = DateTime.UtcNow;

for (var i = 0; i < maxNumberOfUrlsForOneSitemap; i++)
{
urls.Add(Url.CreateUrl("https://example.com/" + i, now));
Expand All @@ -37,14 +37,14 @@ public void It_Only_Saves_One_Sitemap_If_There_Are_Less_Than_50001_Urls()
//--go look in the {sitemapLocation} directory!
}

[Test]
[Fact]
public void It_Saves_Two_Sitemaps_If_There_Are_More_Than_50000_Urls_But_Less_Than_100001_And_It_Names_The_Files_With_A_Three_Digit_Suffix_Incrementing_For_Each_One()
{
//--arrange
var enoughUrlsForTwoSitemaps = Sitemap.DefaultMaxNumberOfUrlsPerSitemap + 1;
var urls = new List<Url>(enoughUrlsForTwoSitemaps);
var now = DateTime.UtcNow;

for (var i = 0; i < enoughUrlsForTwoSitemaps; i++)
{
urls.Add(Url.CreateUrl("https://example.com/" + i, now));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Xunit;

namespace X.Web.Sitemap.Tests.IntegrationTests.SitemapIndexGeneratorIntegrationTests;

[TestFixture]
public class GenerateSitemapIndexIntegrationTests
public class GenerateSitemapIndexIntegrationTests : IDisposable
{
private SitemapIndexGenerator _sitemapIndexGenerator;
private readonly string _sitemapLocation = Path.GetTempPath();

[SetUp]
public void SetUp()
public GenerateSitemapIndexIntegrationTests()
{
_sitemapIndexGenerator = new SitemapIndexGenerator();
}

[Test]
public void Dispose()
{
// Cleanup code if needed
}

[Fact]
public void It_Saves_A_Generated_Sitemap_Index_File_From_The_Specified_Sitemaps()
{
//--arrange
Expand All @@ -26,7 +26,7 @@ public void It_Saves_A_Generated_Sitemap_Index_File_From_The_Specified_Sitemaps(
new SitemapInfo(new Uri("https://example.com"), DateTime.UtcNow),
new SitemapInfo(new Uri("https://example2.com"), DateTime.UtcNow.AddDays(-1))
};

var expectedDirectory = new DirectoryInfo(_sitemapLocation);
var expectedFilename = "testSitemapIndex1.xml";

Expand Down
5 changes: 1 addition & 4 deletions tests/X.Web.Sitemap.Tests/TestFileSystemWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.IO;
using System.Threading.Tasks;

namespace X.Web.Sitemap.Tests;
namespace X.Web.Sitemap.Tests;

public class TestFileSystemWrapper : IFileSystemWrapper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;

namespace X.Web.Sitemap.Tests.UnitTests.SerializedXmlSaver;

[TestFixture]
public class DeserializeTests
{
[Test]
public void Check_That_XmlFile_Deserialized()
{
var xml = File.ReadAllText("Data/example.xml");
var sitemap = Sitemap.Parse(xml);
Assert.NotNull(sitemap);
}
[Fact]
public void Check_That_XmlFile_Deserialized()
{
var xml = File.ReadAllText("Data/example.xml");
var sitemap = Sitemap.Parse(xml);

Assert.NotNull(sitemap);
}
}
Original file line number Diff line number Diff line change
@@ -1,67 +1,61 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using Xunit;

namespace X.Web.Sitemap.Tests.UnitTests.SerializedXmlSaver;

[TestFixture]
public class SerializeAndSaveTests
{
private IFileSystemWrapper _fileSystemWrapper;

[SetUp]
public void SetUp()
{
_fileSystemWrapper = new TestFileSystemWrapper();
}

//--this is a half-assed test as comparing the full XML string that is generated is a big pain.
[Test]
public void It_Saves_The_XML_File_To_The_Correct_Directory_And_File_Name()
{
//--arrange
var sitemapIndex = new SitemapIndex(new List<SitemapInfo>
{
new SitemapInfo(new Uri("http://example.com/sitemap1.xml"), DateTime.UtcNow),
new SitemapInfo(new Uri("http://example.com/sitemap2.xml"), DateTime.UtcNow.AddDays(-1))
});

var fileName = "sitemapindex.xml";
var directory = new DirectoryInfo("x");
var path = Path.Combine(directory.FullName, fileName);

var serializer = new SitemapIndexSerializer();
var xml = serializer.Serialize(sitemapIndex);

//--act
var result = _fileSystemWrapper.WriteFile(xml, path);

Assert.True(result.FullName.Contains("sitemapindex"));
Assert.AreEqual(directory.Name, result.Directory.Name);
Assert.AreEqual(fileName, result.Name);
}

[Test]
public void It_Returns_A_File_Info_For_The_File_That_Was_Created()
{
//--arrange
var expectedFileInfo = new FileInfo("something/file.xml");
var sitemapIndex = new SitemapIndex(new List<SitemapInfo>());

var serializer = new SitemapIndexSerializer();
var xml = serializer.Serialize(sitemapIndex);

var fileName = "file.xml";
var directory = new DirectoryInfo("something");
var path = Path.Combine(directory.FullName, fileName);

//--act
var result = _fileSystemWrapper.WriteFile(xml, path);

Assert.AreEqual(expectedFileInfo.FullName, result.FullName);
Assert.AreEqual(expectedFileInfo.Directory, result.Directory);
}

private IFileSystemWrapper _fileSystemWrapper;

public SerializeAndSaveTests()
{
_fileSystemWrapper = new TestFileSystemWrapper();
}

[Fact]
public void It_Saves_The_XML_File_To_The_Correct_Directory_And_File_Name()
{
//--arrange
var sitemapIndex = new SitemapIndex(new List<SitemapInfo>
{
new SitemapInfo(new Uri("http://example.com/sitemap1.xml"), DateTime.UtcNow),
new SitemapInfo(new Uri("http://example.com/sitemap2.xml"), DateTime.UtcNow.AddDays(-1))
});

var fileName = "sitemapindex.xml";
var directory = new DirectoryInfo("x");
var path = Path.Combine(directory.FullName, fileName);

var serializer = new SitemapIndexSerializer();
var xml = serializer.Serialize(sitemapIndex);

//--act
var result = _fileSystemWrapper.WriteFile(xml, path);

//--assert
Assert.True(result.FullName.Contains("sitemapindex"));
Assert.Equal(directory.Name, result.Directory.Name);
Assert.Equal(fileName, result.Name);
}

[Fact]
public void It_Returns_A_File_Info_For_The_File_That_Was_Created()
{
//--arrange
var expectedFileInfo = new FileInfo("something/file.xml");
var sitemapIndex = new SitemapIndex(new List<SitemapInfo>());

var serializer = new SitemapIndexSerializer();
var xml = serializer.Serialize(sitemapIndex);

var fileName = "file.xml";
var directory = new DirectoryInfo("something");
var path = Path.Combine(directory.FullName, fileName);

//--act
var result = _fileSystemWrapper.WriteFile(xml, path);

//--assert
Assert.Equal(expectedFileInfo.FullName, result.FullName);
Assert.Equal(expectedFileInfo.Directory.Name, result.Directory.Name);
}
}
Loading

0 comments on commit b1c0a21

Please sign in to comment.