From efeb455d46bd88dac2edea2cc403c3ee3a488a0d Mon Sep 17 00:00:00 2001 From: Stefan Dragnev Date: Tue, 5 Jan 2016 14:14:40 +0200 Subject: [PATCH] fix: InOrder() on a mock-less arrangement throws. --- Telerik.JustMock.Tests/InOrderFixture.cs | 6 ++++++ .../Core/Behaviors/InOrderBehavior.cs | 18 +++++++++--------- .../Expectations/CommonExpectation.cs | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Telerik.JustMock.Tests/InOrderFixture.cs b/Telerik.JustMock.Tests/InOrderFixture.cs index c0c80ce..573a5b8 100644 --- a/Telerik.JustMock.Tests/InOrderFixture.cs +++ b/Telerik.JustMock.Tests/InOrderFixture.cs @@ -166,5 +166,11 @@ namespace Telerik.JustMock.Tests void Save(); void CommitChanges(); } + + [TestMethod] + public void ShouldCreateInOrderArrangementOnNonMock() + { + Mock.Arrange(() => Arg.IsAny>().Add("a")).InOrder(); + } } } diff --git a/Telerik.JustMock/Core/Behaviors/InOrderBehavior.cs b/Telerik.JustMock/Core/Behaviors/InOrderBehavior.cs index 7782c20..251f38b 100644 --- a/Telerik.JustMock/Core/Behaviors/InOrderBehavior.cs +++ b/Telerik.JustMock/Core/Behaviors/InOrderBehavior.cs @@ -23,7 +23,7 @@ namespace Telerik.JustMock.Core.Behaviors { internal class InOrderBehavior : IAssertableBehavior { - private readonly IMockMixin mock; + private readonly MocksRepository repository; private readonly int arrangementId; private readonly string message; 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 ?? ""); } } - public InOrderBehavior(IMockMixin mock, string message) + public InOrderBehavior(MocksRepository repository, string message) { - this.mock = mock; + this.repository = repository; this.arrangementId = InOrderArrangementCount++; this.message = message; } private int InOrderArrangementCount { - get { return this.mock.Repository.GetValue(typeof(InOrderBehavior), "count", 0); } - set { this.mock.Repository.StoreValue(typeof(InOrderBehavior), "count", value); } + get { return this.repository.GetValue(typeof(InOrderBehavior), "count", 0); } + set { this.repository.StoreValue(typeof(InOrderBehavior), "count", value); } } private int LastIdInOrder { - get { return this.mock.Repository.GetValue(typeof(InOrderBehavior), "id", -1); } - set { this.mock.Repository.StoreValue(typeof(InOrderBehavior), "id", value); } + get { return this.repository.GetValue(typeof(InOrderBehavior), "id", -1); } + set { this.repository.StoreValue(typeof(InOrderBehavior), "id", value); } } private string InOrderExecutionLog { - get { return this.mock.Repository.GetValue(typeof(InOrderBehavior), "log", null); } - set { this.mock.Repository.StoreValue(typeof(InOrderBehavior), "log", value); } + get { return this.repository.GetValue(typeof(InOrderBehavior), "log", null); } + set { this.repository.StoreValue(typeof(InOrderBehavior), "log", value); } } private string InOrderExecutionMessage diff --git a/Telerik.JustMock/Expectations/CommonExpectation.cs b/Telerik.JustMock/Expectations/CommonExpectation.cs index 315f05f..74b1ef4 100644 --- a/Telerik.JustMock/Expectations/CommonExpectation.cs +++ b/Telerik.JustMock/Expectations/CommonExpectation.cs @@ -400,7 +400,7 @@ namespace Telerik.JustMock.Expectations { return ProfilerInterceptor.GuardInternal(() => { - this.behaviors.Add(new InOrderBehavior(this.Mock, message)); + this.behaviors.Add(new InOrderBehavior(this.Repository, message)); return this; }); }