public void SamopalDISeeCommentsIntTest05()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass5>((args) => new Class5((string)args[0]));

            di.BindDefault <IClass2, Class2>();
            di.BindDefault <IClass3, Class3>();
            di.BindDefault <IClass4>((args) =>
            {
                IClass5 c5 = di.GetDefault <IClass5>(args);
                return(new Class4(c5));
            });

            di.BindDefault <IClass1>((args) =>
            {
                IClass2 c2 = di.GetDefault <IClass2>();
                IClass4 c4 = di.GetDefault <IClass4>(args);

                return(new Class1(c2, c4));
            });

            object[] arrayOfArgs = new object[] { "Hello, Test!" };

            Type    expected = typeof(Class1);
            IClass1 variable = di.GetDefault <IClass1>(arrayOfArgs);
            Type    actual   = variable.GetType();

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("Hello, Test!", variable.Class4.Class5.SomeString);
            Assert.IsNotNull(variable.Class2.Class3);
        }
Example #2
0
 public HomeController(IInjectionContainer ioc)
 {
     _class1 = ioc.Resolve <IClass1>();
     _class2 = ioc.Resolve <IClass2>();
     _class3 = ioc.Resolve <IClass3>();
     _thing  = ioc.Resolve <IClass1>("thing");
 }
Example #3
0
        static void Main(string[] args)
        {
            ILogger logger = LogManager.GetCurrentClassLogger();

            IUnityContainer unitycontainer = new UnityContainer(); // 建立物件

            unitycontainer.RegisterTypes(
                AllClasses.FromLoadedAssemblies(),
                WithMappings.FromMatchingInterface,
                WithName.Default,
                WithLifetime.Hierarchical);

            unitycontainer.RegisterInstance <ILogger>(logger); // 注入

            IClass1 class1 = unitycontainer.Resolve <IClass1>();

            //IClass class2 = new Class1(logger);

            class1.Log();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <BModelProfile>();
            });

            var mapper = config.CreateMapper();
            var amodel = new AModel
            {
                Name = "Jeff",
                No   = 123
            };
            BModel bmodel = mapper.Map <BModel>(amodel);
        }
Example #4
0
        public void AggregateTest()
        {
            IAggregatable duck = DuckTyping.Aggregate <IAggregatable>(new AggregateClass1(), new AggregateClass2());

            Assert.IsNotNull(duck);

            Assert.AreEqual(1, duck.Method1());
            Assert.AreEqual(2, duck.Method2());

            // It is still possible to get access
            // to an interface of an underlying object.
            //
            IClass2 cls2 = DuckTyping.Implement <IClass2>(duck);

            Assert.IsNotNull(cls2);
            Assert.AreEqual(2, cls2.Method2());

            // Even to switch from one aggregated object to another
            //
            IClass1 cls1 = DuckTyping.Implement <IClass1>(cls2);

            Assert.IsNotNull(cls1);
            Assert.AreEqual(1, cls1.Method1());
            Assert.AreEqual(3, cls1.Method3());
        }
    // Start is called before the first frame update
    void Start()
    {
        Teddy = new Class1("Teddy", "Chihuahua");
        Daisy = new Class1("Daisy", "Irish Wolfhound");
        Max   = new Class1("Max", "Poodle", 100);

        Pred = new Class2("Pred", "like");

        if (Pred is Class2)
        {
            (Pred as Class2).predator = 10;
        }

        var classss = new Classxxx();

        IClass1 class1 = classss;

        IClass1 class2 = Teddy;

        class1.Move();
        class2.Move();

        Max.SetHeight(105);
        Max.pros3 = 100;
    }
Example #6
0
        public void GenericMethodWithConstrait()
        {
            IClass1 class1 = MockRepository.Mock <IClass1>();
            IClass2 class2 = MockRepository.Mock <IClass2>();

            class1.Expect(x => x.Method1 <int>(1));
            class2.Expect(x => x.Method2(new ExampleClass()));
        }
Example #7
0
        public void GenericMethodWithConstrait()
        {
            MockRepository mocks = new MockRepository();

            IClass1 class1 = mocks.StrictMock <IClass1>();
            IClass2 class2 = mocks.StrictMock <IClass2>();

            class1.Method1 <int>(1);
            class2.Method2(mocks);
        }
Example #8
0
 public Class2(
     IClass1 class1, ILogger<Class2> logger,
     Service1 service1, Service2 service2, IService3 service3)
 {
     this.class1 = class1;
     this.logger = logger;
     _service1 = service1;
     _service2 = service2;
     _service3 = service3;
 }
