<commit_before>﻿using System.IO;
using System.Linq;
using System.Text;
using Dashen.Endpoints.Static;
using Dashen.Endpoints.Static.ContentProviders;
using Dashen.Infrastructure;
using Dashen.Initialisation;
using Shouldly;
using Xunit;

namespace Dashen.Tests
{
	public class DashenConfigurationTests
	{
		[Fact]
		public void EnableConsoleLog_adds_a_logger_to_the_handlers_if_one_is_not_present()
		{
			var config = new DashenConfiguration();

			config.EnableConsoleLog();

			config.MessageHandlers.Single().ShouldBeOfType<ConsoleLoggingHandler>();
		}

		[Fact]
		public void EnableConsoleLog_doesnt_add_a_logger_if_handlers_contains_a_console_logger_already()
		{
			var config = new DashenConfiguration();
			config.MessageHandlers.Add(new ConsoleLoggingHandler());

			config.EnableConsoleLog();

			config.MessageHandlers.Count.ShouldBe(1);
			config.MessageHandlers.Single().ShouldBeOfType<ConsoleLoggingHandler>();
		}

		[Fact]
		public void DisableConsoleLog_removes_the_logger_if_it_exists()
		{
			var config = new DashenConfiguration();
			config.MessageHandlers.Add(new ConsoleLoggingHandler());

			config.DisableConsoleLog();

			config.MessageHandlers.ShouldBeEmpty();
		}

		[Fact]
		public void DisableConsoleLog_does_nothing_if_there_is_no_logger_already()
		{
			var config = new DashenConfiguration();

			config.DisableConsoleLog();

			config.MessageHandlers.ShouldBeEmpty();
		}

		[Fact]
		public void AddResource_allows_the_content_stream_to_be_shut()
		{
			var config = new DashenConfiguration();

			using (var ms = new MemoryStream())
			using( var writer = new StreamWriter(ms))
			{
				writer.Write("Test value");
				writer.Flush();
				ms.Position = 0;

				config.AddResource("test", ms, "text/plain");
			}
			var adhoc = new AdhocContentProvider();
			var init = new StaticContentInitialisation(new ReplacementSource(), adhoc);
			init.ApplyTo(config, null);<commit_msg>tests: fix configuration ctor change<commit_after>﻿using System.IO;
using System.Linq;
using System.Text;
using Dashen.Endpoints.Static;
using Dashen.Endpoints.Static.ContentProviders;
using Dashen.Infrastructure;
using Dashen.Initialisation;
using Shouldly;
using Xunit;

namespace Dashen.Tests
{
	public class DashenConfigurationTests
	{
		[Fact]
		public void EnableConsoleLog_adds_a_logger_to_the_handlers_if_one_is_not_present()
		{
			var config = new DashenConfiguration();

			config.EnableConsoleLog();

			config.MessageHandlers.Single().ShouldBeOfType<ConsoleLoggingHandler>();
		}

		[Fact]
		public void EnableConsoleLog_doesnt_add_a_logger_if_handlers_contains_a_console_logger_already()
		{
			var config = new DashenConfiguration();
			config.MessageHandlers.Add(new ConsoleLoggingHandler());

			config.EnableConsoleLog();

			config.MessageHandlers.Count.ShouldBe(1);
			config.MessageHandlers.Single().ShouldBeOfType<ConsoleLoggingHandler>();
		}

		[Fact]
		public void DisableConsoleLog_removes_the_logger_if_it_exists()
		{
			var config = new DashenConfiguration();
			config.MessageHandlers.Add(new ConsoleLoggingHandler());

			config.DisableConsoleLog();

			config.MessageHandlers.ShouldBeEmpty();
		}

		[Fact]
		public void DisableConsoleLog_does_nothing_if_there_is_no_logger_already()
		{
			var config = new DashenConfiguration();

			config.DisableConsoleLog();

			config.MessageHandlers.ShouldBeEmpty();
		}

		[Fact]
		public void AddResource_allows_the_content_stream_to_be_shut()
		{
			var config = new DashenConfiguration();

			using (var ms = new MemoryStream())
			using( var writer = new StreamWriter(ms))
			{
				writer.Write("Test value");
				writer.Flush();
				ms.Position = 0;

				config.AddResource("test", ms, "text/plain");
			}
			var adhoc = new AdhocContentProvider();
			var init = new StaticContentInitialisation(config, new ReplacementSource(), adhoc);
			init.ApplyTo(null);
{'fraction_non_alphanumeric': 0.10054559625876851, 'fraction_numerical': 0.0010392309690828788, 'mean_word_length': 5.239870340356564, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998184', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1178, 'n_words': 215}