fix: InOrder() on a mock-less arrangement throws.

This commit is contained in:
Stefan Dragnev 2016-01-05 14:14:40 +02:00
Родитель 2ef85fc135
Коммит efeb455d46
3 изменённых файлов: 16 добавлений и 10 удалений

Просмотреть файл

@ -166,5 +166,11 @@ namespace Telerik.JustMock.Tests
void Save(); void Save();
void CommitChanges(); void CommitChanges();
} }
[TestMethod]
public void ShouldCreateInOrderArrangementOnNonMock()
{
Mock.Arrange(() => Arg.IsAny<List<string>>().Add("a")).InOrder();
}
} }
} }

Просмотреть файл

@ -23,7 +23,7 @@ namespace Telerik.JustMock.Core.Behaviors
{ {
internal class InOrderBehavior : IAssertableBehavior internal class InOrderBehavior : IAssertableBehavior
{ {
private readonly IMockMixin mock; private readonly MocksRepository repository;
private readonly int arrangementId; private readonly int arrangementId;
private readonly string message; private readonly string message;
private bool calledInWrongOrder = false; private bool calledInWrongOrder = false;
@ -34,29 +34,29 @@ namespace Telerik.JustMock.Core.Behaviors
get { return String.Format("{0}: in-order execution expectation. {1}", IsExpectationMet ? "Met" : "Unmet", this.message ?? ""); } get { return String.Format("{0}: in-order execution expectation. {1}", IsExpectationMet ? "Met" : "Unmet", this.message ?? ""); }
} }
public InOrderBehavior(IMockMixin mock, string message) public InOrderBehavior(MocksRepository repository, string message)
{ {
this.mock = mock; this.repository = repository;
this.arrangementId = InOrderArrangementCount++; this.arrangementId = InOrderArrangementCount++;
this.message = message; this.message = message;
} }
private int InOrderArrangementCount private int InOrderArrangementCount
{ {
get { return this.mock.Repository.GetValue<int>(typeof(InOrderBehavior), "count", 0); } get { return this.repository.GetValue<int>(typeof(InOrderBehavior), "count", 0); }
set { this.mock.Repository.StoreValue(typeof(InOrderBehavior), "count", value); } set { this.repository.StoreValue(typeof(InOrderBehavior), "count", value); }
} }
private int LastIdInOrder private int LastIdInOrder
{ {
get { return this.mock.Repository.GetValue<int>(typeof(InOrderBehavior), "id", -1); } get { return this.repository.GetValue<int>(typeof(InOrderBehavior), "id", -1); }
set { this.mock.Repository.StoreValue(typeof(InOrderBehavior), "id", value); } set { this.repository.StoreValue(typeof(InOrderBehavior), "id", value); }
} }
private string InOrderExecutionLog private string InOrderExecutionLog
{ {
get { return this.mock.Repository.GetValue<string>(typeof(InOrderBehavior), "log", null); } get { return this.repository.GetValue<string>(typeof(InOrderBehavior), "log", null); }
set { this.mock.Repository.StoreValue<string>(typeof(InOrderBehavior), "log", value); } set { this.repository.StoreValue<string>(typeof(InOrderBehavior), "log", value); }
} }
private string InOrderExecutionMessage private string InOrderExecutionMessage

Просмотреть файл

@ -400,7 +400,7 @@ namespace Telerik.JustMock.Expectations
{ {
return ProfilerInterceptor.GuardInternal(() => return ProfilerInterceptor.GuardInternal(() =>
{ {
this.behaviors.Add(new InOrderBehavior(this.Mock, message)); this.behaviors.Add(new InOrderBehavior(this.Repository, message));
return this; return this;
}); });
} }