PsProcessProviderBaseMock.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using qdr.fnd.core.pqueue.Process;
  2. using Quadarax.Foundation.Core.Data;
  3. using Quadarax.Foundation.Core.Logging;
  4. namespace qdr.fnd.core.pqueue.test.Process.Mock
  5. {
  6. internal class PsProcessProviderBaseMock : PsProcessProviderBase
  7. {
  8. public const string CS_ARG_EMIT_EXC = "emmit-exception";
  9. public PsProcessProviderBaseMock(ProcessDoneCallback processDoneCallback, ProcessStdOutputCallback processStdOutputCallback, string itemId, TypedArgument[] arguments, ILogger logger) : base(processDoneCallback, processStdOutputCallback, itemId, arguments, logger)
  10. {
  11. }
  12. public new static TypedArgument[] CreateArguments()
  13. {
  14. var list = new List<TypedArgument>(PsProcessProviderBase.CreateArguments());
  15. list.Add(new TypedArgument(CS_ARG_EMIT_EXC, typeof(string), false));
  16. return list.ToArray();
  17. }
  18. protected override async Task OnProcess()
  19. {
  20. if (ContainsArgument(CS_ARG_EMIT_EXC) && !string.IsNullOrEmpty(GetArgumentValue<string>(CS_ARG_EMIT_EXC)))
  21. {
  22. var message = GetArgumentValue<string>(CS_ARG_EMIT_EXC);
  23. Log.Log(LogSeverityEnum.Info, $"Emmiting exception '{message}'");
  24. throw new Exception("Test exception");
  25. }
  26. else
  27. {
  28. Log.Log(LogSeverityEnum.Info, $"Nothing to emitte");
  29. }
  30. Task.Delay(3000).Wait();
  31. await base.OnProcess();
  32. }
  33. public void TestOnProcessError(Exception exception)
  34. {
  35. var task = base.OnProcessError(exception);
  36. task.Wait();
  37. }
  38. public TValue? TestGetArgumentValue<TValue>(string name)
  39. {
  40. return base.GetArgumentValue<TValue>(name);
  41. }
  42. public bool TestContainsArgument(string name)
  43. {
  44. return base.ContainsArgument(name);
  45. }
  46. }
  47. }