private List <Measure> GetModelWithMeasures(int numberOfMeasures) { var model = new TabularModelHandler().Model; var t1 = model.AddTable(); return(Enumerable.Repeat(0, numberOfMeasures).Select(i => t1.AddMeasure(null, "1+2")).ToList()); }
public void TestWithoutDisplayFolders() { var handler = new TabularModelHandler(1470); var tree = new TabularUITree(handler); var model = handler.Model; tree.Options = LogicalTreeOptions.Default & ~LogicalTreeOptions.DisplayFolders; var t1 = model.AddTable("Table 1"); t1.AddDataColumn("Column 1"); t1.AddMeasure("Measure 1"); var cg1 = model.AddCalculationGroup("Calc Group 1"); cg1.Field.Name = "Field"; var ci1 = cg1.AddCalculationItem("Item 1"); var cg1Path = tree.GetPath(cg1); var ci1Path = tree.GetPath(ci1); Assert.AreEqual(5, ci1Path.FullPath.Length); Assert.IsTrue( ci1Path.FullPath.SequenceEqual( new object[] { model, model.Groups.Tables, cg1, cg1.Field, ci1 })); Assert.AreEqual(1, tree.GetChildren(cg1Path).Count()); cg1.Field.DisplayFolder = "Folder\\Subfolder"; Assert.AreEqual(5, tree.GetPath(ci1).FullPath.Length); }
public void BatchRenameColumnsFixupTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddTable("T1"); var c1 = t1.AddDataColumn("C1"); var c2 = t1.AddDataColumn("C2"); var m3 = t1.AddMeasure("M3", "SUM('T1'[C1])+SUM('T1'[C2])"); handler.BeginUpdate("Batch rename"); c1.Name = "C1X"; c2.Name = "C2X"; handler.EndUpdate(); Assert.AreEqual("SUM('T1'[C1X])+SUM('T1'[C2X])", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("SUM('T1'[C1])+SUM('T1'[C2])", m3.Expression); handler.BeginUpdate("Batch rename"); c2.Name = "C2X"; c1.Name = "C1X"; handler.EndUpdate(); Assert.AreEqual("SUM('T1'[C1X])+SUM('T1'[C2X])", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("SUM('T1'[C1])+SUM('T1'[C2])", m3.Expression); }
public void DeleteHierarchyAndLevelTest() { var handler = new TabularModelHandler("localhost", "AdventureWorks"); handler.Tree = new MockTree(handler.Model); var hierarchy = handler.Model.Tables["Date"].Hierarchies["Calendar"]; hierarchy.Delete(); handler.SaveDB(); Assert.IsFalse(handler.Model.Tables["Date"].Hierarchies.Contains("Calendar")); handler.UndoManager.Rollback(); handler.SaveDB(); Assert.IsTrue(handler.Model.Tables["Date"].Hierarchies.Contains("Calendar")); hierarchy.Levels["Quarter"].Delete(); hierarchy.Levels["Day"].Delete(); hierarchy.Levels["Year"].Delete(); handler.SaveDB(); Assert.AreEqual(0, hierarchy.Levels["Semester"].Ordinal); Assert.AreEqual(1, hierarchy.Levels["Month"].Ordinal); hierarchy.Delete(); handler.SaveDB(); handler.UndoManager.Rollback(); handler.SaveDB(); Assert.AreEqual(0, hierarchy.Levels["Year"].Ordinal); Assert.AreEqual(1, hierarchy.Levels["Semester"].Ordinal); Assert.AreEqual(2, hierarchy.Levels["Quarter"].Ordinal); Assert.AreEqual(3, hierarchy.Levels["Month"].Ordinal); Assert.AreEqual(4, hierarchy.Levels["Day"].Ordinal); }
public void UnrestrictedPbit1() { var handler = new TabularModelHandler("TestData\\AdvWorks1465.pbit"); handler.Settings = new TabularModelHandlerSettings { PBIFeaturesOnly = false }; Assert.AreEqual(PowerBIGovernanceMode.Unrestricted, handler.PowerBIGovernance.GovernanceMode); // In unrestricted mode, everything should be possible... foreach (var obj in handler.Model.GetChildrenRecursive(true).OfType <TabularObject>()) { // Get public properties: var type = obj.GetType(); var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.SetMethod != null).Select(p => p.Name); foreach (var prop in props) { if (prop == Properties.NAME && obj is SingleColumnRelationship) { continue; } Assert.IsTrue(obj.Editable(prop), $"'{prop}' not editable on {obj.GetTypeName()} '{obj.GetName()}'"); } } }
public void TestExistingDeployment() { var s = new Server(); s.Connect("localhost"); if (s.Databases.ContainsName("AdventureWorks_X")) { s.Databases["AdventureWorks_X"].Drop(); } s.Disconnect(); var orgModel = new TabularModelHandler("AdventureWorks2.bim"); TabularDeployer.Deploy(orgModel, "localhost", "AdventureWorks_X"); var modifiedModel = new TabularModelHandler("AdventureWorks.bim"); foreach (var p in modifiedModel.Model.Perspectives.ToList()) { p.Delete(); } modifiedModel.Model.Tables["Product"].Delete(); TabularDeployer.Deploy(modifiedModel, "localhost", "AdventureWorks_X"); TabularDeployer.Deploy(orgModel, "localhost", "AdventureWorks_X"); }
/// <summary> /// Deploys the specified database to the specified target server and database ID, using the specified options. /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful. /// </summary> /// <param name="db"></param> /// <param name="targetConnectionString"></param> /// <param name="targetDatabaseID"></param> /// <param name="options"></param> /// <returns></returns> internal static DeploymentResult Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseID, DeploymentOptions options, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(targetConnectionString)) { throw new ArgumentNullException("targetConnectionString"); } var s = new TOM.Server(); s.Connect(targetConnectionString); var tmsl = GetTMSL(db, s, targetDatabaseID, options, true); cancellationToken.Register(s.CancelCommand); var result = s.Execute(tmsl); if (result.ContainsErrors) { throw new Exception(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray())); } s.Refresh(); var deployedDB = s.Databases[targetDatabaseID]; return (new DeploymentResult( TabularModelHandler.CheckErrors(deployedDB).Select(t => string.Format("Error on {0}: {1}", GetName(t.Item1), t.Item2)), TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.DependencyError || t.Item2 == TOM.ObjectState.EvaluationError || t.Item2 == TOM.ObjectState.SemanticError) .Select(t => string.Format("Warning! Object not in \"Ready\"-state: {0} ({1})", GetName(t.Item1), t.Item2.ToString())), TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.CalculationNeeded || t.Item2 == TOM.ObjectState.NoData) .Select(t => string.Format("Information: Unprocessed object: {0} ({1})", GetName(t.Item1), t.Item2.ToString())) )); }
public void UpdateTomTests() { Ensure1500ModelExists(); var handler = new TabularModelHandler(Constants.AasServerName, "TomWrapperTest1500"); var cg1 = handler.Model.AddCalculationGroup("CG1"); var ci1 = cg1.AddCalculationItem("CI1", "SELECTEDMEASURE()"); Assert.AreEqual(handler.Model, ci1.Model); handler.SaveDB(); handler.RefreshTom(); cg1 = handler.Model.CalculationGroups.First(); ci1 = (handler.Model.Tables["CG1"] as CalculationGroupTable).CalculationItems[0]; Assert.AreEqual(cg1, ci1.Parent.Table); Assert.AreEqual(handler.Model, cg1.Model); Assert.AreEqual(handler.Model, ci1.Model); var jsonRep = Serializer.SerializeObjects(cg1.CalculationItems); var objContainer = Serializer.ParseObjectJsonContainer(jsonRep); Assert.IsTrue(objContainer[typeof(CalculationItem)].Length > 0, "JsonContainer empty after serializing calc items (this will prevent CTRL+C operations on calc items)"); cg1.Delete(); handler.UndoManager.Undo(); cg1 = handler.Model.CalculationGroups.First(); ci1 = (handler.Model.Tables["CG1"] as CalculationGroupTable).CalculationItems[0]; Assert.AreEqual(cg1, ci1.Parent.Table); Assert.AreEqual(handler.Model, cg1.Model); Assert.AreEqual(handler.Model, ci1.Model); }
public void PerformanceTest() { var handler = new TabularModelHandler("localhost", "AdventureWorks"); var uiTree = new TabularUITree(handler); handler.Model.Tables["Currency"].SetAnnotation("NotNull", "This is a test"); uiTree.FilterMode = FilterMode.Flat; var items = new List <ITabularNamedObject>(); uiTree.Filter = null; uiTree.Filter = ":GetAnnotation(\"NotNull\").Contains(\"test\")"; var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 1000; i++) { items.AddRange(uiTree.GetChildrenInternal(TreePath.Empty)); } sw.Stop(); // Run 1: 3935 // Run 2: 4042 Assert.IsTrue(sw.ElapsedMilliseconds < 1000); Assert.AreEqual(1000, items.Count); }
public void GetRelatedTablesInMeasureTest() { var orgModel = new TabularModelHandler("AdventureWorks2.bim"); var measures = orgModel.Model.AllMeasures.ToList(); Assert.AreEqual(58, measures.Count); string measureName = "Distinct Count Sales Orders"; var measure = measures.Where(m => m.Name == measureName).FirstOrDefault(); Assert.IsNotNull(measure); Assert.AreEqual(measureName, measure.Name); Assert.AreEqual("[Reseller Distinct Count Sales Order] + [Internet Distinct Count Sales Order]", measure.Expression); Assert.AreEqual("Sales Territory", measure.Table.Name); // process expression to leaf level measure //var regx = new Regex(@"(?<func1>[a-z]+)\(\[(?<numerator>.+)\]\)/(?<func2>[a-z]+)\(\[(?<denominator>.+)\]\)", RegexOptions.IgnoreCase); var regx2 = new Regex(@"('.*?')?\[.*?\]", RegexOptions.IgnoreCase); // or: @"\[[^]]+\]" @"\[.*?\]" foreach (var m in measures) { MatchCollection matches = regx2.Matches(m.Expression); if (matches.Count > 2) { var exprSet = new HashSet <string>(); foreach (Match ma in matches) { exprSet.Add(ma.Value); TestContext.WriteLine($"{m.Name} => {ma.Value}"); } } } }
public void MeasureListTest() { var orgModel = new TabularModelHandler("AdventureWorks2.bim"); var measures = orgModel.Model.AllMeasures.ToList(); Assert.AreEqual(58, measures.Count); }
public void DependenciesUndoTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddCalculatedTable("New table"); var m1 = t1.AddMeasure("Measure 1", "123"); var m2 = t1.AddMeasure("Measure 2", "234"); var m3 = t1.AddMeasure("Measure 3", "[Measure 1] + [Measure 2]"); Assert.AreEqual(1, m1.ReferencedBy.Measures.Count()); Assert.AreEqual(m3, m1.ReferencedBy.Measures.First()); Assert.AreEqual(2, m3.DependsOn.Measures.Count()); m3.Delete(); Assert.AreEqual(0, m1.ReferencedBy.Measures.Count()); handler.UndoManager.Undo(); m3 = t1.Measures["Measure 3"]; Assert.AreEqual(1, m1.ReferencedBy.Measures.Count()); Assert.AreEqual(m3, m1.ReferencedBy.Measures.First()); Assert.AreEqual(2, m3.DependsOn.Measures.Count()); }
public void PBIUnrestrictedTest() { var handler = new TabularModelHandler("TestData\\AdvWorks1520v3.pbit", new TabularModelHandlerSettings { PBIFeaturesOnly = false }); handler.Model.SetAnnotation("test", "value"); handler.Model.PropertyGridTest() .IsHidden(nameof(Model.Handler)) .IsReadWrite(nameof(Model.Name)) .IsReadWrite(nameof(Model.DeploymentMetadata)) .IsReadWrite(nameof(Model.Description)) .IsReadOnly(nameof(Model.Database)) .IsReadOnly(nameof(Model.Perspectives)) .IsReadOnly(nameof(Model.ObjectTypeName)) .IsReadOnly(nameof(Model.Annotations), "The annotations property is read only but existing annotations should be writable") .IsReadWrite($@"{nameof(Model.Annotations)}\test") .IsReadOnly(nameof(Model.ExtendedProperties)) .IsReadOnly(nameof(Model.Expressions), "Expressions should not be available for a CL1520 model.") .IsHidden(nameof(Model.ObjectType)) .IsHidden(nameof(Model.AllColumns)) .IsHidden(nameof(Model.CalculationGroups), "Calculation Groups should not be available as a property.") ; foreach (var item in handler.Model.GetChildrenRecursive(false)) { item.PropertyGridTest().AreHidden("Model", "Handler").NotHasCategory("Misc"); } }
public void PerformanceTest() { var handler = new TabularModelHandler("localhost", "AdventureWorks"); var model = handler.Model; var analyzer = new Analyzer(); analyzer.Model = model; var rule = new BestPracticeRule() { Scope = RuleScope.Measure | RuleScope.CalculatedColumn | RuleScope.DataColumn | RuleScope.Table | RuleScope.Hierarchy, Expression = "Description.Contains(\"todo\")" }; model.Tables["Currency"].Description = null; model.Tables["Geography"].Description = "todo"; var results = new List <AnalyzerResult>(); // Warm the cache: results.AddRange(analyzer.Analyze(rule)); results.Clear(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 1000; i++) { results.AddRange(analyzer.Analyze(rule)); } sw.Stop(); // 2600 Assert.IsTrue(sw.ElapsedMilliseconds < 5000); Assert.AreEqual(1000, results.Count); }
public void TestNewDeploymentNoErrors() { var newDbName = "AdventureWorks_UT_New1"; var server = new TOM.Server(); server.Connect("localhost"); if (server.Databases.ContainsName(newDbName)) { server.Databases[newDbName].Drop(); } var handler = new TabularModelHandler("AdventureWorks.bim"); var results = TabularDeployer.Deploy(handler, "localhost", newDbName); Assert.AreEqual(0, results.Issues.Count); Assert.AreNotEqual(0, results.Unprocessed.Count); Assert.AreEqual(0, results.Warnings.Count); server.Refresh(); if (server.Databases.ContainsName(newDbName)) { server.Databases[newDbName].Drop(); } }
public void ColumnsAndDataTypeNotVisibleInTreeTest() { var handler = new TabularModelHandler("localhost", "TestModel"); handler.Tree.Options = 0; // Hide everything var model = handler.Model; var table = model.AddCalculatedTable(); table.Expression = "ROW(\"Int64\", 1, \"String\", \"ABC\", \"Double\", 1.0)"; handler.SaveDB(); var itemsFromTree = handler.Tree.GetChildren(table).ToList(); Assert.AreEqual(0, itemsFromTree.Count); Assert.AreEqual(3, table.Columns.Count); Assert.AreEqual(DataType.Int64, table.Columns["Int64"].DataType); Assert.AreEqual(DataType.String, table.Columns["String"].DataType); Assert.AreEqual(DataType.Double, table.Columns["Double"].DataType); handler.UndoManager.Rollback(); handler.SaveDB(); }
public void TestNewDeploymentCalcColumnError() { var newDbName = "AdventureWorks_UT_New3"; var server = new TOM.Server(); server.Connect("localhost"); if (server.Databases.ContainsName(newDbName)) { server.Databases[newDbName].Drop(); } var handler = new TabularModelHandler("AdventureWorks.bim"); handler.Model.Tables["Employee"].AddCalculatedColumn("ErrorTest", "xxx"); var results = TabularDeployer.Deploy(handler, "localhost", newDbName); Assert.AreNotEqual(0, results.Issues.Count); Assert.AreNotEqual(0, results.Unprocessed.Count); Assert.AreNotEqual(0, results.Warnings.Count); server.Refresh(); if (server.Databases.ContainsName(newDbName)) { server.Databases[newDbName].Drop(); } }
public void ColumnsAndDataTypeVisibleInTreeAlphabeticalTest() { var handler = new TabularModelHandler("localhost", "TestModel"); handler.Tree.Options = LogicalTreeOptions.Columns | LogicalTreeOptions.DisplayFolders | LogicalTreeOptions.OrderByName; var model = handler.Model; var table = model.AddCalculatedTable(); table.Expression = "ROW(\"Int64\", 1, \"String\", \"ABC\", \"Double\", 1.0)"; handler.SaveDB(); var itemsFromTree = handler.Tree.GetChildren(table).ToList(); Assert.AreEqual(3, itemsFromTree.Count); Assert.AreEqual("Double", itemsFromTree[0].Name); Assert.AreEqual("Int64", itemsFromTree[1].Name); Assert.AreEqual("String", itemsFromTree[2].Name); Assert.AreEqual(3, table.Columns.Count); Assert.AreEqual(DataType.Int64, table.Columns["Int64"].DataType); Assert.AreEqual(DataType.String, table.Columns["String"].DataType); Assert.AreEqual(DataType.Double, table.Columns["Double"].DataType); handler.UndoManager.Rollback(); handler.SaveDB(); }
public void Database_Open(string connectionString, string databaseName) { using (new Hourglass()) { var oldHandler = Handler; try { Handler = new TabularModelHandler(connectionString, databaseName); if (Handler.PowerBIGovernance.GovernanceMode == TOMWrapper.PowerBI.PowerBIGovernanceMode.ReadOnly) { MessageBox.Show("Editing a Power BI Desktop model that does not use the Enhanced Model Metadata (V3) format is not allowed, unless you enable Experimental Power BI Features under File > Preferences.\n\nTabular Editor will still load the model in read-only mode.", "Power BI Desktop Model Read-only", MessageBoxButtons.OK, MessageBoxIcon.Warning); } File_Current = null; File_Directory = null; File_SaveMode = ModelSourceType.Database; LoadTabularModelToUI(); LocalInstanceName = ConnectForm.LocalInstanceName; LocalInstanceType = ConnectForm.LocalInstanceType; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error connecting to database", MessageBoxButtons.OK, MessageBoxIcon.Error); Handler = oldHandler; LoadTabularModelToUI(); } } }
public void CheckPerspectiveMembershipAfterSerialization_Positive() { { var handler = new TabularModelHandler(); var model = handler.Model; Table t1 = model.AddCalculatedTable("Table1"); Column c1 = t1.AddCalculatedColumn("Column1"); Column c2 = t1.AddCalculatedColumn("Column2"); var p1 = model.AddPerspective("TestPerspective"); c1.InPerspective[p1] = true; Assert.AreEqual(true, t1.InPerspective[p1]); Assert.AreEqual(true, c1.InPerspective[p1]); Assert.AreEqual(false, c2.InPerspective[p1]); Directory.CreateDirectory("test_2_7_4_perspective_membership_1"); handler.Save("test_2_7_4_perspective_membership_1", SaveFormat.TabularEditorFolder, new SerializeOptions { LocalPerspectives = true }); } { // Load from folder: var handler = new TabularModelHandler("test_2_7_4_perspective_membership_1"); var model = handler.Model; var p1 = model.Perspectives["TestPerspective"]; var t1 = model.Tables["Table1"]; var c1 = t1.Columns["Column1"]; var c2 = t1.Columns["Column2"]; Assert.AreEqual(true, t1.InPerspective[p1]); Assert.AreEqual(true, c1.InPerspective[p1]); Assert.AreEqual(false, c2.InPerspective[p1]); } }
public void DeleteHierarchyAndLevelTest() { var handler = new TabularModelHandler(Constants.ServerName, "TomWrapperTest"); var hierarchy = handler.Model.Tables["Date"].Hierarchies["Calendar"]; hierarchy.Delete(); handler.SaveDB(); Assert.IsFalse(handler.Model.Tables["Date"].Hierarchies.Contains("Calendar")); handler.UndoManager.Rollback(); handler.SaveDB(); Assert.IsTrue(handler.Model.Tables["Date"].Hierarchies.Contains("Calendar")); hierarchy.Levels["Quarter"].Delete(); hierarchy.Levels["Day"].Delete(); hierarchy.Levels["Year"].Delete(); handler.SaveDB(); Assert.AreEqual(0, hierarchy.Levels["Semester"].Ordinal); Assert.AreEqual(1, hierarchy.Levels["Month"].Ordinal); hierarchy.Delete(); handler.SaveDB(); handler.UndoManager.Rollback(); handler.SaveDB(); Assert.AreEqual(0, hierarchy.Levels["Year"].Ordinal); Assert.AreEqual(1, hierarchy.Levels["Semester"].Ordinal); Assert.AreEqual(2, hierarchy.Levels["Quarter"].Ordinal); Assert.AreEqual(3, hierarchy.Levels["Month"].Ordinal); Assert.AreEqual(4, hierarchy.Levels["Day"].Ordinal); }
public void EnsureAnnotationsAreRemovedTest() { Directory.CreateDirectory("test_2_8_annotations2"); File.WriteAllText(@"test_2_8_annotations1\database.json", DatabaseJsonCompare); var handler = new TabularModelHandler(@"test_2_8_annotations1\database.json"); var items = handler.Model.GetChildrenRecursive(true).ToList(); foreach (var item in items.OfType <IAnnotationObject>()) { if (item is Model) { Assert.AreEqual(1, item.GetAnnotationsCount()); Assert.IsTrue(item.HasAnnotation("TabularEditor_SerializeOptions")); } else { Assert.AreEqual(0, item.GetAnnotationsCount()); } } handler.Save("test_2_8_annotations1", SaveFormat.TabularEditorFolder, null, true); var databaseJson = File.ReadAllText(@"test_2_8_annotations1\database.json"); Assert.AreEqual(DatabaseJsonCompare, databaseJson); }
public void MinimalPerspectiveTest() { DeleteTestPerspectives(); var handler = new TabularModelHandler("localhost", "AdventureWorks"); handler.Tree = new MockTree(handler.Model); var m = handler.Model; // Perspective which includes everything except a few select items: var pnEx = "Test Perspective Exclusive"; Perspective.CreateNew(pnEx); m.Tables["Date 6"].InPerspective[pnEx] = true; m.Tables["Currency"].InPerspective[pnEx] = true; //m.Tables.InPerspective(pnEx, true); //m.Tables["Reseller Sales"].InPerspective[pnEx] = true; //m.Tables["Employee"].InPerspective[pnEx] = false; //m.Tables["Date"].Hierarchies.InPerspective(pnEx, false); //m.Tables["Internet Sales"].Measures.InPerspective(pnEx, false); //m.Tables["Product"].Columns.InPerspective(pnEx, false); //m.Tables["Reseller Sales"].Measures["Reseller Total Sales"].InPerspective[pnEx] = false; handler.SaveDB(); handler.UndoManager.Rollback(); handler.SaveDB(); // Check that perspectives were succesfully deleted: Assert.IsFalse(m.Perspectives.Contains(pnEx)); }
public void AlteringObjectPerspectiveTest() { Directory.CreateDirectory("test_2_8_annotations2"); File.WriteAllText(@"test_2_8_annotations2\database.json", DatabaseJsonCompare); var handler = new TabularModelHandler(@"test_2_8_annotations2\database.json"); var model = handler.Model; var t2 = model.Tables["Table 2"]; var c2 = t2.Columns["Column 2"]; Assert.IsTrue(c2.InPerspective["Perspective 2"]); c2.InPerspective["Perspective 2"] = false; Assert.IsFalse(c2.InPerspective["Perspective 2"]); handler.Save("test_2_8_annotations2", SaveFormat.TabularEditorFolder, null, true); handler = new TabularModelHandler(@"test_2_8_annotations2\database.json"); model = handler.Model; t2 = model.Tables["Table 2"]; c2 = t2.Columns["Column 2"]; Assert.IsFalse(c2.InPerspective["Perspective 2"]); c2.InPerspective["Perspective 2"] = true; Assert.IsTrue(c2.InPerspective["Perspective 2"]); handler.Save("test_2_8_annotations2", SaveFormat.TabularEditorFolder, null, true); var databaseJson = File.ReadAllText(@"test_2_8_annotations2\database.json"); Assert.AreEqual(DatabaseJsonCompare, databaseJson); }
public void File_New() { var cl = 0; var td = new TaskDialog(); var tdb1200 = new TaskDialogButton("btnCL1200", "CL 1200"); var tdb1400 = new TaskDialogButton("btnCL1400", "CL 1400"); var tdbCancel = new TaskDialogButton("btnCancel", "Cancel"); tdb1200.Click += (s, e) => { cl = 1200; td.Close(TaskDialogResult.CustomButtonClicked); }; tdb1400.Click += (s, e) => { cl = 1400; td.Close(TaskDialogResult.CustomButtonClicked); }; tdbCancel.Click += (s, e) => { td.Close(TaskDialogResult.Cancel); }; td.Controls.Add(tdb1200); td.Controls.Add(tdb1400); td.Controls.Add(tdbCancel); td.Caption = "Choose Compatibility Level"; td.Text = "Which Compatibility Level (1200 or 1400) do you want to use for the new model?"; var tdr = td.Show(); if (cl == 0) { return; } Handler = new TabularModelHandler(cl, Preferences.Current.GetSettings()); File_Current = null; File_SaveMode = Handler.SourceType; LoadTabularModelToUI(); }
public void TestNewDeploymentNoErrors() { var handler = new TabularModelHandler("localhost", "AdventureWorks"); var model = handler.Model; var table = model.Tables["Reseller Sales"]; var column = table.Columns["Gross Profit"] as CalculatedColumn; var measure = table.Measures["Reseller Total Gross Profit"]; measure.Expression = orgDax; column.Name = "GP"; Assert.AreEqual("SUM([GP]) +\n SUM('Reseller Sales'[GP])", measure.Expression); handler.UndoManager.Undo(); Assert.AreEqual(orgDaxNoCr, measure.Expression); handler.SaveDB(); column.Name = "Gross Profit XXX"; Assert.AreEqual("SUM([Gross Profit XXX]) +\n SUM('Reseller Sales'[Gross Profit XXX])", measure.Expression); handler.SaveDB(); column.Name = "GP"; Assert.AreEqual("SUM([GP]) +\n SUM('Reseller Sales'[GP])", measure.Expression); handler.SaveDB(); column.Name = "Gross Profit"; Assert.AreEqual(orgDaxNoCr, measure.Expression); handler.SaveDB(); }
public void BatchRenameMeasuresFixupTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddTable(); var m1 = t1.AddMeasure("M1", "1"); var m2 = t1.AddMeasure("M2", "2"); var m3 = t1.AddMeasure("M3", "[M1]+[M2]"); handler.BeginUpdate("Batch rename"); m1.Name = "M1X"; m2.Name = "M2X"; handler.EndUpdate(); Assert.AreEqual("[M1X]+[M2X]", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("[M1]+[M2]", m3.Expression); handler.BeginUpdate("Batch rename"); m2.Name = "M2X"; m1.Name = "M1X"; handler.EndUpdate(); Assert.AreEqual("[M1X]+[M2X]", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("[M1]+[M2]", m3.Expression); }
public void ModelWithTranslationsSerialization() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddCalculatedTable("NewTable"); var m1 = t1.AddMeasure("Measure1", "123"); var culture1 = model.AddTranslation("en-US"); var culture2 = model.AddTranslation("da-DK"); m1.TranslatedNames[culture1] = "Measure1US"; m1.TranslatedNames[culture2] = "Measure1DK"; Assert.AreEqual("{\"da-DK\":\"Measure1DK\",\"en-US\":\"Measure1US\"}", m1.TranslatedNames.ToJson()); Directory.CreateDirectory("test_2_7_4_translation_serialization"); handler.Save("test_2_7_4_translation_serialization", SaveFormat.TabularEditorFolder, new TabularEditor.TOMWrapper.Serialization.SerializeOptions() { Levels = new System.Collections.Generic.HashSet <string>(), LocalTranslations = true }); var savedMetadata = File.ReadAllText(@"test_2_7_4_translation_serialization\database.json"); Assert.AreEqual(DatabaseJson, savedMetadata); }
public void BatchRenameTablesFixupTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddTable("T1"); var t2 = model.AddTable("T2"); var m3 = t1.AddMeasure("M3", "COUNTROWS(T1)+COUNTROWS(T2)"); handler.BeginUpdate("Batch rename"); t1.Name = "T1X"; t2.Name = "T2X"; handler.EndUpdate(); Assert.AreEqual("COUNTROWS('T1X')+COUNTROWS('T2X')", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("COUNTROWS(T1)+COUNTROWS(T2)", m3.Expression); handler.BeginUpdate("Batch rename"); t2.Name = "T2X"; t1.Name = "T1X"; handler.EndUpdate(); Assert.AreEqual("COUNTROWS('T1X')+COUNTROWS('T2X')", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("COUNTROWS(T1)+COUNTROWS(T2)", m3.Expression); }
public void TestNewDeploymentMeasureError() { var newDbName = "AdventureWorks_UT_New2"; var server = new TOM.Server(); server.Connect(Constants.ServerName); if (server.Databases.ContainsName(newDbName)) { server.Databases[newDbName].Drop(); } var handler = new TabularModelHandler("TestData\\AdventureWorks.bim"); handler.Model.Tables["Employee"].AddMeasure("ErrorTest", "xxx"); var results = TabularDeployer.Deploy(handler, Constants.ServerName, newDbName); Assert.AreNotEqual(0, results.Issues.Count); Assert.AreNotEqual(0, results.Unprocessed.Count); Assert.AreEqual(0, results.Warnings.Count); server.Refresh(); if (server.Databases.ContainsName(newDbName)) { server.Databases[newDbName].Drop(); } }