perrich / Hangfire.MemoryStorage

A memory storage for Hangfire.
Apache License 2.0
131 stars 43 forks source link

Is there an easy way to clear down storage between unit tests? #44

Closed grahambunce closed 11 months ago

grahambunce commented 12 months ago

I'm using this to run my hangfire unit tests but jobs etc. are retained between test runs. I can manually delete jobs but it would cleaner if I could start with a fresh instance, or there is a quick way to remove all entries in the Data class.

My current thinking with the existing design is to use cast the JobStorage to the MemoryStorage class, use the GetEnumerable to get a list of keys and then Delete these manually with the Delete method.

Is this is preferred approach or am I missing something obvious?

Thanks

perrich commented 11 months ago

Hi, It's a good question. Nothing really exists to do it.

Your workaround using MemoryStorage.Data seems good to remove old data.

grahambunce commented 11 months ago

For some reason that didn’t work either but I couldn’t work out why. For the benefit of others, what I ended up doing was as follows:

I don’t have the code to hand to copy examples, but after much trail and error I got each test to be properly isolated with the above approach.