Skip to content

Commit

Permalink
Adding repros for issues #26 and #31
Browse files Browse the repository at this point in the history
Incorrectly resolving arg matchers with default args (#31)
Reentrant setting of return values (#26)
Cleaned up code tokens from previous documentation approach.
  • Loading branch information
dtchepak committed Oct 12, 2010
1 parent 47e8379 commit 6724106
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
17 changes: 16 additions & 1 deletion Source/NSubstitute.Acceptance.Specs/ParameterMatching.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NSubstitute.Exceptions;
using NUnit.Framework;

namespace NSubstitute.Acceptance.Specs
{
Expand Down Expand Up @@ -106,6 +107,20 @@ public void Received_should_compare_elements_for_params_arguments()
_something.DidNotReceive().WithParams(1, Arg.Is<string[]>(x => x.Length > 3));
}

[Test]
[Pending]
public void Throw_with_ambiguous_arguments_when_given_an_arg_matcher_and_a_default_arg_value()
{
Assert.Throws<AmbiguousArgumentsException>(() =>
{
_something.Add(0, Arg.Any<int>()).Returns(1);
//Should not make it here, as it can't work out which arg the matcher refers to.
//If it does this will throw an AssertionException rather than AmbiguousArgumentsException.
Assert.That(_something.Add(0, 5), Is.EqualTo(1));
}
);
}

[Test]
[Pending]
public void Resolve_setter_arg_matcher_with_more_specific_type_than_member_signature()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace NSubstitute.Acceptance.Specs
[TestFixture]
public class SimpleSubstituteExamples
{
/* {CODE:Use_a_shiny_new_substitute} */
[Test]
public void Use_a_shiny_new_substitute()
{
Expand All @@ -23,7 +22,6 @@ public void Tell_a_substitute_to_return_a_value()
Assert.That(calculator.Add(1, 2), Is.EqualTo(3));
}

/* {CODE:Return_different_values_for_different_arguments} */
[Test]
public void Return_different_values_for_different_arguments()
{
Expand All @@ -45,7 +43,6 @@ public void Return_a_value_evaluated_at_runtime()
Assert.That(calculator.Add(-1, -2), Is.EqualTo(-3));
}

/* {CODE:Check_a_call_was_received} */
[Test]
public void Check_a_call_was_received()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,49 @@

namespace NSubstitute.Acceptance.Specs
{
[TestFixture]
public class SubstituteTimingAndInteractions
{
[Test]
public void Update_a_property_on_a_substitute_while_it_is_raising_an_event()
public class When_updating_a_property_on_a_sub_from_an_event_handler
{
var firstMate = Substitute.For<IICapn>();
firstMate.HoistTheMainSail += () => firstMate.IsMainSailHoisted = true;
public interface IICapn
{
event Action HoistTheMainSail;
bool IsMainSailHoisted { get; set; }
}

firstMate.HoistTheMainSail += Raise.Action();
Assert.That(firstMate.IsMainSailHoisted, Is.True);
}
[Test]
public void Should_update_the_property_when_the_event_is_raised()
{
var firstMate = Substitute.For<IICapn>();
firstMate.HoistTheMainSail += () => firstMate.IsMainSailHoisted = true;

public interface IICapn
firstMate.HoistTheMainSail += Raise.Action();
Assert.That(firstMate.IsMainSailHoisted, Is.True);
}
}

public class When_setting_the_return_value_of_one_sub_within_the_call_to_set_a_return_on_another
{
event Action HoistTheMainSail;
bool IsMainSailHoisted { get; set; }

public interface IWidget { string GetName(); }
public interface IWidgetFactory { IWidget CreateWidget(); }

[Test][Pending]
public void Should_set_both_calls_to_return_the_specified_values()
{
const string widgetName = "widget x";
var factory = Substitute.For<IWidgetFactory>();
factory.CreateWidget().Returns(CreateSubstituteForWidget(widgetName));

Assert.That(factory.CreateWidget().GetName(), Is.EqualTo(widgetName));
}

IWidget CreateSubstituteForWidget(string widgetName)
{
var widget = Substitute.For<IWidget>();
widget.GetName().Returns(widgetName);
return widget;
}
}
}
}

0 comments on commit 6724106

Please sign in to comment.