Defines a registry for the content of the regions used on View Discovery composition.
Inheritance: IRegionViewRegistry
Exemplo n.º 1
0
        public void CanRegisterContentAsDelegateAndRetrieveIt()
        {
            var registry = new RegionViewRegistry(null);
            var content = new MockContentObject();

            registry.RegisterViewWithRegion("MyRegion", () => content);
            var result = registry.GetContents("MyRegion");

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreSame(content, result.ElementAt(0));
        }
        public void ShouldNotPreventSubscribersFromBeingGarbageCollected()
        {
            var registry = new RegionViewRegistry(null);
            var subscriber = new MySubscriberClass();
            registry.ContentRegistered += subscriber.OnContentRegistered;

            WeakReference subscriberWeakReference = new WeakReference(subscriber);

            subscriber = null;
            GC.Collect();

            Assert.IsFalse(subscriberWeakReference.IsAlive);
        }
Exemplo n.º 3
0
        public void ShouldRaiseEventWhenAddingContent()
        {
            var listener = new MySubscriberClass();
            MockServiceLocator locator = new MockServiceLocator();
            locator.GetInstance = (type) => new MockContentObject();
            var registry = new RegionViewRegistry(locator);

            registry.ContentRegistered += listener.OnContentRegistered;

            registry.RegisterViewWithRegion("MyRegion", typeof(MockContentObject));

            Assert.IsNotNull(listener.onViewRegisteredArguments);
            Assert.IsNotNull(listener.onViewRegisteredArguments.GetView);

            var result = listener.onViewRegisteredArguments.GetView();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(MockContentObject));
        }
Exemplo n.º 4
0
        public void CanRegisterContentAndRetrieveIt()
        {
            MockServiceLocator locator = new MockServiceLocator();
            Type calledType = null;
            locator.GetInstance = (type) =>
                                      {
                                          calledType = type;
                                          return new MockContentObject();
                                      };
            var registry = new RegionViewRegistry(locator);

            registry.RegisterViewWithRegion("MyRegion", typeof(MockContentObject));
            var result = registry.GetContents("MyRegion");

            Assert.AreEqual(typeof(MockContentObject), calledType);
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.IsInstanceOfType(result.ElementAt(0), typeof(MockContentObject));
        }
Exemplo n.º 5
0
        public void OnRegisterErrorShouldGiveClearException()
        {
            var registry = new RegionViewRegistry(null);
            registry.ContentRegistered += new EventHandler<ViewRegisteredEventArgs>(FailWithInvalidOperationException);

            try
            {
                registry.RegisterViewWithRegion("R1", typeof(object));
                Assert.Fail();
            }
            catch (ViewRegistrationException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Dont do this"));
                Assert.IsTrue(ex.Message.Contains("R1"));
                Assert.AreEqual(ex.InnerException.Message, "Dont do this");
            }
            catch(Exception)
            {
                Assert.Fail("Wrong exception type");
            }

        }
Exemplo n.º 6
0
        public void OnRegisterErrorShouldSkipFrameworkExceptions()
        {
            ExceptionExtensions.RegisterFrameworkExceptionType(typeof (FrameworkException));
            var registry = new RegionViewRegistry(null);
            registry.ContentRegistered +=new EventHandler<ViewRegisteredEventArgs>(FailWithFrameworkException);

            try
            {
                registry.RegisterViewWithRegion("R1", typeof (object));
                Assert.Fail();
            }
            catch (ViewRegistrationException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Dont do this"));
                Assert.IsTrue(ex.Message.Contains("R1"));
            }
            catch (Exception)
            {
                Assert.Fail("Wrong exception type");
            }
        }