Beispiel #1
0
        public void TestBrowseCubeShowRule()
        {
            // Arrange
            Reset();
            var dataset    = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);
            var dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            var measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var task       = BusinessLayerTestHelper.GetTask(dataset);
            var rule       = BusinessLayerTestHelper.GetAssociationRule(dimensions, measures, task);

            _data.Setup(d => d.GetRule(It.IsAny <int>())).Returns(rule);
            _arMapper.Setup(ar => ar.GetXAndLegendDimensionsId(It.IsAny <AssociationRule>(), It.IsAny <DimensionTree>()))
            .Returns(Tuple.Create(1, 1));
            var tree = BusinessLayerTestHelper.CreateDimensionTree(BusinessLayerTestHelper.DatasetName);

            _treeBuilder.Setup(tb => tb.ConvertToTree(It.IsAny <int>(), It.IsAny <bool>())).Returns(tree);
            // Act
            var result = _bc.ShowChart(1);

            // Assert
            _data.Verify(d => d.GetRule(1), Times.Once);
            _treeBuilder.Verify(tb => tb.ConvertToTree(It.IsAny <int>(), It.IsAny <bool>()));
            _arMapper.Verify(ar => ar.GetXAndLegendDimensionsId(It.IsAny <AssociationRule>(), It.IsAny <DimensionTree>()));
            _arMapper.Verify(ar => ar.GetFilterValues(It.IsAny <AssociationRule>()));
            _arMapper.Verify(ar => ar.GetChartText(It.IsAny <AssociationRule>()));
            ShowChartCalled();
        }
        public void TestTaskPmml()
        {
            // Arrange
            Reset();
            SetupQuerier();
            var dataset = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);

            dataset.Dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            dataset.Measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var task      = BusinessLayerTestHelper.GetTask(dataset);
            var rowcount  = 9;
            var tree      = _treeBuilder.ConvertToTree(dataset.Dimensions);
            var eqClasses = _discretizator.GetEquivalencyClasses(tree);
            // Act
            var pmml = _generateTestee.GetTaskPmml(task, eqClasses, rowcount);
            // Assert
            var header           = pmml.SelectNodes("//*[local-name()='Header']").Cast <XmlNode>().Single();
            var associationModel = pmml.SelectNodes("//*[local-name()='AssociationModel']").Cast <XmlNode>().Single();
            var thresholds       = pmml.SelectNodes("//*[local-name()='InterestMeasureThreshold']").Cast <XmlNode>().ToList();

            thresholds[0].ChildNodes.Item(0).InnerText.ShouldBeEquivalentTo("BASE");
            thresholds[0].ChildNodes.Item(1).InnerText.ShouldBeEquivalentTo("Greater than or equal");
            thresholds[0].ChildNodes.Item(2).InnerText.ShouldBeEquivalentTo("1");
            thresholds[1].ChildNodes.Item(0).InnerText.ShouldBeEquivalentTo("AAD");
            thresholds[1].ChildNodes.Item(1).InnerText.ShouldBeEquivalentTo("Greater than or equal");
            thresholds[1].ChildNodes.Item(2).InnerText.ShouldBeEquivalentTo("2");
        }
        public void TestPreprocessingPmml()
        {
            // Arrange
            Reset();
            SetupQuerier();
            var dataset = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);

            dataset.Dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            dataset.Measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var task            = BusinessLayerTestHelper.GetTask(dataset);
            var rowcount        = 9;
            var discretizations = _discretizator.GetDiscretizations(dataset, rowcount);
            // Act
            var pmml = _generateTestee.GetPreprocessingPmml(task, discretizations, rowcount);
            // Assert
            var header                   = pmml.SelectNodes("//*[local-name()='Header']").Cast <XmlNode>().Single();
            var miningBuildTask          = pmml.SelectNodes("//*[local-name()='MiningBuildTask']").Cast <XmlNode>().Single();
            var dataDictionary           = pmml.SelectNodes("//*[local-name()='DataDictionary']").Cast <XmlNode>().Single();
            var transformationDictionary = pmml.SelectNodes("//*[local-name()='TransformationDictionary']").Cast <XmlNode>().Single();
            var derivedFields            = pmml.SelectNodes("//*[local-name()='DerivedField']").Cast <XmlNode>().ToList();
            var columns                  = pmml.SelectNodes("//*[local-name()='Column']").Cast <XmlNode>().ToList();
            var discretizeBins           = pmml.SelectNodes("//*[local-name()='DiscretizeBin']").Cast <XmlNode>().ToList();

            dataDictionary.Attributes["numberOfFields"].InnerText.ShouldBeEquivalentTo("6"); // Product, Category, Place, Region, Id, Units
            derivedFields.Count.ShouldBeEquivalentTo(6);
            columns.Count.ShouldBeEquivalentTo(7);
            discretizeBins.Count.ShouldBeEquivalentTo(5);
            discretizeBins[0].Attributes["binValue"].InnerText.ShouldBeEquivalentTo("[5;10]");
            discretizeBins[1].Attributes["binValue"].InnerText.ShouldBeEquivalentTo("[10;10]");
            discretizeBins[2].Attributes["binValue"].InnerText.ShouldBeEquivalentTo("[10;20]");
            discretizeBins[3].Attributes["binValue"].InnerText.ShouldBeEquivalentTo("[20;20]");
            discretizeBins[4].Attributes["binValue"].InnerText.ShouldBeEquivalentTo("[20;80]");
        }
        public void TestResultsPmml()
        {
            // Arrange
            Reset();
            var dataset = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);

            dataset.Dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            dataset.Measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var dimensionValues = new List <DimensionValue>();

            foreach (var dimension in dataset.Dimensions)
            {
                dimensionValues.AddRange(dimension.DimensionValues);
            }
            // Act
            var rules = _parseTestee.GetRules(dimensionValues, dataset.Measures.ToList());

            // Assert
            rules.Count.ShouldBeEquivalentTo(1);
            rules[0].AntecedentValues.ToList()[0].Dimension.Name.ShouldBeEquivalentTo("Product");
            rules[0].AntecedentValues.ToList()[0].Value.ShouldBeEquivalentTo("Bread");
            rules[0].Succedents.ToList()[0].Measure.Name.ShouldBeEquivalentTo("Units");
            rules[0].ConditionValues.ToList()[0].Dimension.Name.ShouldBeEquivalentTo("Category");
            rules[0].ConditionValues.ToList()[0].Value.ShouldBeEquivalentTo("Bakery");
        }
        public void TestCreateAndFillFactTableAndCreateView()
        {
            // Arrange
            Reset();
            SetupConnection();

            var dataset    = BusinessLayerTestHelper.CreateDataset(DatasetName);
            var dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            var values     = BusinessLayerTestHelper.GetValuesDataTable();
            var measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var measure    = measures[0];

            SetupDataMock(dimensions);
            // Act
            _testee.CreateAndFillDimensionTables(DatasetName, dimensions, values);
            _testee.CreateFactTable(dataset, dimensions, measures);
            _testee.FillFactTable(DatasetName, dimensions, measures, values);
            _testee.CreateView(dataset, dimensions, measures);
            var czechRepRows = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Place", "Czech republic")), measure);
            var slovakiaRows = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Place", "Slovakia")), measure);
            var russiaRows   = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Place", "Russia")), measure);
            var breadRows    = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Product", "Bread")), measure);
            var bunRows      = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Product", "Bun")), measure);
            var milkRows     = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Product", "Milk")), measure);
            var europeRows   = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Region", "Europe")), measure);
            var asiaRows     = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Region", "Asia")), measure);
            var bakeryRows   = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Category", "Bakery")), measure);
            var dairyRows    = GetViewValues(_queryBuilder.Select($"{DatasetName}View", GetSelector(dimensions, "Category", "Dairy")), measure);

            // Assert
            czechRepRows.Count.ShouldBeEquivalentTo(3);
            czechRepRows.Sum().ShouldBeEquivalentTo(80);
            slovakiaRows.Count.ShouldBeEquivalentTo(3);
            slovakiaRows.Sum().ShouldBeEquivalentTo(35);
            russiaRows.Count.ShouldBeEquivalentTo(3);
            russiaRows.Sum().ShouldBeEquivalentTo(165);

            breadRows.Count.ShouldBeEquivalentTo(3);
            breadRows.Sum().ShouldBeEquivalentTo(80);
            bunRows.Count.ShouldBeEquivalentTo(3);
            bunRows.Sum().ShouldBeEquivalentTo(150);
            milkRows.Count.ShouldBeEquivalentTo(3);
            milkRows.Sum().ShouldBeEquivalentTo(50);

            europeRows.Count.ShouldBeEquivalentTo(6);
            europeRows.Sum().ShouldBeEquivalentTo(115);
            asiaRows.Count.ShouldBeEquivalentTo(3);
            asiaRows.Sum().ShouldBeEquivalentTo(165);

            bakeryRows.Count.ShouldBeEquivalentTo(6);
            bakeryRows.Sum().ShouldBeEquivalentTo(230);
            dairyRows.Count.ShouldBeEquivalentTo(3);
            dairyRows.Sum().ShouldBeEquivalentTo(50);
        }
