|
//-------------------------------------------------------------------------------
// <copyright file="PublisherSubscriberMatchingTest.cs" company="bbv Software Services AG">
// Copyright (c) 2008 bbv Software Services AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-------------------------------------------------------------------------------
namespace bbv.Common.EventBroker
{
using System;
using Exceptions;
using NUnit.Framework;
[TestFixture]
public class PublisherSubscriberMatchingTest
{
private EventBroker testee;
[SetUp]
public void SetUp()
{
testee = new EventBroker();
}
[Test]
public void Match()
{
NormalPublisher p = new NormalPublisher();
NormalSubscriber s = new NormalSubscriber();
testee.Register(p);
testee.Register(s);
}
[Test]
public void MatchReversedRegistration()
{
NormalPublisher p = new NormalPublisher();
NormalSubscriber s = new NormalSubscriber();
testee.Register(s);
testee.Register(p);
}
[Test]
[ExpectedException(typeof(EventTopicException))]
public void PassNormalToCustomEventArgs()
{
NormalPublisher p = new NormalPublisher();
CustomSubscriber s = new CustomSubscriber();
testee.Register(p);
testee.Register(s);
}
[Test]
[ExpectedException(typeof(EventTopicException))]
public void PassNormalToCustomEventArgsReversedRegistration()
{
NormalPublisher p = new NormalPublisher();
CustomSubscriber s = new CustomSubscriber();
testee.Register(s);
testee.Register(p);
}
[Test]
[ExpectedException(typeof(EventTopicException))]
public void PassCustomToNormalEventArgs()
{
CustomPublisher p = new CustomPublisher();
NormalSubscriber s = new NormalSubscriber();
testee.Register(p);
testee.Register(s);
}
[Test]
[ExpectedException(typeof(EventTopicException))]
public void PassCustomToNormalEventArgsReversedRegistration()
{
CustomPublisher p = new CustomPublisher();
NormalSubscriber s = new NormalSubscriber();
testee.Register(s);
testee.Register(p);
}
[Test]
public void PassGenericToNormalEventArgs()
{
GenericPublisher p = new GenericPublisher();
NormalSubscriber s = new NormalSubscriber();
testee.Register(p);
testee.Register(s);
}
}
public class NormalPublisher
{
[EventPublication("Event")]
public event EventHandler Event;
}
public class GenericPublisher
{
[EventPublication("Event")]
public event EventHandler<EventArgs> Event;
}
public class CustomPublisher
{
[EventPublication("Event")]
public event EventHandler<DescribeToTest.CustomEventArgs> Event;
}
public class NormalSubscriber
{
[EventSubscription("Event", typeof(Handlers.Publisher))]
public void Handler(object sender, EventArgs e)
{}
}
public class CustomSubscriber
{
[EventSubscription("Event", typeof(Handlers.Publisher))]
public void Handler(object sender, DescribeToTest.CustomEventArgs e)
{ }
}
}
|
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.