public void Index_when_schema_is_not_null_and_schema_detail_is_not_null_and_schema_is_online_and_is_external_data_returns_ViewResult_ExternalDataset() { //arrange var schema = "schemanotNull"; var schemaDetail = new DataSetSchema() { IsDisabled = false, IsApproved = true, IsExternalData = true, Category = new Category() { IsDisabled = false } }; var filter = new List <FilterCriteria>(); var mock = new Mock <IDataSetSchemaService>(); mock.Setup(x => x.Get(schema)).Returns(schemaDetail); _dataSchemaService = mock.Object; var mock2 = new Mock <IDataSetDetailService>(); mock2.Setup(x => x.SearchSchema(filter, schemaDetail, "", "")).Returns(new ViewControllerData()); _datasetDetailService = mock2.Object; var sut = new ViewController(_dataSchemaService, _datasetDetailService, _categoryService, _sysConfigService); //action var result = (ViewResult)sut.Index("category", schema, 1, 1, "", "", filter, "", ""); //assert Assert.AreEqual("ExternalDataSet", result.ViewName); //cleanup _dataSchemaService = null; _datasetDetailService = null; }
public void Index_when_category_url_schema_url_filetitle_is_given_and_format_is_xml_returns_XmlDocument_that_is_not_empty() { //arrange var mock = new Mock <IDataSetSchemaService>(); mock.Setup(x => x.Get("schemaurl")).Returns(new DataSetSchema()); _datasetschemaservice = mock.Object; var dt = new DataTable("tablename"); dt.Columns.Add(new DataColumn("test")); var row = dt.NewRow(); row["test"] = "testvalue"; dt.Rows.Add(row); var mock2 = new Mock <IDataSetDetailService>(); mock2.Setup(x => x.GetData("dataseturl", "schemaurl")).Returns(dt); _datasetdetailservice = mock2.Object; var customersController = new DownloadController(_datasetschemaservice, _datasetdetailservice, _categoryservice, _systemConfigurationService); // Act var result = customersController.Index("categoryurl", "schemaurl", "dataseturl", "xml", null, null, null, null) as XmlResult; // Assert Assert.IsTrue(((XmlDocument)result.ObjectToSerialize).HasChildNodes, "Xml document was empty"); }
Ajax_when_getVisualisationData_is_true_and_chart_type_is_NOT_map_and_schema_definition_hasLatLngColumns_SETS_chartNumberToShow_value_from_WebConfig_if_null_andReturns_data_from_visualiseSchema () { //arrange string category = ""; string schema = ""; int? currentPage = null; int? numberToShow = null; string orderByColumn = ""; string orderByDirection = ""; IList <FilterCriteria> filter = new List <FilterCriteria>(); string download = ""; bool getVisualisationData = true; string chartType = ""; string xAxis = ""; string yAxis = ""; int chartCurrentPage = 1; int chartNumberToShow = 10; string yAxisAggregate = ""; DataSetSchema schemaDetail = new DataSetSchema() { Definition = new DataSetSchemaDefinition() { Columns = new List <DataSetSchemaColumn>() { new DataSetSchemaColumn() { ColumnName = "Latitude" }, new DataSetSchemaColumn() { ColumnName = "Longitude" } } } }; var mock = new Mock <IDataSetDetailService>(); mock.Setup(x => x.VisualiseSchema(filter, schemaDetail, 1, 10, chartType, xAxis, yAxis, yAxisAggregate)).Returns(new ViewControllerData() { DataGraph = "fromVisualiseSchema" }); _datasetDetailService = mock.Object; var mock2 = new Mock <IDataSetSchemaService>(); mock2.Setup(x => x.Get(schema)).Returns(schemaDetail); _dataSchemaService = mock2.Object; var sut = new ViewController(_dataSchemaService, _datasetDetailService, _categoryService, _sysConfigService); //action var result = (JsonResult)sut.Ajax(category, schema, currentPage, numberToShow, orderByColumn, orderByDirection, filter, download, getVisualisationData, chartType, xAxis, yAxis, chartCurrentPage, null, yAxisAggregate); var unboxedResult = (ViewControllerData)result.Data; //assert Assert.AreEqual(unboxedResult.DataGraph, "fromVisualiseSchema"); //cleanup }
Ajax_when_getVisualisationData_is_FALSE_returns_result_from_search_schema() { //arrange string category = ""; string schema = ""; int currentPage = 1; int numberToShow = 10; string orderByColumn = ""; string orderByDirection = ""; IList <FilterCriteria> filter = new List <FilterCriteria>(); string download = ""; bool getVisualisationData = false; string chartType = ""; string xAxis = ""; string yAxis = ""; int chartCurrentPage = 1; int chartNumberToShow = 10; string yAxisAggregate = ""; DataSetSchema schemaDetail = new DataSetSchema() { Definition = new DataSetSchemaDefinition() { Columns = new List <DataSetSchemaColumn>() { new DataSetSchemaColumn() { ColumnName = "Latitude" }, new DataSetSchemaColumn() { ColumnName = "Longitude" } } } }; var mock = new Mock <IDataSetDetailService>(); mock.Setup(x => x.SearchSchema(filter, schemaDetail, currentPage, numberToShow, orderByColumn, orderByDirection, true)).Returns(new ViewControllerData() { DataGraph = "fromSearchSchema" }); _datasetDetailService = mock.Object; var mock2 = new Mock <IDataSetSchemaService>(); mock2.Setup(x => x.Get(schema)).Returns(schemaDetail); _dataSchemaService = mock2.Object; var sut = new ViewController(_dataSchemaService, _datasetDetailService, _categoryService, _sysConfigService); //action var result = (JsonNetResult)sut.Ajax(category, schema, currentPage, numberToShow, orderByColumn, orderByDirection, filter, download, getVisualisationData, chartType, xAxis, yAxis, chartCurrentPage, null, yAxisAggregate); var unboxedResult = (ViewControllerData)result.Data; //assert Assert.AreEqual(unboxedResult.DataGraph, "fromSearchSchema"); //cleanup }
public DownloadController(IDataSetSchemaService dataSetSchemaService, IDataSetDetailService dataSetDetailService, ICategoryService categoryService, ISystemConfigurationService systemConfigurationService) : base(systemConfigurationService, categoryService) { _dataSetSchemaService = dataSetSchemaService; _dataSetDetailService = dataSetDetailService; _categoryService = categoryService; }
public void Index_when_schema_is_not_null_and_schema_detail_is_not_null_schema_is_online_Filter_has_value_and_Not_external_data_will_use_Search_schema_to_return_viewControllerData() { //arrange var schema = "schemanotNull"; var schemaDetail = new DataSetSchema() { IsDisabled = false, IsApproved = true, IsExternalData = false, Category = new Category() { IsDisabled = false } }; var filter = new List <FilterCriteria>() { new FilterCriteria() { } }; var mock = new Mock <IDataSetSchemaService>(); mock.Setup(x => x.Get(schema)).Returns(schemaDetail); _dataSchemaService = mock.Object; var mock2 = new Mock <IDataSetDetailService>(); mock2.Setup(x => x.SearchSchema(filter, schemaDetail, 1, 1, "", "", true)).Returns(new ViewControllerData() { Count = 1234 }); _datasetDetailService = mock2.Object; var sut = new ViewController(_dataSchemaService, _datasetDetailService, _categoryService, _sysConfigService); //action var result = (ViewResult)sut.Index("category", schema, 1, 1, "", "", filter, "", ""); var model = (ViewControllerData)result.Model; //assert Assert.AreEqual(1234, model.Count); //cleanup _dataSchemaService = null; _datasetDetailService = null; }
public void TestInit() { _repositoryDataSetSchema = new MemoryRepository <DataSetSchema>(); _datasetschemaservice = GetMockDataSetSchemaService(); _esdFunctionService = GetMockEsdFunctionService(); _mockFileSystem = GetMockFileSystem(); _datasetdetailservice = Getdatasetdetailservice(); ObjectFactory.Initialize( x => { x.For <IUnitOfWorkFactory>().Use <MemoryUnitOfWorkFactory>(); x.For <IDataSetSchemaService>().Use(_datasetschemaservice); x.For <IEsdFunctionService>().Use(_esdFunctionService); x.For <IFileSystem>().Use(_mockFileSystem); x.For <IDataTableSerializer>().Use <CustomDataTableToJsonSerializer>().Named("json"); x.For <IDataTableSerializer>().Use <CustomDataTableToXmlSerializer>().Named("xml"); x.For <IDataSetDetailService>().Use(_datasetdetailservice); } ); }
public void Index_when_category_url_schema_url_filetitle_is_given_and_format_is_xml_returns_XmlResulttype() { //arrange var mock = new Mock <IDataSetSchemaService>(); mock.Setup(x => x.Get("schemaurl")).Returns(new DataSetSchema()); _datasetschemaservice = mock.Object; var dt = new DataTable("tablename"); var mock2 = new Mock <IDataSetDetailService>(); mock2.Setup(x => x.GetData("dataseturl", "schemaurl")).Returns(dt); _datasetdetailservice = mock2.Object; var customersController = new DownloadController(_datasetschemaservice, _datasetdetailservice, _categoryservice, _systemConfigurationService); // Act var result = customersController.Index("categoryurl", "schemaurl", "dataseturl", "xml", null, null, null, null); // Assert Assert.AreEqual(typeof(XmlResult), result.GetType(), "Should have returned an XmlResult"); //Assert.IsNotNull(result, "Should have returned an XmlResult"); //Assert.IsTrue(((XmlDocument)result.ObjectToSerialize).HasChildNodes, "Xml document was empty"); }
public void SetUp() { var mock3 = new Mock <ISystemConfigurationService>(); mock3.Setup(x => x.GetSystemConfigurations()).Returns(new SystemConfigurationObject() { SettingId = 1 }); _systemConfigurationService = mock3.Object; var schemas = new List <DataSetSchema>() { new DataSetSchema() { Title = "datasetschema1" } }; var mock = new Mock <ICategoryService>(); mock.Setup(x => x.GetAll(false)).Returns(new List <Category>() { new Category() { Title = "SampleCat1", Schemas = schemas } }); mock.Setup(x => x.GetByFriendlyUrl("samplecat1", false)).Returns(new List <DataSetSchema>() { new DataSetSchema() { Title = "sampledatasetschema1" } }); mock.Setup(x => x.GetByFriendlyUrlIsOnline("samplecat1")).Returns(new RestSchema[] { new RestSchema(), }); _categoryService = mock.Object; var mock2 = new Mock <IDataSetSchemaService>(); mock2.Setup(x => x.GetByFriendlyUrl("samplecat1", "sampledatasetschema1", false)).Returns(new DataSetDetail[] { new DataSetDetail() { Title = "datasetdetail1" }, }); mock2.Setup(x => x.Get("sampledatasetschema1")).Returns(new DataSetSchema() { Description = "emptydesc", Definition = new DataSetSchemaDefinition() { Columns = new List <DataSetSchemaColumn>() } }); mock2.Setup(x => x.Repository.GetQuery()) .Returns(new List <DataSetSchema>() { new DataSetSchema() { Title = "datasetschema1", IsDisabled = false, IsApproved = true, Category = new Category() { Title = "categoryds1", IsDisabled = false, } } }.AsQueryable); _dataSetSchemaService = mock2.Object; var datatable = new DataTable("datatablename"); datatable.Columns.Add(new DataColumn("TransactionDate", typeof(DateTime))); datatable.Columns.Add(new DataColumn("Amount", typeof(double))); datatable.Columns.Add(new DataColumn("Service", typeof(string))); var row = datatable.NewRow(); row["TransactionDate"] = new DateTime(2009, 11, 30); row["Service"] = "Children's Services - Commissioning & Social Work"; row["Amount"] = 1000; datatable.Rows.Add(row); //var row2 = datatable.NewRow(); //row2["TransactionDate"] = new DateTime(2009, 11, 30); //row2["Amount"] = 1000; //datatable.Rows.Add(row2); var mock4 = new Mock <IDataSetDetailService>(); mock4.Setup(x => x.GetData("datasetdetail1", "sampledatasetschema1")).Returns(new DataTable()); mock4.SetReturnsDefault(new ViewControllerData() { Count = 1, Data = datatable }); _dataSetDetailService = mock4.Object; // Setup StructureMap to determine the concrete repository pattern to use. ObjectFactory.Initialize( x => { //x.For<IUnitOfWorkFactory>().Use<EFUnitOfWorkFactory>(); x.For <IUnitOfWorkFactory>().Use <MemoryUnitOfWorkFactory>(); x.For(typeof(IRepository <>)).Use(typeof(MemoryRepository <>)); x.For <ICategoryService>().Use(_categoryService); x.For <IDataSetSchemaService>().Use(_dataSetSchemaService); x.For <IDataSetDetailService>().Use(_dataSetDetailService); x.For <IDataTableSerializer>().Use <CustomDataTableToJsonSerializer>().Named("json"); x.For <IDataTableSerializer>().Use <CustomDataTableToXmlSerializer>().Named("xml"); } ); //// Select an Entity Framework model to use with the factory. //EFUnitOfWorkFactory.SetObjectContext(() => new DataShareContext()); ////Never recreate the database //Database.SetInitializer<DataShareContext>(null); //_dataSetDetailService = new DataSetDetailService(_systemConfigurationService, ObjectFactory.GetInstance<IRepository<DataSetDetail>>() // , ObjectFactory.GetInstance<IDataSetSchemaService>() // , ObjectFactory.GetInstance<IDataSetDetailSqlRepo>() // ); //_dataSetSchemaDefinitionService = new DataSetSchemaDefinitionService(ObjectFactory.GetInstance<IRepository<DataSetSchemaDefinition>>()); //_dataSetSchemaService = new DataSetSchemaService(ObjectFactory.GetInstance<IRepository<DataSetSchema>>(), // _dataSetSchemaDefinitionService // , ObjectFactory.GetInstance<IRepository<DataSetDetail>>() // , ObjectFactory.GetInstance<ISqlTableUtility>()); //_contactService = new ContactService(ObjectFactory.GetInstance<IRepository<Contact>>()); //_categoryService = new CategoryService(ObjectFactory.GetInstance<IRepository<Category>>(), new FakeCacheProvider()); }