2009-02-04 2 views
0

Я забираю единичный тест для контроллера, и вот мой код.Тестирование в ASP.net MVC Beta 1

public void DocumentController_IndexMethod_ShouldReturn_Documents() 
    { 
     DocumentsController c = new DocumentsController(_repository); 

     ViewResult result = (ViewResult)c.Index("1"); 

     DocumentsController.DocumentsData data = (DocumentsController.DocumentsData)result.ViewData; 

     Assert.IsNotNull(data.Documents); 
     Assert.IsTrue(data.Documents.Count() > 0); 

     Assert.IsNotNull(result); 
    } 

Я в основном следующие вместе с asp.net витрину приложения Роб Конери и понял, что я не могу использовать метод RenderView. Как показано, я попытался метод ViewResult создать экземпляр представления. Я получаю эту ошибку: Ошибка 1 Невозможно преобразовать тип 'System.Web.Mvc.ViewDataDictionary' в 'HomeOwners.Controllers.DocumentsController.DocumentsData' C: \ Documents and Settings \ drmarshall \ Мои документы \ Visual Studio 2008 \ Projects \ ГлавнаяУчастники \ ГлавнаяНоутбуки.Тесты \ ДокументыControllerTests.cs 61 54 ГлавнаяНовеки.Тесты

Я использую правильный метод замены или я что-то упускаю?

Я понял.

[TestMethod] 
    public void DocumentController_IndexMethod_ShouldReturn_Documents() 
    { 
     DocumentsController c = new DocumentsController(_repository); 

     ViewResult result = c.Index("1") as ViewResult; 

     ViewDataDictionary dictionary = result.ViewData; 

     DocumentsController.DocumentsData data = (DocumentsController.DocumentsData)dictionary["Documents"]; 

     Assert.IsNotNull(data.Documents); 
     Assert.IsTrue(data.Documents.Count() > 0); 

     Assert.IsNotNull(result); 
    } 
+0

Если у вас есть вопросы, я не могу сказать, что это такое. –

+0

Вы решили свою проблему? –

ответ

0

[TestMethod] общественного недействительными DocumentController_IndexMethod_ShouldReturn_Documents() { DocumentsController с = новый DocumentsController (_repository);

ViewResult result = c.Index("1") as ViewResult; 

    ViewDataDictionary dictionary = result.ViewData; 

    DocumentsController.DocumentsData data = (DocumentsController.DocumentsData)dictionary["Documents"]; 

    Assert.IsNotNull(data.Documents); 
    Assert.IsTrue(data.Documents.Count() > 0); 

    Assert.IsNotNull(result); 
}