public DataSetDetailUploaderService(IDataSetSchemaService dataSetSchemaService
                                     , IRepository <DataSetDetail> repositoryDataSetDetails
                                     , IDataSetDetailCsvProcessor csvProcessor
                                     , IDataSetDetailSqlRepo dataSetDetailSqlRepo
                                     )
 {
     _dataSetSchemaService     = dataSetSchemaService;
     _repositoryDataSetDetails = repositoryDataSetDetails;
     _csvProcessor             = csvProcessor;
     _dataSetDetailSqlRepo     = dataSetDetailSqlRepo;
 }
        public void SaveCsv_when_schema_cant_be_found_from_id_returns_null_will_return_uploadResult_with_error_message_unable_to_find_schema()
        {
            //arrange
            var mock = new Mock <IDataSetSchemaService>();

            _dataSetSchemaService = mock.Object;
            var mock2 = new Mock <IDataSetDetailCsvProcessor>();

            _csvProcessor = mock2.Object;
            var mock3 = new Mock <IDataSetDetailSqlRepo>();

            _sqlRepo = mock3.Object;
            var sut = new DataSetDetailUploaderService(_dataSetSchemaService, _repositoryDataSetDetail, _csvProcessor, _sqlRepo);
            //act
            var result = sut.SaveCsv(1, "title", "filepathhere");

            //assert
            Assert.AreEqual("Unable to find schema 1", result.Errors[0]);
            //cleanup
            _dataSetSchemaService = null;
            _csvProcessor         = null;
            _sqlRepo = null;
        }
        public void SaveCsv_returns_type_of_upload_result()
        {
            //arrange
            var mock = new Mock <IDataSetSchemaService>();

            _dataSetSchemaService = mock.Object;
            var mock2 = new Mock <IDataSetDetailCsvProcessor>();

            _csvProcessor = mock2.Object;
            var mock3 = new Mock <IDataSetDetailSqlRepo>();

            _sqlRepo = mock3.Object;
            var sut = new DataSetDetailUploaderService(_dataSetSchemaService, _repositoryDataSetDetail, _csvProcessor, _sqlRepo);
            //act
            var result = sut.SaveCsv(1, "title", "filepathhere");

            //assert
            Assert.AreEqual(typeof(UploadResult), result.GetType());
            //cleanup
            _dataSetSchemaService = null;
            _csvProcessor         = null;
            _sqlRepo = null;
        }
        public void SaveCsv_when_exception_is_thrown_returns_uploadresult_with_error_message_contains_error_validating()
        {
            //arrange
            var schema = new DataSetSchema();
            var mock   = new Mock <IDataSetSchemaService>();

            mock.Setup(x => x.Get(1)).Returns(schema);
            _dataSetSchemaService = mock.Object;
            var uploadResult = new UploadResult();
            var mock2        = new Mock <IDataSetDetailCsvProcessor>();

            mock2.Setup(x => x.ProcessCsv("filepathhere", schema, "title")).Returns(uploadResult);
            _csvProcessor = mock2.Object;
            var sut = new DataSetDetailUploaderService(_dataSetSchemaService, _repositoryDataSetDetail, _csvProcessor, _sqlRepo);
            //act
            var result = sut.SaveCsv(1, "title", "filepathhere");

            //assert
            Assert.AreEqual(true, result.Errors[0].Contains("Error Validating"));
            //cleanup
            _dataSetSchemaService = null;
            _csvProcessor         = null;
            _sqlRepo = null;
        }