Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Fix System.IO.Packaging.Tests in uap to create files in temp directory using FileCleanupTestBase helper class #21029

Merged
merged 2 commits into from
Jun 14, 2017

Conversation

safern
Copy link
Member

@safern safern commented Jun 14, 2017

System.IO.Packaging.Tests where failing in uap due to UnauthorizedAccessException because it was trying to create files inside the test folder and since they run inside appx it is not authorized.

I refactored the tests to use FileCleanupTestBase helper class as a base class to create and remove files. This fixes all test failures in Uap for this test project.

cc: @danmosemsft @JeremyKuhne @joperezr

// Console.WriteLine("{0}:{1}", test, fiGuidName.Name);
return fiGuidName;
var existingDoc = new FileInfo(existingFileName);
var content = File.ReadAllBytes(existingDoc.FullName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: var => byte[]

{
private const string Mime_MediaTypeNames_Text_Xml = "text/xml";
private const string Mime_MediaTypeNames_Image_Jpeg = "image/jpeg"; // System.Net.Mime.MediaTypeNames.Image.Jpeg
private const string s_DocumentXml = @"<Hello>Test</Hello>";
private const string s_ResourceXml = @"<Resource>Test</Resource>";

private static FileInfo GetFileSavedWithGuidName(string test, string name)
private FileInfo GetFileSavedWithGuidName(string existingFileName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: does this function need a different name now?

}

public static FileInfo GetGuidNameForNewFile(string test, string extension)
public FileInfo GetGuidNameForNewFile(string extension)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: same question about function name

// If a test leaves a Test-* file in existence, then uncomment following line to determine which test it was.
// Console.WriteLine("{0}:{1}", test, fiDoc.Name);
return fiDoc;
return new FileInfo($"{GetTestFilePath()}.{extension}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the benefits of GetTestFilePath is it includes in the file name information about the test being used, in case the file gets left behind or there's an issue with it, or whatnot. That's done using Caller attributes, which are filled in by the compiler based on the call site. But that scheme is then defeated somewhat when the GetTestFilePath is in a helper method rather than the actual test. You might consider adding such Caller attribute arguments to these helpers and then passing the state through explicitly to GetTestFilePath.

@safern safern force-pushed the FixUapIoPackagingTests branch from f1d0274 to 5e805bf Compare June 14, 2017 08:01
@safern safern force-pushed the FixUapIoPackagingTests branch from 5e805bf to 87cf02e Compare June 14, 2017 08:07
@safern
Copy link
Member Author

safern commented Jun 14, 2017

I've addressed PR feedback. Thanks @stephentoub for the feedback :)

@stephentoub stephentoub merged commit 72f74a6 into dotnet:master Jun 14, 2017
@safern safern deleted the FixUapIoPackagingTests branch June 14, 2017 15:21
Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@karelz karelz modified the milestones: UWP6.0, 2.1.0 Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants