예제 #1
0
        public void BothCompanyAndPersonServiceTest()
        {
            var container = new SyringeContainer();
            container.Register<ICustomerService, CompanyService> ("CompanyService").AsSingleton ();
            container.Register<ICustomerService, PersonService> ("PersonService").AsSingleton ();

            // by default, the first will be used e.g. 'companyservice'
            var targetId = 1001;
            var target = container.Resolve<ICustomerService> ().Retrieve (targetId);
            Assert.IsNotNull (target);
            Assert.IsTrue (target.Id == targetId);

            // fetch explicitely through PersonService
            var secondTargetId = 1002;
            var secondTarget = container.Resolve<ICustomerService> ("PersonService").Retrieve (secondTargetId);
            Assert.IsNotNull (secondTarget);
            Assert.IsTrue (secondTarget.Id == secondTargetId);
        }
예제 #2
0
        public void PersonServiceTest()
        {
            var container = new SyringeContainer();
            container.Register<ICustomerService, PersonService> ("CustomerService").AsSingleton ();

            var targetId = 1002;
            var target = container.Resolve<ICustomerService> ().Retrieve (targetId);
            Assert.IsNotNull (target);
            Assert.IsTrue (target.Id == targetId);
        }
예제 #3
0
        public void SyringeContainer_Should_Resolve_NamedRegistration()
        {
            // arrange
            var c = new SyringeContainer();
            c.Register<IMathNode, Zero>("zero");

            // act
            var target = c.Resolve<IMathNode>("zero");

            // assert
            target.Should ().BeOfType <Zero> ();
            target.Calculate ().Should ().Be (0);
        }
예제 #4
0
        public void SyringeContainer_Should_Allow_MultipleRegistration_And_Fetch_First_ByDefault()
        {
            // arrange
            int expected = 0;
            var c = new SyringeContainer();

            // act: register two instances - by default fetching the first
            c.Register<IMathNode, Zero>();
            c.Register<IMathNode, Number>();
            var target = c.Resolve<IMathNode>().Calculate();

            // assert:
            Assert.AreEqual(expected, target);
        }
예제 #5
0
        public void SyringeContainer_Should_Allow_MultipleRegistration_WithPreference()
        {
            // arrange
            int expected = 0;
            var c = new SyringeContainer();

            // act: register two instances - by default expecting the first
            c.Register<IMathNode, Zero>();
            c.Register<IMathNode, Number>().WithValue("number", expected);
            var target = c.Resolve<IMathNode>();

            // assert
            target.Should ().BeOfType <Zero> ();
            target.Calculate ().Should ().Be (expected);
        }
예제 #6
0
 public void WithValueAnonymous()
 {
     for (int i = 0; i < 3; i++)
     {
         var c = new SyringeContainer();
         c.Register<IMathNode, Number>().WithValue("number", i);
         int target = c.Resolve<IMathNode>().Calculate();
         Assert.AreEqual(i, target);
     }
 }
예제 #7
0
 public void WithValue()
 {
     var c = new SyringeContainer();
     c.Register<IMathNode, Number>("five").WithValue("number", 5);
     int i = c.Resolve<IMathNode>("five").Calculate();
     Assert.AreEqual(5, i);
 }