Click here to Skip to main content
15,886,678 members
Articles / Programming Languages / C# 4.0

Extended Thread Pool

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
6 Apr 2013Ms-PL3 min read 81.7K   1.8K   119  
Your own extensible and configurable Thread Pool.
using System;
using Moq;
using Nelibur.Sword.Patterns;
using Xunit;

namespace UnitTests.Nelibur.Sword.Patterns
{
    public class VisitorTests
    {
        [Fact]
        public void ActionVisitor_Visit_Success()
        {
            var mock = new Mock<VisitorTests>();

            IActionVisitor<Letter> visitor = Visitor.For<Letter>();
            visitor.Register<A>(mock.Object.VisitAction);
            visitor.Register<B>(mock.Object.VisitAction);
            var value = new A();

            visitor.Visit(value);
            mock.Verify(x => x.VisitAction(value));
        }

        [Fact]
        public void FuncVisitor_Visit_Success()
        {
            var mock = new Mock<VisitorTests>();

            IFuncVisitor<Letter, int> visitor = Visitor.For<Letter, int>();
            visitor.Register<A>(mock.Object.VisitFunc)
                   .Register<B>(mock.Object.VisitFunc);

            var value = new A();

            visitor.Visit(value);
            mock.Verify(x => x.VisitFunc(value));
        }

        protected virtual void VisitAction(A value)
        {
        }

        protected virtual void VisitAction(B value)
        {
        }

        protected virtual int VisitFunc(A value)
        {
            return 1;
        }

        protected virtual int VisitFunc(B value)
        {
            return 1;
        }

        protected sealed class A : Letter
        {
        }

        protected sealed class B : Letter
        {
        }

        protected abstract class Letter
        {
        }
    }
}

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 Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior)
United States United States
B.Sc. in Computer Science.

Comments and Discussions