Skip to content

Commit

Permalink
added EmailRequestEvent message (#197)
Browse files Browse the repository at this point in the history
Signed-off-by: Lillie Dae <[email protected]>
  • Loading branch information
lillie-dae authored May 17, 2023
1 parent 5ab1eea commit 8f81687
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/Messaging/Events/EmailRequestEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2022 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

namespace Monai.Deploy.Messaging.Events
{
public class EmailRequestEvent : EventBase
{
[JsonProperty(PropertyName = "id")]
[Required]
public Guid Id { get; set; }

[JsonProperty(PropertyName = "workflow_instance_id")]
[Required]
public string WorkflowInstanceId { get; set; }

[JsonProperty(PropertyName = "workflow_name")]
[Required]
public string WorkflowName { get; set; }

[JsonProperty(PropertyName = "task_id")]
[Required]
public string TaskId { get; set; }

[JsonProperty(PropertyName = "roles")]
public string Roles { get; set; }

[JsonProperty(PropertyName = "emails")]
public string Emails { get; set; }

[Required]
[JsonProperty(PropertyName = "metadata")]
public Dictionary<string, string> Metadata { get; set; }

public EmailRequestEvent()
{
Id = Guid.NewGuid();
WorkflowInstanceId = string.Empty;
TaskId = string.Empty;
WorkflowName = string.Empty;
Metadata = new Dictionary<string, string>();
Roles = string.Empty;
Emails = string.Empty;
}
}
}
43 changes: 43 additions & 0 deletions src/Messaging/Tests/EmailRequestEventTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2022 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using Monai.Deploy.Messaging.Common;
using Monai.Deploy.Messaging.Events;
using Xunit;

namespace Monai.Deploy.Messaging.Tests
{
public class EmailRequestEventTest
{
[Fact(DisplayName = "Validation throws on error")]
public void ValidationThrowsOnError()
{
var runnerComplete = new EmailRequestEvent();
Assert.Throws<MessageValidationException>(() => runnerComplete.Validate());

runnerComplete.WorkflowInstanceId = Guid.NewGuid().ToString();
Assert.Throws<MessageValidationException>(() => runnerComplete.Validate());

runnerComplete.WorkflowName = Guid.NewGuid().ToString();
Assert.Throws<MessageValidationException>(() => runnerComplete.Validate());

runnerComplete.TaskId = Guid.NewGuid().ToString();
var exception = Record.Exception(() => runnerComplete.Validate());
Assert.Null(exception);
}
}
}
1 change: 1 addition & 0 deletions src/Messaging/Tests/TaskCallbackEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Monai.Deploy.Messaging.Tests
{

public class TaskCallbackEventTest
{
[Fact(DisplayName = "Validation throws on error")]
Expand Down

0 comments on commit 8f81687

Please sign in to comment.