forked from ddrilling/AsbCloudServer
Test Add Stop to WorkTest
This commit is contained in:
parent
de516d2081
commit
d130d3ca5e
@ -86,7 +86,6 @@ namespace AsbCloudWebApi.Tests.Services
|
||||
Assert.Equal(expectedProgress, currentState.Progress);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task Work_fails_with_info()
|
||||
{
|
||||
@ -122,5 +121,30 @@ namespace AsbCloudWebApi.Tests.Services
|
||||
Assert.Contains(expectedErrorText, error.ErrorText, StringComparison.InvariantCultureIgnoreCase);
|
||||
Assert.Equal(expectedState, error.State);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Stop()
|
||||
{
|
||||
var workTime = TimeSpan.FromMilliseconds(1_000);
|
||||
|
||||
Task workAction(string id, IServiceProvider services, Action<string, double?> callback, CancellationToken token)
|
||||
=> Task.Delay(workTime, token);
|
||||
|
||||
var work = Work.CreateByDelegate("", workAction);
|
||||
|
||||
//act
|
||||
var begin = DateTime.Now;
|
||||
_ = work.Start(provider, CancellationToken.None);
|
||||
await Task.Delay(10);
|
||||
work.Stop();
|
||||
await Task.Delay(10);
|
||||
|
||||
//assert
|
||||
Assert.Equal(0, work.CountComplete);
|
||||
Assert.Equal(1, work.CountStart);
|
||||
Assert.Equal(0, work.CountErrors);
|
||||
Assert.Null(work.LastComplete);
|
||||
Assert.Null(work.LastError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user