|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | using DurableTask.Core; |
| 5 | +using DurableTask.Core.Entities; |
5 | 6 | using Microsoft.Extensions.DependencyInjection; |
6 | 7 | using Microsoft.Extensions.Options; |
7 | 8 |
|
@@ -85,4 +86,139 @@ public void UseOrchestrationService_Callback_Sets() |
85 | 86 |
|
86 | 87 | options.Client.Should().Be(client); |
87 | 88 | } |
| 89 | + |
| 90 | + [Fact] |
| 91 | + public void EnableEntities_NoBackendSupport_Throws() |
| 92 | + { |
| 93 | + ServiceCollection services = new(); |
| 94 | + IOrchestrationServiceClient client = Mock.Of<IOrchestrationServiceClient>(); |
| 95 | + services.AddSingleton(client); |
| 96 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 97 | + |
| 98 | + builder.UseOrchestrationService(o => o.EnableEntitySupport = true); |
| 99 | + |
| 100 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 101 | + Action act = () => provider.GetOptions<ShimDurableTaskClientOptions>(); |
| 102 | + act.Should().ThrowExactly<OptionsValidationException>() |
| 103 | + .WithMessage("ShimDurableTaskClientOptions.Entities.Queries must not be null when entity support is enabled."); |
| 104 | + } |
| 105 | + |
| 106 | + [Fact] |
| 107 | + public void EnableEntities_BackendSupport_ExplicitProvider() |
| 108 | + { |
| 109 | + ServiceCollection services = new(); |
| 110 | + IOrchestrationServiceClient client = Mock.Of<IOrchestrationServiceClient>(); |
| 111 | + services.AddSingleton(client); |
| 112 | + Mock<EntityBackendQueries> mock = new(); |
| 113 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 114 | + |
| 115 | + builder.UseOrchestrationService(o => |
| 116 | + { |
| 117 | + o.EnableEntitySupport = true; |
| 118 | + o.Entities.Queries = mock.Object; |
| 119 | + }); |
| 120 | + |
| 121 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 122 | + provider.GetOptions<ShimDurableTaskClientOptions>(); // no-throw |
| 123 | + } |
| 124 | + |
| 125 | + [Fact] |
| 126 | + public void EnableEntities_BackendSupport_RegisteredService1() |
| 127 | + { |
| 128 | + ServiceCollection services = new(); |
| 129 | + IOrchestrationServiceClient client = Mock.Of<IOrchestrationServiceClient>(); |
| 130 | + services.AddSingleton(client); |
| 131 | + EntityBackendQueries queries = Mock.Of<EntityBackendQueries>(); |
| 132 | + services.AddSingleton(queries); |
| 133 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 134 | + |
| 135 | + builder.UseOrchestrationService(o => o.EnableEntitySupport = true ); |
| 136 | + |
| 137 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 138 | + ShimDurableTaskClientOptions options = provider.GetOptions<ShimDurableTaskClientOptions>(); |
| 139 | + options.Entities.Queries.Should().Be(queries); |
| 140 | + } |
| 141 | + |
| 142 | + [Fact] |
| 143 | + public void EnableEntities_BackendSupport_RegisteredService2() |
| 144 | + { |
| 145 | + ServiceCollection services = new(); |
| 146 | + Mock<IOrchestrationServiceClient> client = new(); |
| 147 | + EntityBackendQueries queries = Mock.Of<EntityBackendQueries>(); |
| 148 | + Mock<IEntityOrchestrationService> entities = client.As<IEntityOrchestrationService>(); |
| 149 | + entities.Setup(m => m.EntityBackendQueries).Returns(queries); |
| 150 | + services.AddSingleton(client.Object); |
| 151 | + |
| 152 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 153 | + |
| 154 | + builder.UseOrchestrationService(o => o.EnableEntitySupport = true); |
| 155 | + |
| 156 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 157 | + ShimDurableTaskClientOptions options = provider.GetOptions<ShimDurableTaskClientOptions>(); |
| 158 | + options.Entities.Queries.Should().Be(queries); |
| 159 | + } |
| 160 | + |
| 161 | + [Fact] |
| 162 | + public void EnableEntities_BackendSupport_RegisteredService3() |
| 163 | + { |
| 164 | + ServiceCollection services = new(); |
| 165 | + Mock<IOrchestrationServiceClient> client = new(); |
| 166 | + EntityBackendQueries queries = Mock.Of<EntityBackendQueries>(); |
| 167 | + Mock<IEntityOrchestrationService> entities = client.As<IEntityOrchestrationService>(); |
| 168 | + entities.Setup(m => m.EntityBackendQueries).Returns(queries); |
| 169 | + |
| 170 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 171 | + |
| 172 | + builder.UseOrchestrationService(o => |
| 173 | + { |
| 174 | + o.Client = client.Object; |
| 175 | + o.EnableEntitySupport = true; |
| 176 | + }); |
| 177 | + |
| 178 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 179 | + ShimDurableTaskClientOptions options = provider.GetOptions<ShimDurableTaskClientOptions>(); |
| 180 | + options.Entities.Queries.Should().Be(queries); |
| 181 | + } |
| 182 | + |
| 183 | + [Fact] |
| 184 | + public void EnableEntities_BackendSupport_RegisteredService4() |
| 185 | + { |
| 186 | + ServiceCollection services = new(); |
| 187 | + IOrchestrationServiceClient client = Mock.Of<IOrchestrationServiceClient>(); |
| 188 | + services.AddSingleton(client); |
| 189 | + |
| 190 | + EntityBackendQueries queries = Mock.Of<EntityBackendQueries>(); |
| 191 | + IEntityOrchestrationService entities = Mock.Of<IEntityOrchestrationService>(m => m.EntityBackendQueries == queries); |
| 192 | + services.AddSingleton(entities); |
| 193 | + |
| 194 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 195 | + |
| 196 | + builder.UseOrchestrationService(o => o.EnableEntitySupport = true); |
| 197 | + |
| 198 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 199 | + ShimDurableTaskClientOptions options = provider.GetOptions<ShimDurableTaskClientOptions>(); |
| 200 | + options.Entities.Queries.Should().Be(queries); |
| 201 | + } |
| 202 | + |
| 203 | + [Fact] |
| 204 | + public void EnableEntities_BackendSupport_RegisteredService5() |
| 205 | + { |
| 206 | + ServiceCollection services = new(); |
| 207 | + IOrchestrationServiceClient client = Mock.Of<IOrchestrationServiceClient>(); |
| 208 | + services.AddSingleton(client); |
| 209 | + |
| 210 | + EntityBackendQueries queries = Mock.Of<EntityBackendQueries>(); |
| 211 | + Mock<IOrchestrationService> orchestration = new(); |
| 212 | + Mock<IEntityOrchestrationService> entities = orchestration.As<IEntityOrchestrationService>(); |
| 213 | + entities.Setup(m => m.EntityBackendQueries).Returns(queries); |
| 214 | + services.AddSingleton(orchestration.Object); |
| 215 | + |
| 216 | + DefaultDurableTaskClientBuilder builder = new(null, services); |
| 217 | + |
| 218 | + builder.UseOrchestrationService(o => o.EnableEntitySupport = true); |
| 219 | + |
| 220 | + IServiceProvider provider = services.BuildServiceProvider(); |
| 221 | + ShimDurableTaskClientOptions options = provider.GetOptions<ShimDurableTaskClientOptions>(); |
| 222 | + options.Entities.Queries.Should().Be(queries); |
| 223 | + } |
88 | 224 | } |
0 commit comments