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 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)); }
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)); }
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"); } }
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"); } }