Example #9
0
        public void MissedMethodsAggregateTest()
        {
            IClass1 duck = DuckTyping.Aggregate <IClass1>(new Version(1, 0), Guid.NewGuid());

            Assert.That(duck, Is.Not.Null);

            // Neither System.Guid nor System.Version will ever have Method1.
            //
            Assert.That(duck.Method1(), Is.EqualTo(0));
        }
Example #10
0
        public void Setup()
        {
            IClass1 fakeClass1 = Substitute.For <Class1>();

            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 1 && x.Count == 2)).Returns(new OrderDetail
            {
                Amount    = 246,
                ProductId = 1
            });
            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 2 && x.Count == 3)).Returns(new OrderDetail
            {
                Amount    = 1902,
                ProductId = 2
            });
            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 4 && x.Count == 1)).Returns(new OrderDetail
            {
                Amount    = 150,
                ProductId = 4
            });
            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 1 && x.Count == 5)).Returns(new OrderDetail
            {
                Amount    = 615,
                ProductId = 1
            });
            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 2 && x.Count == 4)).Returns(new OrderDetail
            {
                Amount    = 2536,
                ProductId = 2
            });
            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 3 && x.Count == 7)).Returns(new OrderDetail
            {
                Amount    = 1400,
                ProductId = 3
            });
            fakeClass1.ProcessOrderDetail(
                Arg.Any <string>(),
                Arg.Is <PaymentDetail>(x => x.ProdId == 4 && x.Count == 3)).Returns(new OrderDetail
            {
                Amount    = 450,
                ProductId = 4
            });
            FakeClass1 = fakeClass1;
        }
        public void GenericMethodWithConstrait()
        {
            IClass1 class1 = MockRepository.Mock <IClass1>();

            class1.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
            IClass2 class2 = MockRepository.Mock <IClass2>();

            class2.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            class1.Expect(x => x.Method1 <int>(1));
            class2.Expect(x => x.Method2(new ExampleClass()));
        }
Example #12
0
        static void Main(string[] args)
        {
            // Register new type
            DependencyFactory.Register <IClass1, Class1>();
            // Get saved type
            IClass1 cl1Object = DependencyFactory.Resolve <IClass1>();

            // Test the result
            Console.WriteLine(cl1Object.ToString());

            Console.ReadLine();
        }
        public void Should_resolve_multi_derived_class()
        {
            //Arrange
            IContainer containerBuilder = GetContainerBuilder()
                                          .Register <IClass3, Class3>()
                                          .Build();

            //Act
            IClass1 class1 = containerBuilder.Resolve <IClass1>();

            //Assert
            Assert.NotNull(class1);
            Assert.IsInstanceOf <Class3>(class1);
            Assert.AreEqual("Hello test", class1.Greet("test"));
        }
        public void Should_resolve_interface_singleton()
        {
            //Arrange
            IContainer containerBuilder = GetContainerBuilder()
                                          .RegisterSingleton <IClass1, Class1>()
                                          .Build();

            //Act
            IClass1 class1 = containerBuilder.Resolve <IClass1>();
            IClass1 class2 = containerBuilder.Resolve <IClass1>();

            //Assert
            Assert.NotNull(class1);
            Assert.AreEqual(class1, class2);
            Assert.AreEqual("Hello test", class1.Greet("test"));
        }
        public void Should_resolve_factory_with_interface()
        {
            //Arrange
            IContainer containerBuilder = GetContainerBuilder()
                                          .Register <IClass1>((IContainer inner) => new Class1())
                                          .Build();

            //Act
            IClass1 class1 = containerBuilder.Resolve <IClass1>();
            IClass1 class2 = containerBuilder.Resolve <IClass1>();

            //Assert
            Assert.NotNull(class1);
            Assert.AreNotEqual(class1, class2);
            Assert.AreEqual("Hello test", class1.Greet("test"));
        }
    public void DoWork_Should_Be_Done()
    {
        //Arrange
        IClass1       class1 = Mock.Of <IClass1>();
        Mock <Class2> class2 = new Mock <Class2>();

        class2.Setup(_ => _.Method2(It.IsAny <Action>()))
        .Returns(true)
        .Callback((Action passedAction) => passedAction?.Invoke());
        SomeClass subject  = new SomeClass(class1, class2.Object);
        string    expected = "done!";
        //Act
        var actual = subject.DoWork();

        //Assert
        actual.Should().Be(expected);                          //actual == expected
        Mock.Get(class1).Verify(_ => _.Method1(), Times.Once); //was action invoked
    }
        public void SamopalDISeeCommentsIntTest03()
        {
            var di = new SamopalDI();

            di.BindDefault <IClass5>((args) => new Class5("Hello, Test!"));

            di.BindDefault <IClass2, Class2>();
            di.BindDefault <IClass3, Class3>();
            di.BindDefault <IClass4, Class4>();

            di.BindDefault <IClass1, Class1>();

            Type    expected = typeof(Class1);
            IClass1 variable = di.GetDefault <IClass1>();
            Type    actual   = variable.GetType();

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("Hello, Test!", variable.Class4.Class5.SomeString);
        }
