public void TryResolve_WithFullInjection_AllInterfaceProperiesGetInjected()
        {
            MvxSingleton.ClearAllSingletons();
            var options = new MvxIocOptions
            {
                PropertyInjectorOptions = new MvxPropertyInjectorOptions()
                {
                    InjectIntoProperties = MvxPropertyInjection.AllInterfaceProperties
                }
            };
            var instance = MvxIoCProvider.Initialize(options);

            Mvx.IoCProvider.RegisterType <IA, A>();
            Mvx.IoCProvider.RegisterType <IB, B>();
            Mvx.IoCProvider.RegisterType <IC, C>();

            IA  a;
            var result = Mvx.IoCProvider.TryResolve(out a);

            Assert.True(result);
            Assert.NotNull(a);
            Assert.IsType <A>(a);
            var castA = (A)a;

            Assert.NotNull(castA.B);
            Assert.IsType <B>(castA.B);
            Assert.NotNull(castA.C);
            Assert.IsType <C>(castA.C);
            Assert.Null(castA.BNever);
            Assert.Null(castA.CNever);
        }
Beispiel #2
0
 protected virtual void Dispose(bool isDisposing)
 {
     if (isDisposing)
     {
         MvxSingleton.ClearAllSingletons();
     }
 }
        public void TryResolve_WithAttrInjection_AttrMarkedProperiesGetInjected()
        {
            MvxSingleton.ClearAllSingletons();
            var options = new MvxIocOptions
            {
                PropertyInjectorOptions = new MvxPropertyInjectorOptions()
                {
                    InjectIntoProperties = MvxPropertyInjection.MvxInjectInterfaceProperties
                }
            };
            var instance = MvxSimpleIoCContainer.Initialize(options);

            Mvx.RegisterType <IA, A>();
            Mvx.RegisterType <IB, B>();
            Mvx.RegisterType <IC, C>();

            IA  a;
            var result = Mvx.TryResolve(out a);

            Assert.IsTrue(result);
            Assert.IsNotNull(a);
            Assert.IsInstanceOf <A>(a);
            var castA = (A)a;

            Assert.IsNotNull(castA.B);
            Assert.IsInstanceOf <B>(castA.B);
            Assert.IsNull(castA.C);
            Assert.IsNull(castA.BNever);
            Assert.IsNull(castA.CNever);
        }
 public void Init()
 {
     MvxSingleton.ClearAllSingletons();
     accountRepository = new Mock <IAccountRepository>();
     accountRepository.SetupAllProperties();
     Setup();
 }
Beispiel #5
0
        public void Non_generic_RegisterType_with_constructor_throws_if_constructor_returns_incompatible_value()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxSimpleIoCContainer.Initialize();

            instance.RegisterType(typeof(IC), () => 36);

            var c1 = Mvx.Resolve <IC>();
        }
Beispiel #6
0
        public void IocConstruct_WithAnonymousTypeArguments_CreatesObject()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            var c = new C2();

            instance.IoCConstruct <B>(new { c });
        }
Beispiel #7
0
 protected virtual void ClearAll()
 {
     // fake set up of the IoC
     MvxSingleton.ClearAllSingletons();
     _ioc = MvxSimpleIoCContainer.Initialise();
     _ioc.RegisterSingleton(_ioc);
     _ioc.RegisterSingleton <IMvxTrace>(new TestTrace());
     MvxTrace.Initialize();
     MvxBindingStatics.ClearCaches();
     AdditionalSetup();
 }
Beispiel #8
0
        public void Non_generic_RegisterType_with_constructor_throws_if_constructor_returns_incompatible_value()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            instance.RegisterType(typeof(IC), () => 36);

            Assert.Throws <MvxIoCResolveException>(() => {
                var c1 = Mvx.Resolve <IC>();
            });
        }
Beispiel #9
0
        public static void ResetContext()
        {
            MvxSingleton.ClearAllSingletons();
            var ioc = MvxSimpleIoCContainer.Initialize(null);

            ioc.RegisterSingleton(ioc);
            ioc.RegisterSingleton <IMvxTrace>(new UnitTestTrace());
            MvxSingletonCache.Initialize();
            ioc.RegisterSingleton <IMvxSettings>(new MvxSettings());
            MvxTrace.Initialize();
        }
Beispiel #10
0
 protected void ClearAll()
 {
     // fake set up of the IoC
     MvxSingleton.ClearAllSingletons();
     _ioc = MvxSimpleIoCContainer.Initialise();
     _ioc.RegisterSingleton(_ioc);
     _ioc.RegisterSingleton <IMvxTrace>(new TestTrace());
     RegisterAdditionalSingletons();
     InitialiseSingletonCache();
     InitialiseMvxSettings();
     MvxTrace.Initialize();
 }
Beispiel #11
0
        public void Init()
        {
            MvxSingleton.ClearAllSingletons();
            accountRepository    = new Mock <IAccountRepository>();
            paymentRepository    = new Mock <IPaymentRepository>();
            recPaymentRepository = new Mock <IRepository <RecurringPayment> >();
            paymentManager       = new Mock <IPaymentManager>();

            accountRepository.SetupAllProperties();
            paymentRepository.SetupAllProperties();
            Setup();
        }
