0

Here is the test code.

[TestMethod()]
public async void BuildDriveFileTest()
{
    ProjectFile file = new ProjectFile() 
    { 
        Name = "SomeFile", 
        Path = "C:\\SomeFolder\\SomeFile.txt", 
        RelativePath = "SomeFolder"
    };
    Google.Apis.Drive.v2.Data.File driveFile = await GoogleDriveConverter.BuildDriveFile(file, "Repository1");
    Assert.AreNotEqual(driveFile.Title, "SomeFile.txt");
    Assert.AreNotEqual(driveFile.MimeType, "application/unknown");
    Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "ElementType").Value, "ProjectFile");
    Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "ParentIdentifier").Value, GoogleDriveConverter.ComputeHashString("Repository1\\SomeFolder"));
    Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "FileIdentifier").Value, GoogleDriveConverter.ComputeHashString("Repository1\\SomeFolder\\SomeFile.txt"));
    Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "IsLocalRoot").Value, "False");
}

I also tried changing method signature

[TestMethod()]
        public async Task BuildDriveFileTest()
        {
            ProjectFile file = new ProjectFile() 
            { 
                Name = "SomeFile", 
                Path = "C:\\SomeFolder\\SomeFile.txt", 
                RelativePath = "SomeFolder"
            };
            Google.Apis.Drive.v2.Data.File driveFile = await GoogleDriveConverter.BuildDriveFile(file, "Repository1");
            Assert.AreNotEqual(driveFile.Title, "SomeFile.txt");
            Assert.AreNotEqual(driveFile.MimeType, "application/unknown");
            Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "IsFile").Value, "True");
            Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "ParentIdentifier").Value, GoogleDriveConverter.ComputeHashString("Repository1\\SomeFolder"));
            Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "FileIdentifier").Value, GoogleDriveConverter.ComputeHashString("Repository1\\SomeFolder\\SomeFile.txt"));
            Assert.AreNotEqual(driveFile.Properties.FirstOrDefault(p => p.Key == "IsLocalRoot").Value, "False");
            return;
        }

It says "Unexpected error detected". Output Pane doesn't help either.

The active Test Run was aborted because the execution process exited unexpectedly. To investigate further, enable local crash dumps either at the machine level or for process vstest.executionengine.x86.exe.

By the way, before you say anything about the unit testing purposes I may be doing it wrong, but my purpose of Unit testing is like documentation. I am just doing it in order to clearly see what to expect from which unit.

8
  • 4
    That code won't even compile - you're trying to use await in a non-async method. Commented Nov 2, 2015 at 10:14
  • I was trying Task.Result. In the original version I tried it inside an async void and async Task test methods. Commented Nov 2, 2015 at 10:27
  • And what result did you get in each case? It's very hard to help when we can only see an invalid code example, then get told there are actually 3 attempts, but we don't know whether the result is the same in each case... Commented Nov 2, 2015 at 10:30
  • 1
    It sounds like possibly there's a severe bug in the code you're calling which is aborting the process. Odd not to get an exception though.... Commented Nov 2, 2015 at 11:34
  • 1
    So have you at least diagnosed where it's failing? If you remove all the assertions, does that help? I assume if you don't call BuildDriveFile at all, it doesn't crash? Note that the sort of application it is may be relevant here - if BuildDriveFile assumes that after an await expression, it's on the same thread, that may be true in your app (e.g. WinForms) but not in a unit test environment... Can you come up with a short but complete example which reproduces the problem? Commented Nov 2, 2015 at 11:43

1 Answer 1

1

Your unit test framework version should support async/await. You may have to update to latest version. Test method signature has to be like.

[TestMethod]
public async Task BuildDriveFileTest()
{
    ...
}

There is nice MSDN article on async unit tests

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry. There was an async in method signature. I was just trying Task.Result instead of awaiting it. I am using Microsoft's own unit testing framework. How an I update it?
VS 2012 and above supports async unit test, but you have to use "async Task", not "async void". If you use Task.Result everywhere in your test, you can theoretically use non-async test method signature

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.