Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access files from xunit in WinRT (The process has no package identity)

I'm writing some unit tests (with xunit) to my WinRT project.

I have prepared text file with json content. I put this file into my Test project and now I want to read file, parse json and check some stuff. It's working for MS Test but failing for xUnit.

When I run test writen with xUnit I receive:

System.InvalidOperationException The process has no package identity. (Exception from HRESULT: 0x80073D54)

[Fact]
public async Task ProjectFile()
{
    var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    folder = await folder.GetFolderAsync("SampleData");

    var file = await folder.GetFileAsync("companies.txt");
    Assert.NotNull(file);

    var result = await Windows.Storage.FileIO.ReadTextAsync(file);
    Assert.True(result.Length > 0);
}

My IDE:

  • Visual Studio 2012 Pro Update 3
  • WinRT project
  • ReSharper 7.1.3
  • xUnit

Anyone can help here?

like image 402
Poniat Avatar asked Nov 11 '22 20:11

Poniat


1 Answers

I know this question is old, but xUnit.net 1.x did not officially support anything but desktop libraries.

xUnit.net 2.x supports:

  • Desktop
  • Portable (Profile 259)
  • DNX (.NET and .NET Core, including ASP.NET 5+)
  • Windows Phone 8 (Silverlight)
  • Windows Universal (Windows Phone 8.1+, Windows 8.1+)
  • Xamarin (MonoAndroid, MonoTouch, and iOS Universal)

Presumably one of these platforms is something you're targeting. ;)

like image 86
Brad Wilson Avatar answered Dec 28 '22 10:12

Brad Wilson