Skip to content

Commit b3441c9

Browse files
committed
Added Test for XmlFileWriter
1 parent 18dbb62 commit b3441c9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using FluentAssertions;
5+
using LinkDotNet.Blog.Web.Shared.Services;
6+
using Xunit;
7+
8+
namespace LinkDotNet.Blog.UnitTests.Web.Shared.Services
9+
{
10+
public sealed class XmlFileWriterTests : IDisposable
11+
{
12+
private const string OutputFilename = "somefile.txt";
13+
14+
[Fact]
15+
public async Task ShouldWriteToFile()
16+
{
17+
var myObj = new MyObject { Property = "Prop" };
18+
19+
await new XmlFileWriter().WriteObjectToXmlFileAsync(myObj, OutputFilename);
20+
21+
var content = await File.ReadAllTextAsync(OutputFilename);
22+
content.Should().NotBeNull();
23+
content.Should().Contain("<MyObject");
24+
content.Should().Contain("<Property>Prop</Property>");
25+
}
26+
27+
public void Dispose()
28+
{
29+
if (File.Exists(OutputFilename))
30+
{
31+
File.Delete(OutputFilename);
32+
}
33+
}
34+
35+
public class MyObject
36+
{
37+
public string Property { get; set; }
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)