Beispiel #6
0
        public void TestUploadCreateDatasetManually()
        {
            // Arrange
            Reset();
            var dataset = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);

            dataset.Dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            dataset.Measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            _data.Setup(d => d.GetDataset(It.IsAny <int>())).Returns(dataset);
            _validations.Setup(
                v =>
                v.DatatypesAreValid(It.IsAny <AttributeViewModel[]>(), It.IsAny <int>(), It.IsAny <string>(),
                                    It.IsAny <string>())).Returns(new List <string>());
            // Act
            var result = _uc.CreateDatasetManually(1, new AttributeViewModel[] {}, ";", "dd.MM.yyyy");
            // Assert
        }
Beispiel #7
0
        public void TestBrowseCubeMapDataset()
        {
            // Arrange
            var dataset =
                BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);

            dataset.Dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            dataset.Measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var filter = new FilterViewModel();
            // Act
            var model = _bcvmm.Map(dataset, filter);

            // Assert
            model.Dataset.Dimensions.Count.ShouldBeEquivalentTo(4);
            model.Dataset.Measures.Count.ShouldBeEquivalentTo(1);
            model.GroupedChart.ShouldBeEquivalentTo(null);
            model.DrilldownChart.ShouldBeEquivalentTo(null);
        }
Beispiel #8
0
        public void TestUploadCreateDataset()
        {
            // Arrange
            Reset();
            var dataset = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);

            dataset.Dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            dataset.Measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            _data.Setup(d => d.GetDataset(It.IsAny <int>())).Returns(dataset);
            _validations.Setup(
                v =>
                v.DatatypesAreValid(It.IsAny <AttributeViewModel[]>(), It.IsAny <int>(), It.IsAny <string>(),
                                    It.IsAny <string>())).Returns(new List <string>());
            _handler.Setup(h => h.SaveFile(It.IsAny <HttpPostedFileBase>(), It.IsAny <string>()))
            .Returns(new RecommenderFile());
            _datasetMapper.Setup(dm => dm.Map(It.IsAny <Dataset>(), It.IsAny <FilterViewModel>())).Returns(new SingleDatasetViewModel());
            // Act
            var result = _uc.CreateDataset(1, ";");
            // Assert
        }
        public void TestMapRuleToView()
        {
            // Arrange
            var dataset    = BusinessLayerTestHelper.CreateDataset(BusinessLayerTestHelper.DatasetName);
            var dimensions = BusinessLayerTestHelper.CreateDimensions(dataset);
            var measures   = BusinessLayerTestHelper.CreateMeasures(dataset);
            var tree       = BusinessLayerTestHelper.CreateDimensionTree(BusinessLayerTestHelper.DatasetName);
            var task       = BusinessLayerTestHelper.GetTask(dataset);
            var rule       = BusinessLayerTestHelper.GetAssociationRule(dimensions, measures, task);

            Setup(dimensions, tree);
            // Act
            var ids     = _mapper.GetXAndLegendDimensionsId(rule, tree);
            var filters = _mapper.GetFilterValues(rule).ToList();
            var text    = _mapper.GetChartText(rule);

            // Assert
            ids.Item1.ShouldBeEquivalentTo(1);
            ids.Item2.ShouldBeEquivalentTo(4);
            filters.Count.ShouldBeEquivalentTo(1);
            filters[0].Name.ShouldBeEquivalentTo("Category");
            filters[0].DimensionValues[0].Value.ShouldBeEquivalentTo("Bakery");
            text.ShouldBeEquivalentTo("Association rule: ");
        }