mercredi 22 février 2017

ModelState.IsValid threw an exception of type System.IO.FileLoadException

I have an .NET MVC application and I'm writing some unit test for it using NUnit.

This is the function I'm currently testing:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Add(AddInstrumentViewModel model)
{
    if (ModelState.IsValid)
    {
        var group = new FtpServerGroup
        {
            Disabled = true,
            FtpLastPullTime = DateTime.Now,
            FtpPullInterval = TimeSpan.Zero,
        };

        await db.CreateAsync(group, model.Address, model.Username, model.Password);

        // go back to card view
        var res = await db.GetAll();
        return RedirectToAction("Index", res);
    }

    return View(model);
}

this is the actual test:

[Test]
public async Task Test()
{
    var controller = new AutomaticTransferController(mockService.Object);

    var model = new AddInstrumentViewModel
    {
        Address = "124.124.124.124",
        Password = "123456",
        Username = "John Foo"
    };

    var res = await controller.Add(model);
}

Stepping with the debugger I noticed that as soon as I enter the .Add() method the line if (ModelState.IsValid) throw an exception

ModelState.IsValid threw an exception of type System.IO.FileLoadException

In fact, it threw an exception without telling me when nor where

Aucun commentaire:

Enregistrer un commentaire