diff --git a/src/Altinn.App.Core/Features/Telemetry/Telemetry.Instances.cs b/src/Altinn.App.Core/Features/Telemetry/Telemetry.Instances.cs
index 7bb4dc2cc..8925c154d 100644
--- a/src/Altinn.App.Core/Features/Telemetry/Telemetry.Instances.cs
+++ b/src/Altinn.App.Core/Features/Telemetry/Telemetry.Instances.cs
@@ -76,10 +76,11 @@ internal void InstanceDeleted(Instance instance)
return activity;
}
- internal Activity? StartUpdateProcessActivity(Instance instance)
+ internal Activity? StartUpdateProcessActivity(Instance instance, int eventCount = 0)
{
var activity = ActivitySource.StartActivity($"{Prefix}.UpdateProcess");
activity?.SetInstanceId(instance);
+ activity?.SetTag(Labels.InstanceEventsCount, eventCount);
return activity;
}
diff --git a/src/Altinn.App.Core/Features/Telemetry/Telemetry.cs b/src/Altinn.App.Core/Features/Telemetry/Telemetry.cs
index 6732e0894..f0bf97423 100644
--- a/src/Altinn.App.Core/Features/Telemetry/Telemetry.cs
+++ b/src/Altinn.App.Core/Features/Telemetry/Telemetry.cs
@@ -126,6 +126,11 @@ public static class Labels
///
public static readonly string InstanceGuid = "instance.guid";
+ ///
+ /// Label for the guid that identifies the instance.
+ ///
+ public static readonly string InstanceEventsCount = "instance.events.count";
+
///
/// Label for the guid that identifies the data.
///
diff --git a/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs b/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
index 4735935dd..085c83933 100644
--- a/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
+++ b/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
@@ -162,6 +162,39 @@ public async Task UpdateProcess(Instance instance)
}
}
+ ///
+ public async Task UpdateProcessAndEvents(Instance instance, List events)
+ {
+ using var activity = _telemetry?.StartUpdateProcessActivity(instance, events.Count);
+ ProcessState processState = instance.Process;
+
+ foreach (var instanceEvent in events)
+ instanceEvent.InstanceId = instance.Id;
+
+ string apiUrl = $"instances/{instance.Id}/process/instanceandevents";
+ string token = _userTokenProvider.GetUserToken();
+
+ var update = new ProcessStateUpdate { State = processState, Events = events };
+ string updateString = JsonConvert.SerializeObject(update);
+ _logger.LogInformation($"update process state: {updateString}");
+
+ StringContent httpContent = new(updateString, Encoding.UTF8, "application/json");
+ HttpResponseMessage response = await _client.PutAsync(token, apiUrl, httpContent);
+ if (response.StatusCode == HttpStatusCode.OK)
+ {
+ string instanceData = await response.Content.ReadAsStringAsync();
+ Instance updatedInstance =
+ JsonConvert.DeserializeObject(instanceData)
+ ?? throw new Exception("Could not deserialize instance");
+ return updatedInstance;
+ }
+ else
+ {
+ _logger.LogError($"Unable to update instance process with instance id {instance.Id}");
+ throw await PlatformHttpException.CreateAsync(response);
+ }
+ }
+
///
public async Task CreateInstance(string org, string app, Instance instanceTemplate)
{
diff --git a/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs b/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs
index b83a67096..9c1fecc0f 100644
--- a/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs
+++ b/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs
@@ -29,6 +29,11 @@ public interface IInstanceClient
///
Task UpdateProcess(Instance instance);
+ ///
+ /// Updates the process model of the instance and the instance events and returns the updated instance.
+ ///
+ Task UpdateProcessAndEvents(Instance instance, List events);
+
///
/// Creates an instance of an application with no data.
///
diff --git a/src/Altinn.App.Core/Internal/Process/ProcessEventDispatcher.cs b/src/Altinn.App.Core/Internal/Process/ProcessEventDispatcher.cs
index 5225b0105..c7844fe83 100644
--- a/src/Altinn.App.Core/Internal/Process/ProcessEventDispatcher.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessEventDispatcher.cs
@@ -13,7 +13,6 @@ namespace Altinn.App.Core.Internal.Process;
public class ProcessEventDispatcher : IProcessEventDispatcher
{
private readonly IInstanceClient _instanceClient;
- private readonly IInstanceEventClient _instanceEventClient;
private readonly IEventsClient _eventsClient;
private readonly IOptions _appSettings;
private readonly ILogger _logger;
@@ -23,14 +22,12 @@ public class ProcessEventDispatcher : IProcessEventDispatcher
///
public ProcessEventDispatcher(
IInstanceClient instanceClient,
- IInstanceEventClient instanceEventClient,
IEventsClient eventsClient,
IOptions appSettings,
ILogger logger
)
{
_instanceClient = instanceClient;
- _instanceEventClient = instanceEventClient;
_eventsClient = eventsClient;
_appSettings = appSettings;
_logger = logger;
@@ -39,12 +36,7 @@ ILogger logger
///
public async Task DispatchToStorage(Instance instance, List? events)
{
- // need to update the instance process and then the instance in case appbase has changed it, e.g. endEvent sets status.archived
- Instance updatedInstance = await _instanceClient.UpdateProcess(instance);
- await DispatchProcessEventsToStorage(updatedInstance, events);
-
- // remember to get the instance anew since AppBase can have updated a data element or stored something in the database.
- updatedInstance = await _instanceClient.GetInstance(updatedInstance);
+ Instance updatedInstance = await _instanceClient.UpdateProcessAndEvents(instance, events ?? []);
return updatedInstance;
}
@@ -74,19 +66,4 @@ await _eventsClient.AddEvent(
}
}
}
-
- private async Task DispatchProcessEventsToStorage(Instance instance, List? events)
- {
- string org = instance.Org;
- string app = instance.AppId.Split("/")[1];
-
- if (events != null)
- {
- foreach (InstanceEvent instanceEvent in events)
- {
- instanceEvent.InstanceId = instance.Id;
- await _instanceEventClient.SaveInstanceEvent(instanceEvent, org, app);
- }
- }
- }
}
diff --git a/test/Altinn.App.Api.Tests/Mocks/InstanceClientMockSi.cs b/test/Altinn.App.Api.Tests/Mocks/InstanceClientMockSi.cs
index cb5ae85a7..b91df1ee6 100644
--- a/test/Altinn.App.Api.Tests/Mocks/InstanceClientMockSi.cs
+++ b/test/Altinn.App.Api.Tests/Mocks/InstanceClientMockSi.cs
@@ -116,6 +116,11 @@ public Task UpdateProcess(Instance instance)
return Task.FromResult(storedInstance);
}
+ public Task UpdateProcessAndEvents(Instance instance, List events)
+ {
+ return UpdateProcess(instance);
+ }
+
private static Instance GetTestInstance(string app, string org, int instanceOwnerId, Guid instanceId)
{
string instancePath = GetInstancePath(app, org, instanceOwnerId, instanceId);
diff --git a/test/Altinn.App.Core.Tests/Internal/Process/ProcessEventHandlingTests.cs b/test/Altinn.App.Core.Tests/Internal/Process/ProcessEventHandlingTests.cs
index c78eeb48f..4a20c8a5a 100644
--- a/test/Altinn.App.Core.Tests/Internal/Process/ProcessEventHandlingTests.cs
+++ b/test/Altinn.App.Core.Tests/Internal/Process/ProcessEventHandlingTests.cs
@@ -19,7 +19,7 @@ namespace Altinn.App.Core.Tests.Internal.Process;
public class ProcessEventHandlingTests
{
- private readonly List processTasks =
+ private readonly List _processTasks =
[
new Mock().Object,
new Mock().Object,
@@ -28,11 +28,10 @@ public class ProcessEventHandlingTests
];
[Fact]
- public async Task UpdateProcessAndDispatchEvents_StartEvent_instance_updated_and_events_sent_to_storage_nothing_sent_to_ITask()
+ public async Task UpdateProcessAndDispatchEvents_StartEvent_instance_updated_and_events_sent_to_storage()
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings());
@@ -48,12 +47,11 @@ public async Task UpdateProcessAndDispatchEvents_StartEvent_instance_updated_and
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler.Object,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -64,22 +62,9 @@ public async Task UpdateProcessAndDispatchEvents_StartEvent_instance_updated_and
Id = Guid.NewGuid().ToString(),
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_1" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_1", Flow = 2 },
+ CurrentTask = new() { Flow = 1, ElementId = "Task_1" },
},
};
List events = new List()
@@ -98,8 +83,7 @@ public async Task UpdateProcessAndDispatchEvents_StartEvent_instance_updated_and
},
},
};
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService.Setup(i => i.UpdateProcessAndEvents(instance, events)).ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -107,22 +91,18 @@ public async Task UpdateProcessAndDispatchEvents_StartEvent_instance_updated_and
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
- instanceEvent.Verify(p => p.SaveInstanceEvent(events[0], instance.Org, "test-app"), Times.Once);
+ result.Should().Be(instance);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, events), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
[Fact]
- public async Task UpdateProcessAndDispatchEvents_StartTask_instance_updated_and_events_sent_to_storage_nothing_sent_to_ITask_when_tasktype_missing()
+ public async Task UpdateProcessAndDispatchEvents_StartTask_instance_updated_and_events_sent_to_storage_missing_tasktype()
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings());
@@ -138,12 +118,11 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_instance_updated_and_
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler.Object,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -154,20 +133,9 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_instance_updated_and_
Id = Guid.NewGuid().ToString(),
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_1" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_1", Flow = 2 },
+ CurrentTask = new() { Flow = 1, ElementId = "Task_1" },
},
};
List events = new List()
@@ -181,8 +149,7 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_instance_updated_and_
},
},
};
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService.Setup(i => i.UpdateProcessAndEvents(instance, events)).ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -190,22 +157,18 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_instance_updated_and_
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
- instanceEvent.Verify(p => p.SaveInstanceEvent(events[0], instance.Org, "test-app"), Times.Once);
+ result.Should().Be(instance);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, events), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
[Fact]
- public async Task UpdateProcessAndDispatchEvents_StartTask_data_instance_updated_and_events_sent_to_storage_and_trigger_ITask()
+ public async Task UpdateProcessAndDispatchEvents_StartTask_data_instance_updated_and_events_sent_to_storage()
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings());
@@ -221,12 +184,11 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_data_instance_updated
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler.Object,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -237,22 +199,9 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_data_instance_updated
Id = Guid.NewGuid().ToString(),
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_1" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_1", Flow = 2 },
+ CurrentTask = new() { Flow = 1, ElementId = "Task_1" },
},
};
List events = new List()
@@ -267,13 +216,12 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_data_instance_updated
ElementId = "Task_1",
AltinnTaskType = "data",
Name = "Utfylling",
- Flow = 2,
+ Flow = 1,
},
},
},
};
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService.Setup(i => i.UpdateProcessAndEvents(instance, events)).ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -281,22 +229,18 @@ public async Task UpdateProcessAndDispatchEvents_StartTask_data_instance_updated
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
- instanceEvent.Verify(p => p.SaveInstanceEvent(events[0], instance.Org, "test-app"), Times.Once);
+ result.Should().Be(instance);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, events), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
[Fact]
- public async Task UpdateProcessAndDispatchEvents_EndTask_confirmation_instance_updated_and_events_sent_to_storage_and_trigger_ITask()
+ public async Task UpdateProcessAndDispatchEvents_EndTask_confirmation_instance_updated_and_events_sent_to_storage()
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings());
@@ -312,12 +256,11 @@ public async Task UpdateProcessAndDispatchEvents_EndTask_confirmation_instance_u
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler.Object,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -328,22 +271,9 @@ public async Task UpdateProcessAndDispatchEvents_EndTask_confirmation_instance_u
Id = Guid.NewGuid().ToString(),
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_2" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_2", Flow = 3 },
+ CurrentTask = new() { Flow = 2, ElementId = "Task_2" },
},
};
List events = new List()
@@ -363,8 +293,8 @@ public async Task UpdateProcessAndDispatchEvents_EndTask_confirmation_instance_u
},
},
};
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService.Setup(i => i.UpdateProcessAndEvents(instance, events)).ReturnsAsync(instance);
+ instanceService.Setup(i => i.GetInstance(instance)).ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -372,22 +302,18 @@ public async Task UpdateProcessAndDispatchEvents_EndTask_confirmation_instance_u
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
- instanceEvent.Verify(p => p.SaveInstanceEvent(events[0], instance.Org, "test-app"), Times.Once);
+ result.Should().Be(instance);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, events), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
[Fact]
- public async Task UpdateProcessAndDispatchEvents_AbandonTask_feedback_instance_updated_and_events_sent_to_storage_and_trigger_ITask()
+ public async Task UpdateProcessAndDispatchEvents_AbandonTask_feedback_instance_updated_and_events_sent_to_storage()
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings());
@@ -403,12 +329,11 @@ public async Task UpdateProcessAndDispatchEvents_AbandonTask_feedback_instance_u
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler.Object,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -419,22 +344,9 @@ public async Task UpdateProcessAndDispatchEvents_AbandonTask_feedback_instance_u
Id = Guid.NewGuid().ToString(),
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_2" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_2", Flow = 4 },
+ CurrentTask = new() { Flow = 2, ElementId = "Task_2" },
},
};
List events = new List()
@@ -449,13 +361,12 @@ public async Task UpdateProcessAndDispatchEvents_AbandonTask_feedback_instance_u
ElementId = "Task_2",
AltinnTaskType = "feedback",
Name = "Bekreft",
- Flow = 4,
+ Flow = 2,
},
},
},
};
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService.Setup(i => i.UpdateProcessAndEvents(instance, events)).ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -463,22 +374,18 @@ public async Task UpdateProcessAndDispatchEvents_AbandonTask_feedback_instance_u
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
- instanceEvent.Verify(p => p.SaveInstanceEvent(events[0], instance.Org, "test-app"), Times.Once);
+ result.Should().Be(instance);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, events), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
[Fact]
- public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_updated_and_events_sent_to_storage_and_trigger_ITask()
+ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_updated_and_events_sent_to_storage()
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appMetadata = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
@@ -495,12 +402,11 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -511,20 +417,9 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
Id = $"{1234}/{Guid.NewGuid()}",
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_2" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_2", Flow = 3 },
+ CurrentTask = new() { Flow = 2, ElementId = "Task_2" },
},
};
List events = new List()
@@ -562,8 +457,7 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
appMetadata.Setup(x => x.GetApplicationMetadata()).ReturnsAsync(applicationMetadata);
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService.Setup(i => i.UpdateProcessAndEvents(instance, events)).ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -571,13 +465,10 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
+ result.Should().Be(instance);
appEvents.Verify(a => a.OnEndAppEvent("EndEvent", instance), Times.Once);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
- instanceEvent.Verify(p => p.SaveInstanceEvent(events[0], instance.Org, "test-app"), Times.Once);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, events), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
@@ -587,7 +478,6 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings());
@@ -603,12 +493,11 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
endTaskEventHandler.Object,
abandonTaskEventHandler.Object,
endEventHandler.Object,
- processTasks
+ _processTasks
);
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -619,25 +508,15 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
Id = Guid.NewGuid().ToString(),
Org = "ttd",
AppId = "ttd/test-app",
- };
- Instance updateInstanceResponse = new Instance()
- {
- Id = instance.Id,
- Org = "ttd",
- AppId = "ttd/test-app",
- Process = new ProcessState() { CurrentTask = new() { ElementId = "Task_2" } },
- };
- Instance getInstanceResponse = new Instance()
- {
- Id = instance.Id,
Process = new ProcessState()
{
- CurrentTask = new() { ElementId = "Task_2", Flow = 3 },
+ CurrentTask = new() { Flow = 2, ElementId = "Task_2" },
},
};
List events = null;
- instanceService.Setup(i => i.UpdateProcess(instance)).ReturnsAsync(updateInstanceResponse);
- instanceService.Setup(i => i.GetInstance(updateInstanceResponse)).ReturnsAsync(getInstanceResponse);
+ instanceService
+ .Setup(i => i.UpdateProcessAndEvents(instance, new List()))
+ .ReturnsAsync(instance);
Dictionary prefill = new Dictionary();
// Act
@@ -645,11 +524,9 @@ public async Task UpdateProcessAndDispatchEvents_EndEvent_confirmation_instance_
var result = await dispatcher.DispatchToStorage(instance, events);
// Assert
- result.Should().Be(getInstanceResponse);
- instanceService.Verify(i => i.UpdateProcess(instance), Times.Once);
- instanceService.Verify(i => i.GetInstance(updateInstanceResponse), Times.Once);
+ result.Should().Be(instance);
+ instanceService.Verify(i => i.UpdateProcessAndEvents(instance, new List()), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
@@ -659,7 +536,6 @@ public async Task RegisterEventWithEventsComponent_sends_movedTo_event_to_events
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings() { RegisterEventsWithEventsComponent = true });
@@ -667,7 +543,6 @@ public async Task RegisterEventWithEventsComponent_sends_movedTo_event_to_events
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -685,7 +560,6 @@ public async Task RegisterEventWithEventsComponent_sends_movedTo_event_to_events
// Assert
eventsService.Verify(e => e.AddEvent("app.instance.process.movedTo.Task_1", instance), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
@@ -695,7 +569,6 @@ public async Task RegisterEventWithEventsComponent_sends_complete_event_to_event
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings() { RegisterEventsWithEventsComponent = true });
@@ -703,7 +576,6 @@ public async Task RegisterEventWithEventsComponent_sends_complete_event_to_event
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -721,7 +593,6 @@ public async Task RegisterEventWithEventsComponent_sends_complete_event_to_event
// Assert
eventsService.Verify(e => e.AddEvent("app.instance.process.completed", instance), Times.Once);
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
@@ -731,7 +602,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_process_
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings() { RegisterEventsWithEventsComponent = true });
@@ -739,7 +609,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_process_
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -752,7 +621,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_process_
// Assert
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
@@ -762,7 +630,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_current_
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings() { RegisterEventsWithEventsComponent = true });
@@ -770,7 +637,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_current_
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -783,7 +649,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_current_
// Assert
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}
@@ -793,7 +658,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_register
{
// Arrange
var instanceService = new Mock();
- var instanceEvent = new Mock();
var appEvents = new Mock();
var eventsService = new Mock();
var appSettings = Options.Create(new AppSettings() { RegisterEventsWithEventsComponent = false });
@@ -801,7 +665,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_register
ProcessEventDispatcher dispatcher = new ProcessEventDispatcher(
instanceService.Object,
- instanceEvent.Object,
eventsService.Object,
appSettings,
logger
@@ -818,7 +681,6 @@ public async Task RegisterEventWithEventsComponent_sends_no_events_when_register
// Assert
instanceService.VerifyNoOtherCalls();
- instanceEvent.VerifyNoOtherCalls();
appEvents.VerifyNoOtherCalls();
eventsService.VerifyNoOtherCalls();
}