public WorkTime?FindLatestFromSnapshot(User user) { var sql = $@"SELECT {TableCols} FROM {TableName} INNER JOIN (SELECT AggregateId as 'idsnap', AggregateVersion as 'ver' FROM {TableName} WHERE EventName=@EventName AND json_extract(Data, '$.Snapshot.User.UserId') = @UserId ORDER BY Date DESC LIMIT 1) snap ON AggregateId = snap.idsnap AND AggregateVersion >= snap.ver"; using var conn = CreateConnection(true); var events = conn.Query <DbEvent>(sql, new { EventName = EventName.WorkTimeSnapshotCreated, UserId = user.UserId, }) .MapToEvents(_mapper).ToList(); if (events.Count == 0) { return(null); } var workTime = WorkTime.CreateFromSnapshot(events); return(workTime); }
public WorkTime?FindFromSnapshot(WorkTimeSnapshotCreated snapshotEvent) { var sql = $@"SELECT {TableCols} FROM {TableName} WHERE AggregateId = @AggregateId AND AggregateVersion = @AggregateVersion"; using var conn = CreateConnection(true); var events = conn.Query <DbEvent>(sql, new { AggregateVersion = snapshotEvent.AggregateVersion, AggregateId = snapshotEvent.AggregateId, }) .MapToEvents(_mapper).ToList(); if (events.Count != 1) { throw new Exception(); } var snap = events.First() as WorkTimeSnapshotCreated; if (snap == null) { throw new Exception(); } var workTime = WorkTime.CreateFromSnapshot(snap); return(workTime); }
public void Combine_ads_new_events() { var workTime = WorkTimeTestUtils.CreateManual(_user); workTime.StartManually(); var snap = workTime.TakeSnapshot(); var totalEvs = workTime.PendingEvents.Count; var fromSnap = WorkTime.CreateFromSnapshot(snap); fromSnap.AddRecognitionFailure(DateTime.UtcNow, false, false); WorkTime joined = WorkTime.Combine(workTime, fromSnap); joined.PendingEvents.Count.Should().Be(totalEvs + 1); joined.PendingEvents.Last().Should().BeOfType <FaceRecognitionFailure>(); }