Esempio n. 1
0
        public UnityRegionNavigationContentLoaderFixture()
        {
            _container = new UnityContainer();
            MockServiceLocator serviceLocator = new MockServiceLocator(_container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);
        }
        public CastleWindsorRegionNavigationContentLoaderFixture()
        {
            _container = new WindsorContainer();
            var serviceLocator = new MockServiceLocator(_container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);
        }
        public void TryResolveShouldReturnNullIfNotFound()
        {
            IServiceLocator sl = new MockServiceLocator(() => null);

            object value = sl.TryResolve(typeof(ServiceLocatorExtensionsFixture));

            Assert.IsNull(value);
        }
        public void ShouldResolveFoundtypes()
        {
            IServiceLocator sl = new MockServiceLocator(() => new ServiceLocatorExtensionsFixture());

            object value = sl.TryResolve(typeof(ServiceLocatorExtensionsFixture));

            Assert.IsNotNull(value);
        }
        public void GenericTryResolveShouldReturn()
        {
            IServiceLocator sl = new MockServiceLocator(() => new ServiceLocatorExtensionsFixture());

            ServiceLocatorExtensionsFixture value = sl.TryResolve <ServiceLocatorExtensionsFixture>();

            Assert.IsNotNull(value);
        }
        public void TryResolveShouldReturnNullIfNotFound()
        {
            IServiceLocator sl = new MockServiceLocator(() => null);

            object value = sl.TryResolve(typeof(ServiceLocatorExtensionsFixture));

            Assert.IsNull(value);
        }
        public override void Setup()
        {
            base.Setup();

            _testView = new TestView(new TestViewModel());
            MockNavigationLookup.Where_GetViewType_returns <TestViewModel>(typeof(TestView));
            MockServiceLocator.Where_Resolve_returns(_testView, typeof(TestView));
        }
        public void CanChangeServiceLocator()
        {
            var mock = new MockServiceLocator();

            SharePointServiceLocator.ReplaceCurrentServiceLocator(mock);

            Assert.AreEqual(mock, SharePointServiceLocator.Current);
        }
        public void ShouldResolveFoundtypes()
        {
            IServiceLocator sl = new MockServiceLocator(() => new ServiceLocatorExtensionsFixture());

            object value = sl.TryResolve(typeof(ServiceLocatorExtensionsFixture));

            Assert.IsNotNull(value);
        }
        public void IF_service_provider_returns_null_SHOULD_throw()
        {
            //Arrange
            MockServiceLocator.Where_Resolve_returns(null, typeof(TestView));

            //Act
            Assert.ThrowsAsync <NavigationException>(async() => await Sut.ShowViewAsync <TestViewModel>(), "No View of type TestView has been registered with the Ioc container");
        }
        public void GenericTryResolveShouldReturn()
        {
            IServiceLocator sl = new MockServiceLocator(() => new ServiceLocatorExtensionsFixture());

            ServiceLocatorExtensionsFixture value = sl.TryResolve<ServiceLocatorExtensionsFixture>();

            Assert.IsNotNull(value);
        }
        public void IF_resolved_view_cannot_be_converted_to_Page_SHOULD_throw()
        {
            //Arrange
            MockNavigationLookup.Where_GetViewType_returns <TestViewModel>(typeof(FakeView));
            MockServiceLocator.Where_Resolve_returns(new FakeView(), typeof(FakeView));

            //Act
            Assert.ThrowsAsync <NavigationException>(async() => await Sut.ShowViewAsync <TestViewModel>(), "View type FakeView is not a Xamarin.Forms Page");
        }
        public void Create_New_Instance_With_Valid_ServiceLocator()
        {
            DefaultFilterFinder finder;
            var locator = new MockServiceLocator();

            finder = new DefaultFilterFinder(locator);
            Assert.IsNotNull(finder);
            Assert.IsNotNull(finder.ServiceLocator);
        }
        public override void Setup()
        {
            base.Setup();

            _parameter          = Guid.NewGuid();
            _testView           = new TestInitializingView(new TestInitializingViewModel());
            _testNavigationView = new NavigationView(MockNavigationService.Object, _testView);

            MockNavigationLookup.Where_GetViewType_returns <TestInitializingViewModel>(typeof(TestInitializingView));
            MockServiceLocator.Where_Resolve_returns(_testView, typeof(TestInitializingView));
        }
        public void CanRegisterContentAndRetrieveIt()
        {
            MockServiceLocator locator = GetServiceLocator(new[] { "MyRegion" });
            var registry = (IRegionViewRegistry)locator.GetInstance(typeof(IRegionViewRegistry));

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

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.IsInstanceOfType(result.ElementAt(0), typeof(MockView));
        }
