public void ExportTest()
        {
            // Arrange
            var controller = new FunctionController(mockRepository.Object);
            controller.ControllerContext = ctrlContext.Object;

            // Act
            var resultGet = controller.Export() as ViewResult;

            var resultPost = controller.ExportConfirmed() as FileResult;

            // Assert
            Assert.IsNotNull(resultGet);
            Assert.IsNotNull(resultPost);
            Assert.AreEqual(resultPost.ContentType, "text/csv");
            Assert.AreEqual(resultPost.FileDownloadName.Substring(0, 6), "ViDat_");
        }
        public void IndexTest()
        {
            // Arrange
            var controller = new FunctionController(mockRepository.Object);
            controller.ControllerContext = ctrlContext.Object;

            // Act
            var result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void InitializeTest()
        {
            // Arrange
            var controller = new FunctionController(mockRepository.Object);
            controller.ControllerContext = ctrlContext.Object;

            // Act
            var resultGet = controller.Initialize() as ViewResult;
            var resultPost = controller.InitializeConfirmed() as ViewResult;
            var model = resultPost.Model as List<Card>;
            var result = resultPost.ViewBag.Result as String;

            // Assert
            Assert.IsNotNull(resultGet);
            Assert.IsNotNull(resultPost);
            Assert.AreEqual(result, "The database was initialized");
            Assert.AreEqual(model.Count(), mockRepository.Object.Cards.Count());
        }
        public void ImportTest()
        {
            // Arrange
            var controller = new FunctionController(mockRepository.Object);
            controller.ControllerContext = ctrlContext.Object;

            string filePath = Path.GetFullPath(@"../../Files\ViDat_20140910_010203.csv");
            var fileStream = new FileStream(filePath, FileMode.Open);

            uploadedFile
                .Setup(f => f.InputStream)
                .Returns(fileStream);

            // Act
            var resultGet = controller.Import() as ViewResult;
            var resultPost = controller.ImportConfirmed(
                csvFile:uploadedFile.Object, overwrite:false) as ViewResult;
            var model = resultPost.Model as List<Card>;
            model = model.OrderBy(m => m.CreatedAt).ToList();

            // Assert
            Assert.IsNotNull(resultGet);
            Assert.IsNotNull(resultPost);
            Assert.AreEqual(model.Count, 5);
            Assert.AreEqual(model.First().Question, "q6");
            Assert.AreEqual(model.Last().Question, "question4");
            Assert.AreEqual(model[4].CreatedAt - model[3].CreatedAt,
                new TimeSpan(0, 0, 0, 0, 100));
        }