コード例 #1
0
        public void ShouldHandleCollisions()
        {
            Tuple <string, string> s = MakeCollision();

            var registrationSet = new RegistrationSet();
            var registration1   = new InternalRegistration();
            var registration2   = new InternalRegistration();
            var registration3   = new InternalRegistration();

            registrationSet.Add(typeof(IService), s.Item1, registration1);
            Assert.AreEqual(1, registrationSet.Count);
            registrationSet.Add(typeof(IService), s.Item2, registration2);
            Assert.AreEqual(2, registrationSet.Count);
            registrationSet.Add(typeof(IService), s.Item1, registration3);
            Assert.AreEqual(2, registrationSet.Count);
        }
コード例 #2
0
        public void ShouldHandleCollisions()
        {
            var(s1, s2) = MakeCollision();

            var registrationSet = new RegistrationSet();
            var registration1   = new InternalRegistration();
            var registration2   = new InternalRegistration();
            var registration3   = new InternalRegistration();

            registrationSet.Add(typeof(IService), s1, registration1);
            Assert.AreEqual(1, registrationSet.Count);
            registrationSet.Add(typeof(IService), s2, registration2);
            Assert.AreEqual(2, registrationSet.Count);
            registrationSet.Add(typeof(IService), s1, registration3);
            Assert.AreEqual(2, registrationSet.Count);
        }
コード例 #3
0
        public async Task Add_DoesntRegister()
        {
            var handler1 = CreateHandler();
            var handler2 = CreateHandler();
            var handler3 = CreateHandler();

            var broker = Mocks.Create <IMessageBroker>();

            broker
            .Setup(b => b.RegisterAsync(It.IsAny <Type>(), It.IsAny <MessageHandler>()))
            .ReturnsAsync(() => new Registration());

            var set = new RegistrationSet(broker.Object)
                      .Add(typeof(Message1), handler1);

            await set.RegisterAsync();

            set
            .Add(typeof(Message2), handler2)
            .Add(typeof(Message3), handler3);

            broker.Verify(b => b.RegisterAsync(typeof(Message1), handler1), Times.Once());
            broker.VerifyNoOtherCalls();
        }