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);
 }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
 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);
     }
 }
 public static void MyClassInitialize()
 {
     // Initialize the Singleton
     staticContainer = new SyringeContainer();
     staticContainer.Register<IMathNode, Zero>("zero").AsSingleton();
 }