Example #18
0
        public TodoController(TodoContext context, IClass1 class1)
        {
            // test project reference with "dependency injection" ;-]
            var test       = class1;
            var testResult = test.Test();

            // test project reference with "dependency injection" ;-]

            _context = context;

            if (_context.TodoItems.Count() == 0)
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                _context.TodoItems.Add(new TodoItem {
                    Name = "Item1 " + testResult
                });
                _context.SaveChanges();
            }
        }
        public void SamopalDISeeCommentsIntTest09()
        {
            var di = new SamopalDI();

            di.BindExample <IClass5>(100500, (args) => new Class5((string)args[0]));

            // now we'll get IClass4 example instance by correct delegate
            di.BindExample <IClass2>(1456, (args) =>
            {
                IClass3 class3 = di.GetExample <IClass3>(3334445);
                return(new Class2(class3));
            });
            di.BindExample <IClass3, Class3>(3334445);

            di.BindExample <IClass4>(1, (args) =>
            {
                IClass5 c5 = di.GetExample <IClass5>(100500, args);
                return(new Class4(c5));
            });

            di.BindExample <IClass1>(-100600, (args) =>
            {
                IClass2 c2 = di.GetExample <IClass2>(1456);
                IClass4 c4 = di.GetExample <IClass4>(1, args);

                return(new Class1(c2, c4));
            });

            object[] arrayOfArgs = new object[] { "Hello, Test!" };

            Type    expected = typeof(Class1);
            IClass1 variable = di.GetExample <IClass1>(-100600, arrayOfArgs);
            Type    actual   = variable.GetType();

            Assert.AreEqual(expected, actual);
            Assert.AreEqual("Hello, Test!", variable.Class4.Class5.SomeString);
            Assert.IsNotNull(variable.Class2.Class3);
        }
Example #20
0
 public TenClassesController(
     IClass1 classA,
     IClass2 classB,
     IClass3 classC,
     IClass4 classD,
     IClass5 classE,
     IClass6 classF,
     IClass7 classG,
     IClass8 classH,
     IClass9 classI,
     IClass10 classJ
     )
 {
     this.classA = classA;
     this.classB = classB;
     this.classC = classC;
     this.classD = classD;
     this.classE = classE;
     this.classF = classF;
     this.classG = classG;
     this.classH = classH;
     this.classI = classI;
     this.classJ = classJ;
 }
Example #21
0
 static void InvokeFoo(this IClass1 e, IBCLClass1 x)
 {
     e.Foo(null);
     x.Foo(null);
 }
Example #22
0
 public void Setup()
 {
     cs01 = new Class1();
     cs02 = Mock.Create <IClass1>();
 }
 public void fRun(IClass1 p_oOb1, IClass2 p_oOb2)
 {
     _1.fRun(p_oOb1);
     _2.fRun(p_oOb2);
 }
Example #24
0
 public ImplIClass3Bis(IClass2 class1, IClass1 class2)
 {
 }
