public static void MultipleCallbacks( IFoo fake, bool firstWasCalled, bool secondWasCalled, int returnValue) { "establish" .x(() => fake = A.Fake<IFoo>()); "when configuring multiple callback" .x(() => { A.CallTo(() => fake.Baz()) .Invokes(x => firstWasCalled = true) .Invokes(x => secondWasCalled = true) .Returns(10); returnValue = fake.Baz(); }); "it should call the first callback" .x(() => firstWasCalled.Should().BeTrue()); "it should call the second callback" .x(() => secondWasCalled.Should().BeTrue()); "it should return the configured value" .x(() => returnValue.Should().Be(10)); }
public void Setup() { this.faked = A.Fake<IFoo>(); IFoo wrapped = A.Fake<IFoo>(); this.wrapperConfigurator = new FakeWrapperConfigurator<IFoo>(A.Fake<IFakeOptionsBuilder<IFoo>>(), wrapped); }
public static void MatchingCallsWithMatches( IFoo fake, IEnumerable<ICompletedFakeObjectCall> completedCalls, IEnumerable<ICompletedFakeObjectCall> matchedCalls) { "Given a Fake" .x(() => fake = A.Fake<IFoo>()); "And I make several calls to the Fake" .x(() => { fake.AMethod(); fake.AnotherMethod(); fake.AnotherMethod("houseboat"); }); "And I use the static Fake class to get the calls made on the Fake" .x(() => completedCalls = Fake.GetCalls(fake)); "When I use Matching to find calls to a method with a match" .x(() => matchedCalls = completedCalls.Matching<IFoo>(c => c.AnotherMethod("houseboat"))); "Then it finds the matching call" .x(() => matchedCalls.Select(c => c.Method.Name).Should().Equal("AnotherMethod")); }
public void Setup() { this.faked = A.Fake<IFoo>(); IFoo wrapped = A.Fake<IFoo>(); this.wrapperConfigurator = new FakeWrapperConfigurator(wrapped); }
public BarWithMultipleParameters(IFoo parameter1, string parameter2, string parameter3, int parameter4) { Parameter1 = parameter1; Parameter2 = parameter2; Parameter3 = parameter3; Parameter4 = parameter4; }
public static void MultistepOrderedAssertionsInOrder( IFoo fake, Exception exception, IOrderableCallAssertion lastAssertion) { "Given a Fake" .x(() => fake = A.Fake<IFoo>()); "And a call on the Fake, passing argument 1" .x(() => fake.Bar(1)); "And a call on the Fake, passing argument 2" .x(() => fake.Bar(2)); "And a call on the Fake, passing argument 2" .x(() => fake.Bar(2)); "And a call on the Fake, passing argument 3" .x(() => fake.Bar(3)); "When I assert that a call with argument 1 was made exactly once" .x(() => lastAssertion = A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once)); "And then a call with argument 2" .x(() => lastAssertion = lastAssertion.Then(A.CallTo(() => fake.Bar(2)).MustHaveHappened())); "And then a call with argument 3 exactly once" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(3)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the assertions should pass" .x(() => exception.Should().BeNull()); }
public void VoidMethodWithInvokes( IFoo foo, Action action1, Action action2) { "Given a fake" .x(() => foo = A.Fake<IFoo>()); "And two delegates" .x(() => { action1 = A.Fake<Action>(); action2 = A.Fake<Action>(); }); "When a void method is configured to invoke a delegate once then invoke another delegate" .x(() => A.CallTo(() => foo.Bar()).Invokes(action1).DoesNothing().Once() .Then.Invokes(action2)); "And the method is called 3 times" .x(() => { foo.Bar(); foo.Bar(); foo.Bar(); }); "Then the first delegate is invoked once, and the second delegate is invoked twice" .x(() => A.CallTo(() => action1()).MustHaveHappened(Repeated.Exactly.Once) .Then(A.CallTo(() => action2()).MustHaveHappened(Repeated.Exactly.Twice))); }
public void VoidMethodWithThrows( IFoo foo, Action action, Exception exception) { "Given a fake" .x(() => foo = A.Fake<IFoo>()); "And an action" .x(() => action = A.Fake<Action>()); "When a void method is configured to invoke a delegate twice then throw an exception" .x(() => A.CallTo(() => foo.Bar()).Invokes(action).DoesNothing().Twice() .Then.Throws<InvalidOperationException>()); "And the method is called 3 times" .x(() => { foo.Bar(); foo.Bar(); exception = Record.Exception(() => foo.Bar()); }); "Then the delegate is invoked twice" .x(() => A.CallTo(() => action()).MustHaveHappened(Repeated.Exactly.Twice)); "And the third call throws an exception" .x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>()); }
public static void Serialize(IFoo h) { Point point1 = new Point (0, 1); Point? point2 = new Point (1, 2); h.Foo (ref point1); h.Foo (ref point2); }
public void SetUp() { this.foo = A.Fake<IFoo>(); this.foo.SomethingHappened += new EventHandler(this.Foo_SomethingHappened); this.sender = null; this.eventArguments = null; }
public FakeWrapperConfiguratorTests() { this.faked = A.Fake<IFoo>(); IFoo wrapped = A.Fake<IFoo>(); this.wrapperConfigurator = new FakeWrapperConfigurator<IFoo>(A.Fake<IFakeOptions<IFoo>>(), wrapped); }
private double Run(IFoo foo) { double sum = 0; for (int i = 0; i < 1001; i++) sum += foo.Inc(0); return sum; }
public RaiseTests() { this.foo = A.Fake<IFoo>(); this.foo.SomethingHappened += this.Foo_SomethingHappened; this.sender = null; this.eventArguments = null; }
public void Setup() { this.foo = A.Fake<IFoo>(); this.foo.SomethingHappened += this.Foo_SomethingHappened; this.sender = null; this.eventArguments = null; }
public static void MultipleCallbacks( IFoo fake, bool firstWasCalled, bool secondWasCalled, int returnValue) { "Given a fake" .x(() => fake = A.Fake<IFoo>()); "And I configure a method to invoke two actions and return a value" .x(() => A.CallTo(() => fake.Baz()) .Invokes(x => firstWasCalled = true) .Invokes(x => secondWasCalled = true) .Returns(10)); "When I call the method" .x(() => returnValue = fake.Baz()); "Then it calls the first callback" .x(() => firstWasCalled.Should().BeTrue()); "And it calls the first callback" .x(() => secondWasCalled.Should().BeTrue()); "And it returns the configured value" .x(() => returnValue.Should().Be(10)); }
public PingHub(ILifetimeScope lifetimeScope) { // Create a lifetime scope for this hub instance. _hubLifetimeScope = lifetimeScope.BeginLifetimeScope(); // Resolve the dependencies from the hub lifetime scope (unfortunately, service locator style). _bar = _hubLifetimeScope.Resolve<IBar>(); _foo = _hubLifetimeScope.Resolve<IFoo>(); }
public static void Method1(GetString f, IFoo foo) { Console.WriteLine("Method1"); Console.WriteLine("foo: " + foo.Invoke1("clr")); Console.WriteLine("GetString: " + f()); Console.WriteLine("GetString: " + f()); Console.WriteLine("GetString: " + f()); }
public Bastard(IFoo foo) { if (foo == null) { throw new ArgumentNullException(nameof(foo)); } this.foo = foo; }
public FooBar(IFoo f, IBar b) { if (f == null) throw new ArgumentNullException("f"); if (b == null) throw new ArgumentNullException("b"); Foo = f; Bar = b; }
public void Write(string msg) { Logger.Write("Trace: FooInterfaceProxy.Write enter."); if(_foo == null) { Logger.Write("Trace: Creating new Foo"); _foo = new Foo(Logger); } _foo.Write(msg); Logger.Write("Trace: FooInterfaceProxy.Write exit.\n"); }
public override void Context() { _routerForSubstitute = mock<ICallRouter>(); _substitute = mock<IFoo>(); _context = mock<ISubstitutionContext>(); _context.stub(x => x.GetCallRouterFor(_substitute)).Return(_routerForSubstitute); temporarilyChange(() => SubstitutionContext.Current).to(_context); }
public void WithEmpty_should_return_raise_object_with_event_args_empty_set() { // Arrange this.foo = A.Fake<IFoo>(); this.foo.SomethingHappened += this.Foo_SomethingHappened; // Act this.foo.SomethingHappened += Raise.WithEmpty(); // Assert this.eventArguments.Should().Be(EventArgs.Empty); }
public override void Context() { _sub = mock<IFoo>(); _substitutionContext = mock<ISubstitutionContext>(); _callRouter = mock<ICallRouter>(); _substitutionContext.stub(x => x.GetCallRouterFor(_sub)) .IgnoreArguments() .Return(_callRouter); _callRouter.stub(x => x.SetReturnForType(It.IsAny<Type>(), It.IsAny<IReturn>())) .IgnoreArguments() .WhenCalled(x => _returnValueSet = (IReturn)x.Arguments[1]); temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext); }
public static void WithNonVoidReturnType(IFoo fake) { "Given a fake with a generic method" .x(() => fake = A.Fake<IFoo>()); "When the fake's generic method is configured to return null for any non-void return type" .x(() => A.CallTo(fake).Where(call => call.Method.Name == "Bar").WithNonVoidReturnType().Returns(null)); "Then the configured method returns null when called with generic argument String" .x(() => fake.Bar<string>().Should().BeNull()); "And the configured method returns null when called with generic argument IFoo" .x(() => fake.Bar<IFoo>().Should().BeNull()); }
public void Setup() { this.fakedObject = A.Fake<IFoo>(); this.fakeObject = Fake.GetFakeManager(this.fakedObject); this.recordedRule = A.Fake<RecordedCallRule>(x => x.WithArgumentsForConstructor(() => new RecordedCallRule(A.Fake<MethodInfoManager>()))); this.callFormatter = A.Fake<IFakeObjectCallFormatter>(); this.asserter = A.Fake<IFakeAsserter>(); this.asserterFactory = x => { this.argumentUsedForAsserterFactory = x; return this.asserter; }; }
public static void WithReturnType( IFoo fake, string returnValue) { "Given a fake with a generic method" .x(() => fake = A.Fake<IFoo>()); "When the fake's generic method is configured to return a specific value for a given return type" .x(() => A.CallTo(fake).Where(call => call.Method.Name == "Bar").WithReturnType<string>().Returns(returnValue = "hello world")); "Then the configured method returns the specified value when called with generic argument String" .x(() => fake.Bar<string>().Should().Be(returnValue)); "And the configured method returns a dummy when called with generic argument IFoo" .x(() => fake.Bar<IFoo>().Should().NotBeNull().And.BeAssignableTo<IFoo>()); }
public static void Callback( IFoo fake, bool wasCalled) { "Given a fake" .x(() => fake = A.Fake<IFoo>()); "And I configure a method to invoke an action" .x(() => A.CallTo(() => fake.Bar()).Invokes(x => wasCalled = true)); "When I call the method" .x(() => fake.Bar()); "Then it invokes the action" .x(() => wasCalled.Should().BeTrue()); }
public static void Callback( IFoo fake, bool wasCalled) { "establish" .x(() => fake = A.Fake<IFoo>()); "when configuring callback" .x(() => { A.CallTo(() => fake.Bar()).Invokes(x => wasCalled = true); fake.Bar(); }); "it should invoke the callback" .x(() => wasCalled.Should().BeTrue()); }
public void CanceledTokenPassedAsObject( IFoo fake, CancellationToken cancellationToken, int result) { "Given a fake" .x(() => fake = A.Fake<IFoo>()); "And a cancellation token that is canceled" .x(() => cancellationToken = new CancellationToken(true)); "When a method is called with this cancellation token passed as Object" .x(() => result = fake.Bar((object)cancellationToken)); "Then it doesn't throw and returns the default value" .x(() => result.Should().Be(0)); }
public void NoResultPassExceptionFactoryWithCallArg(IFoo fake, Task task) { "Given a fake" .x(() => fake = A.Fake<IFoo>()); "And an async method of the fake configured to throw asynchronously" .x(() => A.CallTo(() => fake.BarAsync()).ThrowsAsync(call => new MyException())); "When that method is called" .x(() => { task = fake.BarAsync(); }); "Then it returns a failed task" .x(() => task.Status.Should().Be(TaskStatus.Faulted)); "And the task's exception is the configured exception" .x(() => task.Exception?.InnerException.Should().BeAnExceptionOfType<MyException>()); }
public DecoratedFoo(IFoo <T1, T2> inner) { _inner = inner; }
static void Main(string[] args) { Show show = Hi; //переменная делегата с адресом метода show(); int price = 1000; int age = 0; string name = ""; try { Console.WriteLine("What is your name?"); name = Console.ReadLine(); Console.WriteLine("How old are you?"); age = int.Parse(Console.ReadLine()); } catch (FormatException) //обработка исключения { Console.WriteLine("\nError: in the field \"age\" you did not enter a number!"); } Console.WriteLine("Your garage:"); Car car1 = new Car("Mercedes-Benz W124", 306, price); Car car2 = new Car("Mercedes-Benz W", 224, price); Car car3 = new Car("Tesla Model X", 250, price); Car car4 = new Car("TeslaModel S", 200, price); IFoo foo = car1; foo.GetInfo(); IFoo foo2 = car2; foo2.GetInfo(); IFoo foo3 = car3; foo3.GetInfo(); IFoo foo4 = car4; foo4.GetInfo(); PriceList pricelist = new PriceList(); pricelist.Notify += delegate (string mes) //анонимный метод в качестве обработчика события { Console.WriteLine(mes); }; MenuHandler menu = message => Console.WriteLine(message); //лямбда-выражения menu("\t\t\t\t\t\tMenu"); menu("\t\t\t1. Enter 1 if you want to compare the speed of Mercedes."); menu("\t\t\t2. Enter 2 if you want to compare the speed of Tesla."); menu("\t\t\t3. Enter 3 if you want to increase the price of your car collection."); menu("\t\t\t4. Enter 4 if you want to sort cars by maximum speed."); int otvet1 = Convert.ToInt32(Console.ReadLine()); Console.Clear(); switch (otvet1) { case 1: { CarComparison carComparison = new CarComparison(); Console.WriteLine("Compare the speed of Mercedes: "); carComparison.SpeedComparison(car1, car2); break; } case 2: { CarComparison carComparison = new CarComparison(); Console.WriteLine("Compare the speed of Tesla: "); carComparison.SpeedComparison(car3, car4); break; } case 3: { pricelist.Price(price); Console.WriteLine($"How much do you want to raise the price?"); int increase = Convert.ToInt32(Console.ReadLine()); pricelist.Increase(increase); Console.WriteLine($"Done, now all your cars cost: {pricelist.newprice}"); break; } case 4: { pricelist.Price(price); Console.WriteLine($"На сколько вы хотите понизить зарплату работникам команды?"); int reduce = Convert.ToInt32(Console.ReadLine()); pricelist.Reduce(reduce); Console.WriteLine($"Done, now all your cars cost: {pricelist.newprice}"); break; } case 5: { Car[] cars = new Car[] { car1, car2, car3, car4 }; Array.Sort(cars); foreach (Car c in cars) { Console.WriteLine(c._mark + "(" + c.technicalproperties.Speed + ")"); } break; } } show -= Hi; //-обработчик show += Bye; //+обработчик show(); //вызов метода }
public FooDecorator(IFoo <T> foo) { }
public FooDecoratorWithDependency(IFoo foo, IBar bar) { Foo = foo; Bar = bar; }
public ClosedGenericFooDecorator(IFoo <int> foo) { }
private void Prepare([Value("@(CiaoFoo)")] IFoo ciao) { this.ciao = ciao; }
public FooWithRecursiveDependency(IFoo foo) { }
private void Prepare([Dialect(Language = "Italian")] IFoo ciao) { this.ciao = ciao; }
public AutowireTestConstructorNormal([Dialect(Language = "Italian")] IFoo ciao) { this.ciao = ciao; }
public AutowireTestConstructorNormal([Qualifier("ciao")] IFoo ciao) { this.ciao = ciao; }
private void Prepare([Qualifier("ciao")] IFoo ciao) { this.ciao = ciao; }
public ValuesController(IFoo baseRepository) { _baseRepository = baseRepository; }
public void SetUp() { _sub = Substitute.For <IFoo>(); }
public AutowireTestConstructorNormal([Value("@(CiaoFoo)")] IFoo ciao) { this.ciao = ciao; }
public HalfClosedOpenGenericFooDecorator(IFoo <string, T> foo) { }
public AutowireTestConstructorNormal(IFoo hello) { this.hello = hello; }
public FooDecoratorWithDependencyFirst(IBar bar, IFoo foo) { Foo = foo; Bar = bar; }
private void Prepare(IFoo hello) { this.hello = hello; }
public AnotherFooDecorator(IFoo <T> foo) { }
public static void SomeMethod(this IFoo foo) { foo.SomeMethod(0); }
public FooDecoratorWithClassConstraint(IFoo <T> foo) { }
public Sut(IFoo foo) { this.foo = foo; }
private static void Parameters(IFoo foo, IBar bar, IBaz baz) { }
public void World <U> (U u, IFoo <U> foo) { }
public void Configure(IApplicationBuilder app, IFoo foo) { foo.Bar(); }
public void DoBarFoo(IFoo foo) { _bar.DoFoo(foo); }
string IFoo.this[string p, IFoo p2] { get { return(p); } set { } }
public static void Say(this IFoo foo) { Console.WriteLine("Extension method"); }
static void SomeMethod(long a, long b, out IFoo c) { c = new Foo(a, b); }
public void World <V> (IFoo <V> foo) { }