Example #1
0
        public void Callback()
        {
            IContainer container = new Container();

            container.Set(typeof(IRobot)).To(typeof(AttackRobot)).Callback(new PostFunc(PostCreateRobot));

            AttackRobot robot = container.Get(typeof(IRobot)) as AttackRobot;

            string result = robot.Attack();

            Assert.AreEqual("attack with the drill punch", result);
        }
Example #2
0
        public void Singleton()
        {
            IContainer container = new Container();

            container.Set(typeof(IRobot)).To(typeof(AttackRobot)).Singleton();
            container.Set(typeof(IPilot)).To(typeof(Pilot));

            AttackRobot robot = container.Get(typeof(IRobot)) as AttackRobot;

            robot.SetWeapon("drill punch");

            string result = robot.Attack();

            Assert.AreEqual("attack with the drill punch", result);

            AttackRobot robot2 = container.Get(typeof(IRobot)) as AttackRobot;

            result = robot2.Attack();

            Assert.AreEqual("attack with the drill punch", result);

            Assert.AreEqual(true, robot.Equals(robot2));
        }