Guidance around testing workflow.GetItems(state)
Closed this issue · 9 comments
Howdy.
Can someone offer guidance on how to either augment the current fake data provider or to replace it?
Specifically I need a variant that implements GetItemsInWorkflowState(WorkflowInfo). I have a custom workflow that inherits from Simple Workflow which of course, was implemented so that I can't pass in an IWorkflowProvider otherwise I'd mock.
Thanks!
You can replace it with your own but it's not a simple config patch. Take a look at #146, for example.
Thanks @pveller. That was the path I was headed down but did not see how I could replace the provider. I'll do some more digging to determine that part.
@TimEllison, it's a little ugly but you can do it in code: #146 (comment)
@TimEllison, is there any need to override the data provider? If necessary, you can register a custom provider in the unit test App.config
file:
<databases>
<database id="master">
<dataProviders hint="list:AddDataProvider">
<dataProvider ref="dataProviders/custom" />
</dataProviders>
</database>
</databases>
<dataProviders>
<custom type="MyAssembly.CustomDataProvider, MyAssembly" />
</dataProviders>
AFAICS, the WorkflowProvider can be mocked without configuration changes. Please take a look on the following sample. Is that what you're looking for?
[Fact]
public void GetWorkflowSample()
{
var stateId = Guid.NewGuid().ToString();
var workflowProvider = Substitute.For<IWorkflowProvider>();
var extectedItems = new DataUri[0];
using (var db = new Db())
{
db.Database.WorkflowProvider = workflowProvider;
var item = db.GetItem("/sitecore/content");
workflowProvider.GetWorkflow(item).GetItems(stateId)
.Returns(extectedItems);
db.Database.WorkflowProvider
.GetWorkflow(item).GetItems(stateId)
.Should().BeSameAs(extectedItems);
}
}
Mocking is preferred. My impl subclasses the simple workflow impl. Sadly simple doesn't follow the interface.
Sent from my iPhone.
Tim Ellison
On Nov 21, 2016, at 4:30 PM, sergeyshushlyapin <notifications@github.commailto:notifications@github.com> wrote:
@TimEllisonhttps://github.com/TimEllison, is there any need to override the data provider? If necessary, you can register a custom provider in the unit test App.config file:
AFAICS, the WorkflowProvider can be mocked without configuration changes. Please take a look on the following sample. Is that what you're looking for?
[Fact]
public void GetWorkflowSample()
{
var stateId = Guid.NewGuid().ToString();
var workflowProvider = Substitute.For();
var extectedItems = new DataUri[0];
using (var db = new Db())
{
db.Database.WorkflowProvider = workflowProvider;
var item = db.GetItem("/sitecore/content");
workflowProvider.GetWorkflow(item).GetItems(stateId)
.Returns(extectedItems);
db.Database.WorkflowProvider
.GetWorkflow(item).GetItems(stateId)
.Should().BeSameAs(extectedItems);
}
}
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/150#issuecomment-262073126, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANJOMZj0FpUCdja3A0sTVM5XZC_DRzheks5rAg1TgaJpZM4K4gwH.
My impl subclasses the simple workflow impl. Sadly simple doesn't follow the interface.
@TimEllison, could you please bring a code sample to clarify your intentions? What the interface your implementation doesn't follow? Is it IWorkflow
or IWorkflowProvider
? Either of them can be mocked in a way that allows you use the 'extra' methods that does not exists in the abstraction (sample with NSubstitute):
var workflowProvider = Substitute.For<MyCustomWorkflowProvider, IWorkflowProvider>();
workflowProvider.MyCustomWorkflowProviderMethod();
Sergey. Thanks for the feedback/responses. I’m not thinking out of the box to solve this correctly. I just caught myself trying to mock something I should first isolate.
Tim Ellison
Senior Manager | CapTech
804.405.4874 | tellison@captechconsulting.commailto:tellison@captechconsulting.com
From: sergeyshushlyapin notifications@github.com
Reply-To: "sergeyshushlyapin/Sitecore.FakeDb" reply@reply.github.com
Date: Tuesday, November 22, 2016 at 3:01 AM
To: "sergeyshushlyapin/Sitecore.FakeDb" Sitecore.FakeDb@noreply.github.com
Cc: Tim Ellison TEllison@captechconsulting.com, Mention mention@noreply.github.com
Subject: Re: [sergeyshushlyapin/Sitecore.FakeDb] Guidance around testing workflow.GetItems(state) (#150)
My impl subclasses the simple workflow impl. Sadly simple doesn't follow the interface.
@TimEllisonhttps://github.com/TimEllison, could you please bring a code sample to clarify your intentions? What the interface your implementation doesn't follow? Is it IWorkflow or IWorkflowProvider? Either of them can be mocked in a way that allows you use the 'extra' methods that does not exists in the abstraction (sample with NSubstitutehttp://nsubstitute.github.io/):
var workflowProvider = Substitute.For<MyCustomWorkflowProvider, IWorkflowProvider>();
workflowProvider.MyCustomWorkflowProviderMethod();
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/150#issuecomment-262172418, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANJOMZ5arHnmLFlBr8tLzanVE4KyjqtGks5rAqE-gaJpZM4K4gwH.
Does it mean the issue can be closed now?
Yes sir!
Tim Ellison
Senior Manager | CapTech
804.405.4874 | tellison@captechconsulting.commailto:tellison@captechconsulting.com
From: sergeyshushlyapin notifications@github.com
Reply-To: "sergeyshushlyapin/Sitecore.FakeDb" reply@reply.github.com
Date: Tuesday, November 22, 2016 at 9:32 AM
To: "sergeyshushlyapin/Sitecore.FakeDb" Sitecore.FakeDb@noreply.github.com
Cc: Tim Ellison TEllison@captechconsulting.com, Mention mention@noreply.github.com
Subject: Re: [sergeyshushlyapin/Sitecore.FakeDb] Guidance around testing workflow.GetItems(state) (#150)
Does it mean the issue can be closed now?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/150#issuecomment-262255584, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ANJOMePq_544C_DhqbMaGGmY0Kh6ccvpks5rAv0WgaJpZM4K4gwH.