private static void AddFakeRule <T>(T fakedObject, Action <FakeCallRule> ruleConfiguration) where T : class { var rule = new FakeCallRule(); ruleConfiguration(rule); AddFakeRule(fakedObject, rule); }
public void The_first_applicable_interceptor_should_be_called_when_it_has_not_been_used() { var fake = this.CreateFakeManager <IFoo>(); var interception = new FakeCallRule { IsApplicableTo = x => true }; fake.AddRuleFirst(NonApplicableInterception); fake.AddRuleFirst(interception); ((IFoo)fake.Object).Bar(); interception.ApplyWasCalled.Should().BeTrue(); }
public void The_first_applicable_interceptor_should_be_called_when_it_has_not_been_used() { var fake = this.CreateFakeObject <IFoo>(); var interception = new FakeCallRule { IsApplicableTo = x => true }; fake.AddRule(NonApplicableInterception); fake.AddRule(interception); ((IFoo)fake.Object).Bar(); Assert.That(interception.ApplyWasCalled, Is.True); }
public void The_first_interceptor_should_be_applied_when_it_has_not_been_used() { var fake = new FakeObject(typeof(IFoo)); var interception = new FakeCallRule { IsApplicableTo = x => true }; fake.AddRule(interception); // Act ((IFoo)fake.Object).Bar(); Assert.That(interception.ApplyWasCalled, Is.True); }
public void Adding_last_rule_to_scope_affects_all_calles_in_scope() { // Arrange var fake1 = A.Fake<IFoo>(); var fake2 = A.Fake<IFoo>(); var ruleLast = new FakeCallRule() { IsApplicableTo = x => true }; // Act using (var scope = Fake.CreateScope()) { scope.AddScopeRuleLast(ruleLast); fake1.Bar(); } // Assert Assert.That(ruleLast.ApplyWasCalled, Is.True); }
public void Adding_rule_to_scope_affects_calles_in_nested_scope() { // Arrange var fake1 = A.Fake<IFoo>(); var rule = new FakeCallRule() { IsApplicableTo = x => true }; // Act using (var scope = Fake.CreateScope()) { scope.AddScopeRuleFirst(rule); using (Fake.CreateScope()) { fake1.Bar(); } } // Assert Assert.That(rule.ApplyWasCalled, Is.True); }
public void An_applicable_action_should_be_called_its_specified_number_of_times_before_the_next_applicable_action_is_called() { var fake = this.CreateFakeManager <IFoo>(); var applicableTwice = new FakeCallRule { IsApplicableTo = x => true, NumberOfTimesToCall = 2 }; var nextApplicable = CreateApplicableInterception(); fake.AddRuleFirst(nextApplicable); fake.AddRuleFirst(applicableTwice); ((IFoo)fake.Object).Bar(); ((IFoo)fake.Object).Bar(); nextApplicable.ApplyWasCalled.Should().BeFalse(); ((IFoo)fake.Object).Bar(); nextApplicable.ApplyWasCalled.Should().BeTrue(); }
public void An_applicable_action_should_be_called_its_specified_number_of_times_before_the_next_applicable_action_is_called() { var fake = new FakeObject(typeof(IFoo)); var applicableTwice = new FakeCallRule { IsApplicableTo = x => true, NumberOfTimesToCall = 2 }; var nextApplicable = CreateApplicableInterception(); fake.AddRule(nextApplicable); fake.AddRule(applicableTwice); ((IFoo)fake.Object).Bar(); ((IFoo)fake.Object).Bar(); Assert.That(nextApplicable.ApplyWasCalled, Is.False); ((IFoo)fake.Object).Bar(); Assert.That(nextApplicable.ApplyWasCalled, Is.True); }
public void Adding_first_rule_to_scope_affects_all_calles_in_scope() { // Arrange var fake1 = A.Fake<IFoo>(); var fake2 = A.Fake<IFoo>(); int applyCalledNumber = 0; var ruleFirst = new FakeCallRule() { IsApplicableTo = x => true, Apply = x => applyCalledNumber++ }; var ruleLast = new FakeCallRule() { IsApplicableTo = x => true }; // Act using (var scope = Fake.CreateScope()) { scope.AddScopeRuleFirst(ruleFirst); scope.AddScopeRuleLast(ruleLast); fake1.Bar(); fake2.Bar(); } // Assert Assert.That(ruleFirst.ApplyWasCalled, Is.True); Assert.That(ruleLast.ApplyWasCalled, Is.False); Assert.That(applyCalledNumber, Is.EqualTo(2)); }
private static void AddFakeRule <T>(T fakedObject, FakeCallRule rule) where T : class { Fake.GetFakeObject(fakedObject).AddRule(rule); }
private static void AddFakeRule <T>(T fakedObject, FakeCallRule rule) where T : class { Fake.GetFakeManager(fakedObject).AddRuleFirst(rule); }
public void Adding_rule_to_scope_does_not_affect_calles_out_of_scope() { // Arrange var fake1 = A.Fake<IFoo>(); var rule = new FakeCallRule() { IsApplicableTo = x => true }; // Act using (var scope = Fake.CreateScope()) { scope.AddScopeRuleFirst(rule); } fake1.Bar(); // Assert Assert.That(rule.ApplyWasCalled, Is.False); }