Example #25
0
 public Class1Container(IClass1 class1Instance)
 {
     this.Class1Instance = class1Instance;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="WelcomeController"/> class.
 /// </summary>
 /// <param name="class1">The class1.</param>
 public WelcomeController(
     IClass1 class1)
 {
     Guard.AgainstNull(() => class1);
     _class1 = class1;
 }
Example #27
0
 public Ping(IClass1 class1)
 {
     this.class1 = class1;
 }
Example #28
0
 public LogClass1(IClass1 obj)
 {
     _obj = obj;
 }
Example #29
0
 public TestController(IClass1 class1)
 {
     // At this point, your class1 will have been
     // instantiated by Unity.
 }
Example #30
0
 static Bar <T> InvokeFoo <T>(this IClass1 <Bar <T> > e, Bar <T> t)
 {
     return(e.Foo(t));
 }
 public HundredClassesController(
     IClass1 class1,
     IClass2 class2,
     IClass3 class3,
     IClass4 class4,
     IClass5 class5,
     IClass6 class6,
     IClass7 class7,
     IClass8 class8,
     IClass9 class9,
     IClass10 class10,
     IClass11 class11,
     IClass12 class12,
     IClass13 class13,
     IClass14 class14,
     IClass15 class15,
     IClass16 class16,
     IClass17 class17,
     IClass18 class18,
     IClass19 class19,
     IClass20 class20,
     IClass21 class21,
     IClass22 class22,
     IClass23 class23,
     IClass24 class24,
     IClass25 class25,
     IClass26 class26,
     IClass27 class27,
     IClass28 class28,
     IClass29 class29,
     IClass30 class30,
     IClass31 class31,
     IClass32 class32,
     IClass33 class33,
     IClass34 class34,
     IClass35 class35,
     IClass36 class36,
     IClass37 class37,
     IClass38 class38,
     IClass39 class39,
     IClass40 class40,
     IClass41 class41,
     IClass42 class42,
     IClass43 class43,
     IClass44 class44,
     IClass45 class45,
     IClass46 class46,
     IClass47 class47,
     IClass48 class48,
     IClass49 class49,
     IClass50 class50,
     IClass51 class51,
     IClass52 class52,
     IClass53 class53,
     IClass54 class54,
     IClass55 class55,
     IClass56 class56,
     IClass57 class57,
     IClass58 class58,
     IClass59 class59,
     IClass60 class60,
     IClass61 class61,
     IClass62 class62,
     IClass63 class63,
     IClass64 class64,
     IClass65 class65,
     IClass66 class66,
     IClass67 class67,
     IClass68 class68,
     IClass69 class69,
     IClass70 class70,
     IClass71 class71,
     IClass72 class72,
     IClass73 class73,
     IClass74 class74,
     IClass75 class75,
     IClass76 class76,
     IClass77 class77,
     IClass78 class78,
     IClass79 class79,
     IClass80 class80,
     IClass81 class81,
     IClass82 class82,
     IClass83 class83,
     IClass84 class84,
     IClass85 class85,
     IClass86 class86,
     IClass87 class87,
     IClass88 class88,
     IClass89 class89,
     IClass90 class90,
     IClass91 class91,
     IClass92 class92,
     IClass93 class93,
     IClass94 class94,
     IClass95 class95,
     IClass96 class96,
     IClass97 class97,
     IClass98 class98,
     IClass99 class99,
     IClass100 class100
     )
 {
     this.class1   = class1;
     this.class2   = class2;
     this.class3   = class3;
     this.class4   = class4;
     this.class5   = class5;
     this.class6   = class6;
     this.class7   = class7;
     this.class8   = class8;
     this.class9   = class9;
     this.class10  = class10;
     this.class11  = class11;
     this.class12  = class12;
     this.class13  = class13;
     this.class14  = class14;
     this.class15  = class15;
     this.class16  = class16;
     this.class17  = class17;
     this.class18  = class18;
     this.class19  = class19;
     this.class20  = class20;
     this.class21  = class21;
     this.class22  = class22;
     this.class23  = class23;
     this.class24  = class24;
     this.class25  = class25;
     this.class26  = class26;
     this.class27  = class27;
     this.class28  = class28;
     this.class29  = class29;
     this.class30  = class30;
     this.class31  = class31;
     this.class32  = class32;
     this.class33  = class33;
     this.class34  = class34;
     this.class35  = class35;
     this.class36  = class36;
     this.class37  = class37;
     this.class38  = class38;
     this.class39  = class39;
     this.class40  = class40;
     this.class41  = class41;
     this.class42  = class42;
     this.class43  = class43;
     this.class44  = class44;
     this.class45  = class45;
     this.class46  = class46;
     this.class47  = class47;
     this.class48  = class48;
     this.class49  = class49;
     this.class50  = class50;
     this.class51  = class51;
     this.class52  = class52;
     this.class53  = class53;
     this.class54  = class54;
     this.class55  = class55;
     this.class56  = class56;
     this.class57  = class57;
     this.class58  = class58;
     this.class59  = class59;
     this.class60  = class60;
     this.class61  = class61;
     this.class62  = class62;
     this.class63  = class63;
     this.class64  = class64;
     this.class65  = class65;
     this.class66  = class66;
     this.class67  = class67;
     this.class68  = class68;
     this.class69  = class69;
     this.class70  = class70;
     this.class71  = class71;
     this.class72  = class72;
     this.class73  = class73;
     this.class74  = class74;
     this.class75  = class75;
     this.class76  = class76;
     this.class77  = class77;
     this.class78  = class78;
     this.class79  = class79;
     this.class80  = class80;
     this.class81  = class81;
     this.class82  = class82;
     this.class83  = class83;
     this.class84  = class84;
     this.class85  = class85;
     this.class86  = class86;
     this.class87  = class87;
     this.class88  = class88;
     this.class89  = class89;
     this.class90  = class90;
     this.class91  = class91;
     this.class92  = class92;
     this.class93  = class93;
     this.class94  = class94;
     this.class95  = class95;
     this.class96  = class96;
     this.class97  = class97;
     this.class98  = class98;
     this.class99  = class99;
     this.class100 = class100;
 }