Esempio n. 16
0
        public void PassingServiceLocatorForInstrumentationAndActivityIDProviderRequestsInstrumentationProviderInstance()
        {
            MockServiceLocator serviceLocator = new MockServiceLocator();

            LogSource source    = new LogSource("tracesource", SourceLevels.All);
            LogWriter logWriter = new LogWriterImpl(new List <ILogFilter>(), new List <LogSource>(), source, null, new LogSource("errors"), "default", false, false);

            new Tracer("testoperation", Guid.NewGuid(), logWriter, serviceLocator).Dispose();

            Assert.AreEqual(1, serviceLocator.ServicesRequested.Count);
            Assert.AreEqual(typeof(ITracerInstrumentationProvider), serviceLocator.ServicesRequested[0]);
        }
        private MockServiceLocator GetServiceLocator(string[] defaultRegions)
        {
            MockServiceLocator locator = new MockServiceLocator();
            var regionViewRegistry     = new RegionViewRegistry(locator);
            var behavior = new AutoPopulateRegionBehavior(regionViewRegistry);
            var regionBehaviorFactory = new RegionBehaviorFactory(locator);

            regionBehaviorFactory.AddIfMissing(AutoPopulateRegionBehavior.BehaviorKey, typeof(AutoPopulateRegionBehavior));
            var regionManager = new RegionManager(regionBehaviorFactory);

            locator.GetInstance = (type) =>
            {
                if (type == typeof(IRegionManager))
                {
                    return(regionManager);
                }
                if (type == typeof(IRegionViewRegistry))
                {
                    return(regionViewRegistry);
                }
                if (type == typeof(AutoPopulateRegionBehavior))
                {
                    return(behavior);
                }
                if (type == typeof(IRegionBehaviorFactory))
                {
                    return(regionBehaviorFactory);
                }
                if (type == typeof(IServiceLocator))
                {
                    return(locator);
                }
                if (type == typeof(MockView))
                {
                    return(new MockView());
                }
                if (type == typeof(object))
                {
                    return(new object());
                }
                return(null);
            };

            foreach (var region in defaultRegions)
            {
                regionManager.Regions.Add(new MockRegion {
                    Name = region
                });
            }

            return(locator);
        }
        public void CanRegisterContentAsDelegateAndRetrieveIt()
        {
            MockServiceLocator locator = GetServiceLocator(new[] { "MyRegion" });
            var registry = (IRegionViewRegistry)locator.GetInstance(typeof(IRegionViewRegistry));
            var content  = new MockView();

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

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreSame(content, result.ElementAt(0));
        }
        public async Task IF_ViewModel_is_IAsyncInitializable_SHOULD_initialize()
        {
            //Arrange
            var testAsyncInitializableView = new TestAsyncInitializableView(new TestAsyncInitializableViewModel());

            MockNavigationLookup.Where_GetViewType_returns <TestAsyncInitializableViewModel>(typeof(TestAsyncInitializableView));
            MockServiceLocator.Where_Resolve_returns(testAsyncInitializableView, typeof(TestAsyncInitializableView));

            //Act
            await Sut.ShowMainViewAsync <TestAsyncInitializableViewModel>();

            //Assert
            Assert.That(((TestAsyncInitializableViewModel)testAsyncInitializableView.BindingContext).IsInitialized, Is.True);
        }
        public override void Setup()
        {
            base.Setup();

            MockForms.Init();

            _testViewModel = new TestViewModel();
            _testView      = new TestView(new TestViewModel());

            _testMenuView        = new TestMenuView(_testViewModel);
            _testFlyoutViewModel = new TestFlyoutViewModel();
            _testFlyoutPage      = new FlyoutPage <TestFlyoutViewModel, TestMenuView, TestView>(_testFlyoutViewModel, MockNavigationService.Object, _testMenuView, _testView);

            MockNavigationLookup.Where_GetViewType_returns <TestViewModel>(typeof(TestView));
            MockServiceLocator.Where_Resolve_returns(_testView, typeof(TestView));
        }
        public void ShouldRaiseEventWhenAddingContent()
        {
            MockServiceLocator locator = GetServiceLocator(new[] { "MyRegion" });
            var listener = new MySubscriberClass();
            var registry = (IRegionViewRegistry)locator.GetInstance(typeof(IRegionViewRegistry));

            registry.ViewRegistered += listener.OnViewRegistered;

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

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

            var result = listener.onViewRegisteredArguments.Region;

            Assert.IsNotNull(result);
        }
        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));
        }
Esempio n. 24
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));
        }
Esempio n. 25
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 OnRegisterErrorShouldGiveClearException()
        {
            MockServiceLocator locator = GetServiceLocator(new[] { "R1" });
            var registry = (IRegionViewRegistry)locator.GetInstance(typeof(IRegionViewRegistry));

            registry.ViewRegistered += 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));
            MockServiceLocator locator = GetServiceLocator(new[] { "R1" });
            var registry = (IRegionViewRegistry)locator.GetInstance(typeof(IRegionViewRegistry));

            registry.ViewRegistered += 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");
            }
        }
Esempio n. 28
0
        public void ConfigureMockServiceLocator(DependencyInjectionContainer container)
        {
            MockServiceLocator serviceLocator = new MockServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);
        }
Esempio n. 29
0
        private static void ConfigureMockServiceLocator(IDependecyRegistrar container)
        {
            var serviceLocator = new MockServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);
        }
        public void ConfigureMockServiceLocator(IKernel kernel)
        {
            MockServiceLocator serviceLocator = new MockServiceLocator(kernel);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);
        }
 public CastleWindsorRegionNavigationContentLoaderFixture()
 {
     _container = new WindsorContainer();
     MockServiceLocator serviceLocator = new MockServiceLocator(_container);
 }
Esempio n. 32
0
        public static void ClassInitialize(TestContext testContext)
        {
            IServiceLocator mockServiceLocator = new MockServiceLocator(EnterpriseLibraryContainer.Current);

            EnterpriseLibraryContainer.Current = mockServiceLocator;
        }
        public void ConfigureMockServiceLocator(IUnityContainer container)
        {
            MockServiceLocator serviceLocator = new MockServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);
        }