示例#1
0
        public byte Foo()
        {
            byte[] bars = _bar.Bar();
            byte   foo  = bars.Max();

            return(foo);
        }
示例#2
0
    public static int Main()
    {
        FooBar <string, object> fooBar = new FooBar <string, object>();
        IFoo <string>           foo    = (IFoo <string>)fooBar;
        IBar <string[]>         bar    = (IBar <string[]>)fooBar;

        Console.WriteLine("Calling IFoo<string>.Foo on FooBar<string, object> - expecting default method IFoo<string>.Foo");
        Test.Assert(foo.Foo("ABC") == typeof(string), "Calling IFoo<string>.Foo on FooBar<string, object>");

        Console.WriteLine("Calling IBar<string[]>.Foo on FooBar<string, object> - expecting default method IBar<object>.Foo");
        Test.Assert(bar.Bar(new string[] { "ABC" }) == typeof(object), "Calling IBar<object>.Bar on FooBar<string, object>");

        return(Test.Ret());
    }
示例#3
0
        public void Example12()
        {
            var mock = new Mock <Something>();

            /* Bu şekilde mocklama yapamayız. Bar metodu overridable değil.
             * Bu nedenle mock objemize interface tipi üzerinden mocklama
             * yapmamız gerekiyor. As<> kullanarak bunu sağlayabiliyoruz.
             *
             * mock.Setup(x => x.Bar()).Returns("Emre");
             *
             */
            mock.As <IBar>().Setup(x => x.Bar()).Returns("Hızlı");
            IBar something = mock.Object;

            var result1 = something.Bar();             // Hızlı
        }
示例#4
0
    public static int Main()
    {
        FooBar fooBar = new FooBar();
        IFoo   foo    = (IFoo)fooBar;
        IBar   bar    = (IBar)fooBar;
        IBlah  blah   = (IBlah)fooBar;

        Console.WriteLine("Calling IFoo.Foo on FooBar - expecting default method on IFoo.Foo. ");
        Test.Assert(foo.Foo(10) == 11, "Calling IFoo.Foo on FooBar");

        Console.WriteLine("Calling IBar.Bar on FooBar - expecting default method on IBar.Bar. ");
        Test.Assert(bar.Bar(10) == 20, "Calling IBar.Bar on FooBar");

        Console.WriteLine("Calling IBlah.Blah on FooBar - expecting default method on IBlah.Blah from Base. ");
        Test.Assert(blah.Blah(10) == 16, "Calling IBlah.Blah on FooBar");

        Console.WriteLine("Calling FooBar.CallBlahProtected - expecting protected methods on interface can be called");
        Test.Assert(fooBar.CallBlahProtected() == 3, "Calling FooBar.CallBlahProtected");

        return(Test.Ret());
    }
示例#5
0
 void IFoo.Foo()
 {
     WriteLine(nameof(Foo));
     _bar.Bar();
 }
示例#6
0
 public int Foo(string s)
 => _bar.Bar(s);