Test Add Stop to WorkTest

This commit is contained in:
ngfrolov 2023-11-07 15:34:05 +05:00
parent de516d2081
commit d130d3ca5e
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -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);
}
}
}