PsQueueItemMock.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using qdr.fnd.core.pqueue.Storages;
  2. using Quadarax.Foundation.Core.Data;
  3. using Quadarax.Foundation.Core.Logging;
  4. using System.Xml.Linq;
  5. namespace qdr.fnd.core.pqueue.test.Mocks
  6. {
  7. public class PsQueueItemMock : PsQueueItem
  8. {
  9. public PsQueueItemMock(string id) : base(id)
  10. {
  11. }
  12. public PsQueueItemMock(string id, string owner, string ownerRef, string providerClass, DateTime created, ITypedArgument[]? arguments, int initialAttempts = 0): base(id, owner, ownerRef, providerClass, created, arguments, initialAttempts)
  13. {
  14. }
  15. public void SetOwner(string owner, string ownerRef)
  16. {
  17. Owner = owner;
  18. OwnerRef = ownerRef;
  19. }
  20. public void ClearArguments()
  21. {
  22. Arguments = new ITypedArgument[0];
  23. }
  24. public void AddToStorage(IPsQueueStorage storage)
  25. {
  26. var itemId = storage.CreateItem(Owner, OwnerRef, ProcessProviderClass, AtteptsInitial, null);
  27. foreach (var argument in Arguments)
  28. {
  29. if (argument.ValueType.FullName == null) throw new InvalidOperationException($"Cannot obtain fullName of type '{argument.ValueType.Name}'");
  30. storage.CreateItemAttribute(itemId, argument.Name, argument.Value, argument.ValueType.FullName, argument.IsOutput);
  31. }
  32. Id = itemId;
  33. }
  34. }
  35. }