Exemple #1
0
        public async Task Register_MultipleCalls_DoesntDuplicate()
        {
            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)
                      .Add(typeof(Message2), handler2)
                      .Add(typeof(Message3), handler3);

            await set.RegisterAsync();

            await set.RegisterAsync();

            await set.RegisterAsync();

            broker.Verify(b => b.RegisterAsync(typeof(Message1), handler1), Times.Once());
            broker.Verify(b => b.RegisterAsync(typeof(Message2), handler2), Times.Once());
            broker.Verify(b => b.RegisterAsync(typeof(Message3), handler3), Times.Once());
            broker.VerifyNoOtherCalls();
        }
Exemple #2
0
 public RegistrationSetDebugProxy(RegistrationSet set)
 {
     Registrations = set._entries
                     .Cast <IContainerRegistration>()
                     .Take(set.Count)
                     .ToArray();
 }
Exemple #3
0
        public async Task Unregister_UnregistersAll()
        {
            var handler1 = CreateHandler();
            var handler2 = CreateHandler();
            var handler3 = CreateHandler();

            var registration1 = new Registration();
            var registration2 = new Registration();
            var registration3 = new Registration();

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

            broker.Setup(b => b.RegisterAsync(typeof(Message1), handler1)).ReturnsAsync(registration1);
            broker.Setup(b => b.RegisterAsync(typeof(Message2), handler2)).ReturnsAsync(registration2);
            broker.Setup(b => b.RegisterAsync(typeof(Message3), handler3)).ReturnsAsync(registration3);

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

            await set.RegisterAsync();

            await set.UnregisterAsync();

            Assert.True(registration1.Disposed);
            Assert.True(registration2.Disposed);
            Assert.True(registration3.Disposed);
        }
Exemple #4
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);
        }
        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);
        }
Exemple #6
0
 public static void InitializeRegistrationSets()
 {
     PIMRepresentantsSet = new RegistrationSet
     {
         new RepresentantRegistration(typeof(AssociationClass), typeof(PIM_AssociationClass), typeof(ClassController), typeof(AssociationClassViewHelper), 6, 0),
         new RepresentantRegistration(typeof(Association), typeof(PIM_Association), typeof(AssociationController), typeof(AssociationViewHelper), 8, 1),
         new RepresentantRegistration(typeof(PIMClass), typeof(PIM_Class), typeof(ClassController), typeof(ClassViewHelper), 5, 2),
         new RepresentantRegistration(typeof(Comment), typeof(XCaseComment), typeof(CommentController), typeof(CommentViewHelper), 15, 10),
         new RepresentantRegistration(typeof(Generalization), typeof(PIM_Generalization), typeof(GeneralizationController), typeof(GeneralizationViewHelper), 10, 10)
     };
     PSMRepresentantsSet = new RegistrationSet
     {
         new RepresentantRegistration(typeof(PSMClass), typeof(PSM_Class), typeof(PSM_ClassController), typeof(PSMElementViewHelper), 1, 10),
         new RepresentantRegistration(typeof(PSMAttributeContainer), typeof(PSM_AttributeContainer), typeof(PSM_AttributeContainerController), typeof(PSMElementViewHelper), 2, 10),
         new RepresentantRegistration(typeof(PSMClassUnion), typeof(PSM_ClassUnion), typeof(PSM_ClassUnionController), typeof(PSMElementViewHelper), 3, 10),
         new RepresentantRegistration(typeof(PSMContentContainer), typeof(PSM_ContentContainer), typeof(PSM_ContentContainerController), typeof(PSMElementViewHelper), 4, 10),
         new RepresentantRegistration(typeof(PSMContentChoice), typeof(PSM_ContentChoice), typeof(PSM_ContentChoiceController), typeof(PSMElementViewHelper), 5, 10),
         new RepresentantRegistration(typeof(Comment), typeof(XCaseComment), typeof(CommentController), typeof(CommentViewHelper), 15, 10),
         new RepresentantRegistration(typeof(PSMAssociation), typeof(PSM_Association), typeof(PSM_AssociationController), typeof(PSMAssociationViewHelper), 12, 10),
         new RepresentantRegistration(typeof(Generalization), typeof(PIM_Generalization), typeof(GeneralizationController), typeof(GeneralizationViewHelper), 13, 10),
     };
 }
Exemple #7
0
        private static IList <TElement> ResolveRegistrations <TElement>(ref BuilderContext context, RegistrationSet registrations)
        {
            var type = typeof(TElement);
            var list = new List <TElement>();

            for (var i = 0; i < registrations.Count; i++)
            {
                ref var entry = ref registrations[i];
                try
                {
#if NETSTANDARD1_0 || NETCOREAPP1_0
                    if (entry.RegisteredType.GetTypeInfo().IsGenericTypeDefinition)
#else
                    if (entry.RegisteredType.IsGenericTypeDefinition)
#endif
                    { list.Add((TElement)context.Resolve(type, entry.Name)); }
                    else
                    {
                        list.Add((TElement)context.Resolve(type, entry.Name, entry.Registration));
                    }
                }
                catch (ArgumentException ex) when(ex.InnerException is TypeLoadException)
                {
                    // Ignore
                }
            }
Exemple #8
0
 /// <summary>
 /// Initializes the registration set for the canvas. Registration set is
 /// used to find a represeentation for a model element when it is
 /// added to the diagram
 /// </summary>
 /// <param name="registrationSet">The registration set.</param>
 public void InitializeRegistrationSet(RegistrationSet registrationSet)
 {
     ElementRepresentations = new RepresentationCollection(registrationSet);
 }