Skip to content

Commit f455477

Browse files
committed
Added Unittests for WorkflowRegistry
1 parent 18a7642 commit f455477

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using FakeItEasy;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
using WorkflowCore.Interface;
8+
using WorkflowCore.Models;
9+
using WorkflowCore.Services;
10+
using FluentAssertions;
11+
using Xunit;
12+
using WorkflowCore.Primitives;
13+
using System.Linq.Expressions;
14+
using System.Threading.Tasks;
15+
16+
namespace WorkflowCore.UnitTests.Services
17+
{
18+
public class WorkflowRegistryFixture
19+
{
20+
protected IServiceProvider ServiceProvider { get; }
21+
protected WorkflowRegistry Subject { get; }
22+
protected WorkflowDefinition Definition { get; }
23+
24+
public WorkflowRegistryFixture()
25+
{
26+
ServiceProvider = A.Fake<IServiceProvider>();
27+
Subject = new WorkflowRegistry(ServiceProvider);
28+
29+
Definition = new WorkflowDefinition{
30+
Id = "TestWorkflow",
31+
Version = 1,
32+
};
33+
Subject.RegisterWorkflow(Definition);
34+
}
35+
36+
[Fact(DisplayName = "Should return existing workflow")]
37+
public void getdefinition_should_return_existing_workflow()
38+
{
39+
Subject.GetDefinition(Definition.Id).Should().Be(Definition);
40+
Subject.GetDefinition(Definition.Id, Definition.Version).Should().Be(Definition);
41+
}
42+
43+
[Fact(DisplayName = "Should return null on unknown workflow")]
44+
public void getdefinition_should_return_null_on_unknown()
45+
{
46+
Subject.GetDefinition("UnkownWorkflow").Should().BeNull();
47+
Subject.GetDefinition("UnkownWorkflow", 1).Should().BeNull();
48+
}
49+
50+
[Fact(DisplayName = "Should return highest version of existing workflow")]
51+
public void getdefinition_should_return_highest_version_workflow()
52+
{
53+
var definition2 = new WorkflowDefinition{
54+
Id = Definition.Id,
55+
Version = Definition.Version + 1,
56+
};
57+
Subject.RegisterWorkflow(definition2);
58+
59+
Subject.GetDefinition(Definition.Id).Should().Be(definition2);
60+
Subject.GetDefinition(Definition.Id, definition2.Version).Should().Be(definition2);
61+
Subject.GetDefinition(Definition.Id, Definition.Version).Should().Be(Definition);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)