-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implemented MockDirectory.CreateTempSubDirectory #964
feat: Implemented MockDirectory.CreateTempSubDirectory #964
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gregington : Thank you for working on this missing implementation!
tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
Outdated
Show resolved
Hide resolved
tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
…ith for full temporary path. This is due to MacOS using /private/var when returning the temp path.
I changed one of the tests to hopefully work with MacOS and whether the I don't have access to a Windows platform so I couldn't reproduce failure with the |
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
...tractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj
Outdated
Show resolved
Hide resolved
tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me...
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
…19.2.11 (#291) [](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [TestableIO.System.IO.Abstractions](https://togithub.com/TestableIO/System.IO.Abstractions) | nuget | patch | `19.2.9` -> `19.2.11` | --- ### Release Notes <details> <summary>TestableIO/System.IO.Abstractions</summary> ### [`v19.2.11`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.11) ##### What's Changed - chore(deps): update dependency dotnet-sdk to v7.0.203 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/967](https://togithub.com/TestableIO/System.IO.Abstractions/pull/967) - feat: Implemented MockDirectory.CreateTempSubDirectory by [@​gregington](https://togithub.com/gregington) in [https://github.com/TestableIO/System.IO.Abstractions/pull/964](https://togithub.com/TestableIO/System.IO.Abstractions/pull/964) ##### New Contributors - [@​gregington](https://togithub.com/gregington) made their first contribution in [https://github.com/TestableIO/System.IO.Abstractions/pull/964](https://togithub.com/TestableIO/System.IO.Abstractions/pull/964) **Full Changelog**: TestableIO/System.IO.Abstractions@v19.2.9...v19.2.11 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/Testably/Testably.Abstractions). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS40MC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNDAuMCJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This is addressed in release v19.2.11. |
Implemented MockDirectory.CreateTempSubdirectory(). This implementation generates a random 6 character string with an optional user specified prefix and creates the directory in the temporary directory returned by
Path.GetTempPath()
.The 6 random characters seems to be the algorithm used on my platform (Mac) by the System.IO implementation.
Notes on this PR
MockDirectory
now contains aRandom
instance to generate random temp directory names.Random.Shared
can't be used as it was introduced in .NET 6 it it appears we are supporting earlier .NET versions.MockDirectory
is marked as[Serializable]
, however theRandom
instance cannot be serialized. I have marked theRandom
instance as[NonSerialized]
and created a newRandom
instance on deserializing. The state of the random number generator will be different when deserialized. I don't think this is an issue as there was no way to specify the seed of theRandom
instance when creating theMockDirectory
instance, so there's no way to generate the same sequence of random directories again (besides a very slim chance).<EnableUnsafeBinaryFormatterSerialization>
on the test project and#pragma warning disable SYSLIB0011
on the deserialize method to allow testing that deserialization of aMockDirectory
also instantiates a new random number generator. Deserialization is heavily deprecated and this is only on test classes, so I am assuming this is OK.