コード例 #1
0
        public void MicrosoftDependencyResolver_Should_Throw_If_Attempt_Registration_After_Build()
        {
            var wrapper = new ContainerWrapper();

            wrapper.BuildAndUse();

            var result = Record.Exception(() => Locator.CurrentMutable.Register(() => new ViewOne()));

            result.ShouldBeOfType <InvalidOperationException>();
        }
コード例 #2
0
        public void MicrosoftDependencyResolver_Should_Throw_If_ServiceRegistionCallback_Called()
        {
            var wrapper = new ContainerWrapper();

            wrapper.BuildAndUse();

            var result = Record.Exception(() =>
                                          Locator.CurrentMutable.ServiceRegistrationCallback(typeof(IScreen), disposable => { }));

            result.ShouldBeOfType <NotImplementedException>();
        }
コード例 #3
0
        public void MicrosoftDependencyResolver_Should_Resolve_Screen()
        {
            var wrapper  = new ContainerWrapper();
            var services = wrapper.ServiceCollection;

            services.AddSingleton <IScreen>(new MockScreen());

            wrapper.BuildAndUse();

            var screen = Locator.Current.GetService <IScreen>();

            screen.ShouldNotBeNull();
            screen.ShouldBeOfType <MockScreen>();
        }
コード例 #4
0
        public void MicrosoftDependencyResolver_Should_Resolve_Named_View()
        {
            var wrapper  = new ContainerWrapper();
            var services = wrapper.ServiceCollection;

            services.AddTransient <IViewFor <ViewModelTwo>, ViewTwo>();

            wrapper.BuildAndUse();

            var viewTwo = Locator.Current.GetService(typeof(IViewFor <ViewModelTwo>));

            viewTwo.ShouldNotBeNull();
            viewTwo.ShouldBeOfType <ViewTwo>();
        }
コード例 #5
0
        public void MicrosoftDependencyResolver_Should_Resolve_View_Models()
        {
            var wrapper  = new ContainerWrapper();
            var services = wrapper.ServiceCollection;

            services.AddTransient <ViewModelOne>();
            services.AddTransient <ViewModelTwo>();

            wrapper.BuildAndUse();

            var vmOne = Locator.Current.GetService <ViewModelOne>();
            var vmTwo = Locator.Current.GetService <ViewModelTwo>();

            vmOne.ShouldNotBeNull();
            vmTwo.ShouldNotBeNull();
        }
コード例 #6
0
        public void MicrosoftDependencyResolver_Should_UnregisterAll()
        {
            var wrapper  = new ContainerWrapper();
            var services = wrapper.ServiceCollection;

            services.AddSingleton <IScreen>(new MockScreen());

            Locator.CurrentMutable.HasRegistration(typeof(IScreen))
            .ShouldBeTrue();

            Locator.CurrentMutable.UnregisterAll(typeof(IScreen));

            var result = Locator.Current.GetService <IScreen>();

            result.ShouldBeNull();
        }