Skip to content

Commit

Permalink
test: added unit test to check expected requests for UpdateJobTimeout…
Browse files Browse the repository at this point in the history
…Command
  • Loading branch information
LennartKleymann committed May 26, 2024
1 parent 0b294e0 commit 87e1684
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Client.UnitTests/UpdateJobTimeoutTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using GatewayProtocol;
using Grpc.Core;
using NUnit.Framework;

namespace Zeebe.Client;

[TestFixture]
public class UpdateJobTimeoutTest : BaseZeebeTest
{
[Test]
public async Task ShouldSendRequestAsExpected()
{
// given
var expectedRequest = new UpdateJobTimeoutRequest()
{
JobKey = 1024,
Timeout = 2000
};

// when
await ZeebeClient
.NewUpdateJobTimeoutCommand(1024)
.Timeout(new TimeSpan(0, 0, 2))
.Send();

// then
var request = TestService.Requests[typeof(UpdateJobTimeoutRequest)][0];
Assert.AreEqual(expectedRequest, request);
}

[Test]
public void ShouldTimeoutRequest()
{
// given

// when
var task = ZeebeClient
.NewUpdateJobTimeoutCommand(1024)
.Timeout(new TimeSpan(0, 0, 2))
.Send(TimeSpan.Zero);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];

// then
Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException.Status.StatusCode);
}

[Test]
public void ShouldCancelRequest()
{
// given

// when
var task = ZeebeClient
.NewUpdateJobTimeoutCommand(1024)
.Timeout(new TimeSpan(0, 0, 2))
.Send(new CancellationTokenSource(TimeSpan.Zero).Token);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];

// then
Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode);
}
}

0 comments on commit 87e1684

Please sign in to comment.