public byte Foo() { byte[] bars = _bar.Bar(); byte foo = bars.Max(); return(foo); }
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()); }
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ı }
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()); }
void IFoo.Foo() { WriteLine(nameof(Foo)); _bar.Bar(); }
public int Foo(string s) => _bar.Bar(s);