Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/Spark.Tests/Spool/SpoolWriterTester.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2008-2009 Louis DeJardin - http://whereslou.com
// Copyright 2008-2009 Louis DeJardin - http://whereslou.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ public void Init()
GC.WaitForPendingFinalizers();
_cache.Clear();
}

[Test]
public void ToStringCombinesResults()
{
Expand Down Expand Up @@ -211,12 +211,28 @@ public void DisposingWriter()
Assert.AreEqual(1, countBetween);
Assert.AreEqual(1, countAfter);
}

[Test]
public void EncodingShouldBeUtf8ByDefault()
{
var writer = new SpoolWriter();
Assert.AreEqual(65001, writer.Encoding.CodePage);

Assert.Throws<NotSupportedException>(
() =>
{
var encoding = writer.Encoding;
});
}

[Test]
public void ToStringWhenCodingIsDifferentFromUtf8()
{
TextWriter writer = new SpoolWriter();

// The accentuated char and unicode emoji shouldn't matter as the SpoolPage just keeps track of the bytes
writer.Write("hèllo 🌍");

Assert.AreEqual("hèllo 🌍", writer.ToString());
}
}
}
21 changes: 5 additions & 16 deletions src/Spark/Spool/SpoolWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Configuration;

namespace Spark.Spool
{
public class SpoolWriter : TextWriter, IEnumerable<string>
{
private readonly SpoolPage _first;
private SpoolPage _last;
private Encoding _encoding;

public SpoolWriter()
{
_first = new SpoolPage();
Expand All @@ -39,19 +37,10 @@ public SpoolWriter()
Dispose(false);
}

public override Encoding Encoding
{
get
{
if(_encoding == null)
{
var configSection = ConfigurationManager.GetSection("system.web/globalization") as GlobalizationSection;
_encoding = configSection != null ? configSection.ResponseEncoding : Encoding.UTF8;
}

return _encoding;
}
}
/// <summary>
/// Writing is delegated to <see cref="SpoolPage"/>. SpoolPage itself it just a buffer of bytes. Encoding does not matter.
/// </summary>
public override Encoding Encoding => throw new NotSupportedException("The spool writer is encoding agnostic");

public override void Write(char value)
{
Expand Down