public void Render_CSV_file_for_post_to_DataCollectionToCsv() { var vm = new CsvDumpViewModel { DataCollections = Builder <CollectionListViewModel> .CreateListOfSize(3).Build() }; _form["DataCollectionCsv"] = "Get Data Management Plan to CSV"; _form["DataCollectionList"] = "1"; var dataCollection = SetUpDataCollection("GA37493"); _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection); _csvHelper.ExportToCsv(Arg.Any <DataTable>()).Returns(""); _csvHelper.DataCollectionToDataTable(Arg.Any <DataCollection>()).Returns(new DataTable()); _controller.WithCallTo(c => c.DataCollectionToCsv(vm)).ShouldRenderFile("text/csv"); _csvHelper.Received().ExportToCsv(Arg.Any <DataTable>(), Arg.Any <string>()); _csvHelper.Received().DataCollectionToDataTable(Arg.Any <DataCollection>()); const string headerValue = "attachment;filename=Feeding_habits_of_polarbears_2011_DataCollection.csv"; _context.HttpContext.Response.Received().AddHeader(Arg.Any <string>(), Arg.Is <string>(o => o == headerValue)); }