Beispiel #12
0
 protected virtual void ClearAll()
 {
     // fake set up of the IoC
     MvxSingleton.ClearAllSingletons();
     this._ioc = MvxSimpleIoCContainer.Initialize(this.CreateIocOptions());
     this._ioc.RegisterSingleton(this._ioc);
     this._ioc.RegisterSingleton <IMvxTrace>(new TestTrace());
     InitializeSingletonCache();
     this.InitializeMvxSettings();
     MvxTrace.Initialize();
     this.AdditionalSetup();
 }
        public virtual void Setup()
        {
            // fake set up of the IoC
            MvxSingleton.ClearAllSingletons();
            _ioc = new MvxSimpleIoCServiceProvider();
            var serviceProvider = new MvxServiceProvider(_ioc);

            _ioc.RegisterServiceInstance <IMvxServiceProviderRegistry>(serviceProvider);
            _ioc.RegisterServiceInstance <IMvxServiceProvider>(serviceProvider);
            _ioc.RegisterServiceInstance <IMvxTrace>(new MvxDebugTrace());
            MvxTrace.Initialize();
        }
Beispiel #14
0
        public void IocConstruct_WithDictionaryArguments_CreatesObject()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            var c         = new C2();
            var arguments = new Dictionary <string, object>
            {
                ["c"] = c
            };

            instance.IoCConstruct <B>(arguments);
        }
Beispiel #15
0
        public void IocConstruct_WithMultipleTypedArguments_ThrowsFailedToFindCtor()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            var title    = "The title";
            var subtitle = "The subtitle";
            var enabled  = true;

            Assert.Throws <MvxIoCResolveException>(() => {
                var d = instance.IoCConstruct <D>(title, subtitle, enabled);
            });
        }
Beispiel #16
0
        public void Init()
        {
            MvxSingleton.ClearAllSingletons();
            Setup();

            var settingsMockSetup = new Mock <ISettings>();

            settingsMockSetup.SetupAllProperties();
            settingsMockSetup.Setup(x => x.AddOrUpdateValue(It.IsAny <string>(), It.IsAny <DateTime>(), false))
            .Callback((string key, DateTime date, bool roam) => localDateSetting = date);

            Mvx.RegisterType(() => new Mock <IAutobackupManager>().Object);
            Mvx.RegisterType(() => settingsMockSetup.Object);
        }
Beispiel #17
0
        public void Init()
        {
            MvxSingleton.ClearAllSingletons();
            accountRepository = new Mock <IAccountRepository>();
            paymentRepository = new Mock <IPaymentRepository>();
            paymentManager    = new Mock <IPaymentManager>();
            settingsManager   = new Mock <ISettingsManager>();
            endOfMonthManager = new Mock <IEndOfMonthManager>();
            backupManager     = new Mock <IBackupManager>();

            accountRepository.SetupAllProperties();
            paymentRepository.SetupAllProperties();
            Setup();
        }
Beispiel #18
0
        public void IocConstruct_WithMultipleTypedArguments_CreatesObject()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            var title   = "The title";
            var amount  = 5;
            var enabled = true;

            var d = instance.IoCConstruct <D>(title, amount, enabled);

            Assert.Equal(title, d.Title);
            Assert.Equal(amount, d.Amount);
            Assert.Equal(enabled, d.Enabled);
        }
Beispiel #19
0
        public void RegisterType_with_constructor_creates_different_objects()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxSimpleIoCContainer.Initialize();

            instance.RegisterType <IC>(() => new C2());

            var c1 = Mvx.Resolve <IC>();
            var c2 = Mvx.Resolve <IC>();

            Assert.IsNotNull(c1);
            Assert.IsNotNull(c2);

            Assert.AreNotEqual(c1, c2);
        }
Beispiel #20
0
        public void Non_generic_RegisterType_with_constructor_creates_different_objects()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            instance.RegisterType(typeof(IC), () => new C2());

            var c1 = Mvx.Resolve <IC>();
            var c2 = Mvx.Resolve <IC>();

            Assert.NotNull(c1);
            Assert.NotNull(c2);

            Assert.NotEqual(c1, c2);
        }
Beispiel #21
0
        public void TryResolve_CircularLazyRegistration_ReturnsFalse()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxSimpleIoCContainer.Initialize();

            Mvx.LazyConstructAndRegisterSingleton <IA, A>();
            Mvx.LazyConstructAndRegisterSingleton <IB, B>();
            Mvx.LazyConstructAndRegisterSingleton <IC, C>();

            IA  a;
            var result = Mvx.TryResolve(out a);

            Assert.IsFalse(result);
            Assert.IsNull(a);
        }
Beispiel #22
0
        public void TryResolve_NonCircularRegistration_ReturnsTrue()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            Mvx.LazyConstructAndRegisterSingleton <IA, A>();
            Mvx.LazyConstructAndRegisterSingleton <IB, B>();
            Mvx.LazyConstructAndRegisterSingleton <IC, C2>();

            IA  a;
            var result = Mvx.TryResolve(out a);

            Assert.True(result);
            Assert.NotNull(a);
        }
