Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Flexible Plugin System

, 3 Sep 2008
A generic plugin system used to load and manage plugins
fadd-15373.zip
trunk
dlls
xunit.dll
Examples
Plugins
ExampleApplication.Shared
Properties
ExampleApplication
Properties
ExamplePlugin.Shared
Properties
ExamplePlugin
Properties
Fadd.Globalization.Yaml
fadd.snk
Properties
Tests
fadd
Commands
Net
Tests
fadd.snk
Globalization
Tests
Logging
Plugins
Properties
Tests
Validation
#if DEBUG
using System;
using System.IO;
using System.Threading;
using Xunit;

namespace Fadd.Globalization.Yaml.Tests
{
    public class YamlWatcherTest
    {
        /// <summary>Test an incorrect file</summary>
        [Fact]
        public void TestIncorrectFile()
        {
            Assert.Throws(typeof(FileNotFoundException), delegate { new YamlWatcher(null, @"c:\doesnotexist"); });
        }

        [Fact]
        public void MultipleWriteSuccessTest()
        {
            const string filename = "test.yaml";
            File.WriteAllText("test.yaml", @"	1053: Swedish
		TextEntry1: En text.
		TextEntry2: En text2.
		EnSubNod: Subnoden 1
			SubNodTextEntry1: Subnodens textentry1");

            LanguageNode rootNode = new MemLanguageNode(1053, "RootNode");
            using (YamlWatcher watcher = new YamlWatcher(rootNode, filename))
            {
                Assert.Equal("En text.", rootNode["TextEntry1"]);
                Assert.Equal("Subnodens textentry1", rootNode.GetNode("EnSubNod")["SubNodTextEntry1"]);

                File.WriteAllText("test.yaml", @"	1053: Swedish
		TextEntry1: En text2.
		TextEntry2: En text1.
		EnSubNod: Subnoden 1
			SubNodTextEntry1: Subnodens textentry1");
                FileStream file = File.Open("test.yaml", FileMode.Append, FileAccess.Write);
                Thread.Sleep(1000);
                file.Close();
                Thread.Sleep(500);
                Assert.Equal("En text2.", rootNode["TextEntry1"]);
            }
        }

        [Fact]
        public void CorrectProcedureTest()
        {
            const string filename = "test.yaml";
            File.WriteAllText("test.yaml", @"	1053: Swedish
		TextEntry1: En text.
		TextEntry2: En text2.
		EnSubNod: Subnoden 1
			SubNodTextEntry1: Subnodens textentry1");

            LanguageNode rootNode = new MemLanguageNode(1053, "RootNode");
            using (YamlWatcher watcher = new YamlWatcher(rootNode, filename))
            {
                Assert.Equal("En text.", rootNode["TextEntry1"]);
                Assert.Equal("Subnodens textentry1", rootNode.GetNode("EnSubNod")["SubNodTextEntry1"]);

                Assert.Equal("[SubNodTextEntry2]", rootNode.GetNode("EnSubNod")["SubNodTextEntry2"]);
                File.AppendAllText(filename, Environment.NewLine + "			SubNodTextEntry2: Lite subnodtext.");
                Thread.Sleep(200);
                Assert.Equal("Lite subnodtext.", rootNode.GetNode("EnSubNod")["SubNodTextEntry2"]);

                Assert.Equal("[TextEntry3]", rootNode["TextEntry3"]);
                File.AppendAllText(filename, Environment.NewLine + "		TextEntry3: En text3.");
                Thread.Sleep(200);
                Assert.Equal("En text3.", rootNode["TextEntry3"]);
            }
        }

		[Fact]
		public void TestMultipleFiles()
		{
			const string filename = "test.yaml";
			File.WriteAllText("test.yaml", @"	1053: Swedish
		TextEntry1: En text.
		TextEntry1: En text2.
		EnSubNod: Subnoden 1
			SubNodTextEntry1: Subnodens textentry1
		EnSubNod: Subnoden 2
			SubNodTextEntry1: Subnodens textentry2");
			MemLanguageNode language = new MemLanguageNode(1053, "Test");
			YamlWatcher.LoadFile(filename, language);

			Assert.Equal("En text2.", language["TextEntry1"]);
			Assert.Equal("Subnodens textentry2", language.GetNode("EnSubNod")["SubNodTextEntry1"]);
		}

		[Fact]
		public void TestDoubleEntries()
		{
			const string filename = "test.yaml";
			File.WriteAllText("test.yaml", @"	1053: Swedish
		TextEntry1: En text.
		TextEntry1: En text2.
		EnSubNod: Subnoden 1
			SubNodTextEntry1: Subnodens textentry1
		EnSubNod: Subnoden 2
			SubNodTextEntry1: Subnodens textentry2");
			MemLanguageNode language = new MemLanguageNode(1053, "Test");
			YamlWatcher.LoadFile(filename, language);

			Assert.Equal("En text2.", language["TextEntry1"]);
			Assert.Equal("Subnodens textentry2", language.GetNode("EnSubNod")["SubNodTextEntry1"]);
		}
    }
}
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

About the Author

jgauffin
Founder Gauffin Interactive AB
Sweden Sweden
Founder of OneTrueError, a .NET service which captures, analyzes and provide possible solutions for exceptions.
 
blog | twitter
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 3 Sep 2008
Article Copyright 2008 by jgauffin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid