Exemple #1
0
        public void Constructor_NullServices()
        {
            using (var u = new TestUniverse(InitMode.None))
            {
                // Arrange

                // Act
                var ex = Assert.Throws <ArgumentNullException>(() => u.CreateFactory(InitMode.Registrar));

                // Assert
                Assert.That(ex.ParamName, Is.EqualTo("services"));
            }
        }
Exemple #2
0
        public void GetService_NotRegistered()
        {
            using (var u = new TestUniverse())
            {
                // Assert
                u.Registrar.Setup(r => r.LookUp(typeof(IMyService), "KEY"))
                .Returns(default(Type));

                // Act
                var svc = u.Factory.GetService(typeof(IMyService), "KEY");

                // Assert
                Assert.That(svc, Is.Null);
            }
        }
Exemple #3
0
        public void GetRequiredService_NotRegistered()
        {
            using (var u = new TestUniverse())
            {
                // Assert
                u.Registrar.Setup(r => r.LookUp(typeof(IMyService), "KEY"))
                .Returns(default(Type));

                // Act
                // ReSharper disable once MustUseReturnValue
                var ex = Assert.Throws <InvalidOperationException>(() => u.Factory.GetRequiredService(typeof(IMyService), "KEY"));

                // Assert
                Assert.That(ex.Message, Is.EqualTo("Service 'KEY' of type IMyService is not registered"));
            }
        }
Exemple #4
0
        public void GetService()
        {
            using (var u = new TestUniverse())
            {
                // Arrange
                u.Registrar.Setup(r => r.LookUp(typeof(IMyService), "KEY"))
                .Returns(typeof(MyService2));
                var svc = new MyService2();
                u.Services.Setup(s => s.GetService(typeof(MyService2))).Returns(svc);

                // Act
                var actualSvc = u.Factory.GetService <IMyService>("KEY");

                // Assert
                Assert.That(actualSvc, Is.SameAs(svc));
            }
        }