Beispiel #23
0
        public void IocConstruct_WithMultipleAnonymousArguments_CreatesObject()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            var title       = "The title";
            var subtitle    = "The subtitle";
            var description = "The description";

            var arguments = new { title, subtitle, description };
            var d         = instance.IoCConstruct <D>(arguments);

            Assert.Equal(title, d.Title);
            Assert.Equal(subtitle, d.Subtitle);
            Assert.Equal(description, d.Description);
        }
Beispiel #24
0
        public void TryResolve_CircularButSafeDynamicWithOptionOn_ReturnsFalse()
        {
            COdd.FirstTime = true;
            MvxSingleton.ClearAllSingletons();
            var instance = MvxSimpleIoCContainer.Initialize();

            Mvx.RegisterType <IA, A>();
            Mvx.RegisterType <IB, B>();
            Mvx.RegisterType <IC, COdd>();

            IA  a;
            var result = Mvx.TryResolve(out a);

            Assert.IsFalse(result);
            Assert.IsNull(a);
        }
Beispiel #25
0
        public void TryResolve_ParameterConstructors_CreatesParametersUsingIocResolution()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            Mvx.RegisterType <IB, B>();
            Mvx.LazyConstructAndRegisterSingleton <IC, C2>();
            Mvx.RegisterType <IA, A>();

            IA  a1;
            var result = Mvx.TryResolve(out a1);

            Assert.True(result);
            Assert.NotNull(a1);
            Assert.NotNull(a1.B);
            Assert.IsType <B>(a1.B);
        }
Beispiel #26
0
        public void SetUp()
        {
            MvxSingleton.ClearAllSingletons();
            ClearAll();

            Dispatcher = new MockMvxViewDispatcher();
            Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(Dispatcher);
            Ioc.RegisterSingleton <IMvxViewDispatcher>(Dispatcher);

            DataClient       = new MockCampDataClient();
            Messenger        = new MvxMessengerHub();
            CodeCampService  = new CodeCampService(new InMemoryFileManager(), new MvxJsonConverter(), DataClient);
            ComposeEmailTask = new MockComposeEmailTask();
            WebBrowserTask   = new MockWebBrowserTask();

            Mvx.RegisterSingleton <IMvxStringToTypeParser>(new MvxStringToTypeParser());

            SetUpFixture();
        }
Beispiel #27
0
        public void TryResolve_CircularButSafeDynamicWithOptionOff_ReturnsTrue()
        {
            COdd.FirstTime = true;
            MvxSingleton.ClearAllSingletons();
            var options = new MvxIocOptions()
            {
                TryToDetectDynamicCircularReferences = false
            };
            var instance = MvxSimpleIoCContainer.Initialize(options);

            Mvx.RegisterType <IA, A>();
            Mvx.RegisterType <IB, B>();
            Mvx.RegisterType <IC, COdd>();

            IA  a;
            var result = Mvx.TryResolve(out a);

            Assert.IsTrue(result);
            Assert.IsNotNull(a);
        }
Beispiel #28
0
        protected virtual void ClearAll()
        {
            // fake set up of the IoC
            MvxSingleton.ClearAllSingletons();
            var withInject = new MvxPropertyInjectorOptions()
            {
                InjectIntoProperties          = MvxPropertyInjection.MvxInjectInterfaceProperties,
                ThrowIfPropertyInjectionFails = true
            };
            var options = new MvxIocOptions {
                PropertyInjectorOptions = withInject
            };

            _ioc = MvxSimpleIoCContainer.Initialize(options);
            _ioc.RegisterSingleton(_ioc);
            InitializeTrace();
            InitializeSingletonCache();
            InitializeMvxSettings();
            MvxTrace.Initialize();
            AdditionalSetup();
        }
Beispiel #29
0
        public void TryResolve_Dynamic_ReturnsDifferentInstanceEachTime()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            Mvx.LazyConstructAndRegisterSingleton <IB, B>();
            Mvx.LazyConstructAndRegisterSingleton <IC, C2>();
            Mvx.RegisterType <IA, A>();

            var previous = new Dictionary <IA, bool>();

            for (int i = 0; i < 100; i++)
            {
                IA  a1;
                var result = Mvx.TryResolve(out a1);
                Assert.True(result);
                Assert.False(previous.ContainsKey(a1));
                Assert.Equal(i, previous.Count);
                previous.Add(a1, true);
            }
        }
Beispiel #30
0
        public void IocConstruct_WithMultipleDictionaryArguments_CreatesObject()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxIoCProvider.Initialize();

            var title       = "The title";
            var subtitle    = "The subtitle";
            var description = "The description";

            var arguments = new Dictionary <string, object>
            {
                ["title"]       = title,
                ["subtitle"]    = subtitle,
                ["description"] = description
            };
            var d = instance.IoCConstruct <D>(arguments);

            Assert.Equal(title, d.Title);
            Assert.Equal(subtitle, d.Subtitle);
            Assert.Equal(description, d.Description);
        }