public void InterSGCouplingMatrixIntegrity() { while (DataProvider.Instance.Controller != null) { Thread.Sleep(100); } // Setup variables SettingsProvider.Instance.Settings = new TLCGen.Models.Settings.TLCGenSettingsModel(); var mainwinvm = new MainWindowViewModel(); Assert.IsFalse(mainwinvm.HasController); Assert.IsTrue(mainwinvm.NewFileCommand.CanExecute(null)); mainwinvm.NewFileCommand.Execute(null); Assert.IsTrue(mainwinvm.HasController); var c = DataProvider.Instance.Controller; var controllervm = mainwinvm.ControllerVM; var fasentab = controllervm.FasenTabVM; var synctab = controllervm.CoordinatiesTabVM; // Add signal groups Assert.IsTrue(c.Fasen.Count == 0); Assert.IsTrue(fasentab.AddFaseCommand.CanExecute(null)); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); Assert.IsTrue(c.Fasen.Count == 5); // Check matrix Assert.IsTrue(synctab.DisplayType == TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict); Assert.IsTrue(synctab.ConflictMatrix != null); Assert.IsTrue(synctab.ConflictMatrix.GetLength(0) == 5); Assert.IsTrue(synctab.ConflictMatrix.GetLength(1) == 5); // Add conflicts synctab.ConflictMatrix[0, 1].ConflictValue = "10"; synctab.ConflictMatrix[1, 0].ConflictValue = "20"; synctab.ConflictMatrix[2, 4].ConflictValue = "0"; synctab.ConflictMatrix[4, 2].ConflictValue = "50"; synctab.ConflictMatrix[3, 2].ConflictValue = "FK"; Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null); // Check properties that set cell availability synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart; Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling || synctab.ConflictMatrix[0, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling || synctab.ConflictMatrix[1, 0].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling || synctab.ConflictMatrix[2, 4].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling || synctab.ConflictMatrix[4, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling || synctab.ConflictMatrix[3, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling || synctab.ConflictMatrix[2, 3].IsEnabled); // Set a "gelijkstart" // =================== Assert.IsTrue(synctab.ConflictMatrix[1, 3].AllowCoupling); synctab.ConflictMatrix[1, 3].IsCoupled = true; Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart); Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart); // Assert symmetry Assert.IsFalse(synctab.ConflictMatrix[3, 1].HasNoCoupling); Assert.IsFalse(synctab.ConflictMatrix[1, 3].HasNoCoupling); // Check properties that set cell availability in Conflict Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); // Check properties that set cell availability in Voorstart Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); // Check properties that set cell availability in Naloop Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop; Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled); // Set a "Voorstart" // ================= synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart; Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled); synctab.ConflictMatrix[4, 3].IsCoupled = true; Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Assert this cannot be also set on the opposite side Assert.IsTrue(synctab.ConflictMatrix[3, 4].HasOppositeVoorstart); // Check properties that set cell availability in Conflict Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Check properties that set cell availability in Voorstart Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart; Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Check properties that set cell availability in Naloop Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop; Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 4].IsEnabled); // Set a "Naloop" // ============== synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop; Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); synctab.ConflictMatrix[0, 2].IsCoupled = true; Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled); // Assert this _can_ be also set on the opposite side Assert.IsTrue(synctab.ConflictMatrix[0, 2].HasNaloop); Assert.IsTrue(synctab.ConflictMatrix[2, 0].HasOppositeNaloop); // Check properties that set cell availability in Conflict Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[0, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 0].IsEnabled); // Check properties that set cell availability in Gelijkstart Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart; Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with gelijkstart Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled); // Check properties that set cell availability in Voorstart Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Assert this cannot be also set on the opposite side Assert.IsTrue(synctab.ConflictMatrix[3, 4].HasOppositeVoorstart); Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with voorstart Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled); // Check properties that set cell availability in Naloop Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop; Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling || synctab.ConflictMatrix[0, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling || synctab.ConflictMatrix[1, 0].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling || synctab.ConflictMatrix[2, 4].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling || synctab.ConflictMatrix[4, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling || synctab.ConflictMatrix[3, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling || synctab.ConflictMatrix[2, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 4].IsEnabled); // Check and save Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null); // Simulate saving and opening // =========================== var ser = new TLCGen.DataAccess.SerializeT <ControllerModel>(); var deser = new TLCGen.DataAccess.DeserializeT <ControllerModel>(); var doc = ser.SerializeToXmlDocument(c); controllervm.HasChanged = false; Assert.IsTrue(mainwinvm.CloseFileCommand.CanExecute(null)); mainwinvm.CloseFileCommand.Execute(null); Assert.IsFalse(mainwinvm.HasController); mainwinvm.SetController(deser.SerializeFromXmlDocument(doc)); Assert.IsTrue(mainwinvm.HasController); c = DataProvider.Instance.Controller; controllervm = new ControllerViewModel(mainwinvm, c); fasentab = controllervm.FasenTabVM; synctab = controllervm.CoordinatiesTabVM; synctab.BuildConflictMatrix(); Assert.AreEqual("10", synctab.ConflictMatrix[0, 1].ConflictValue); Assert.AreEqual("20", synctab.ConflictMatrix[1, 0].ConflictValue); Assert.AreEqual("0", synctab.ConflictMatrix[2, 4].ConflictValue); Assert.AreEqual("50", synctab.ConflictMatrix[4, 2].ConflictValue); Assert.AreEqual("FK", synctab.ConflictMatrix[3, 2].ConflictValue); Assert.AreEqual("FK", synctab.ConflictMatrix[2, 3].ConflictValue); Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart); Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart); Assert.IsTrue(synctab.ConflictMatrix[4, 3].HasVoorstart); Assert.IsTrue(synctab.ConflictMatrix[3, 4].HasOppositeVoorstart); Assert.IsTrue(synctab.ConflictMatrix[0, 2].HasNaloop); Assert.IsTrue(synctab.ConflictMatrix[2, 0].HasOppositeNaloop); Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null); AssertConfictMatrixModelEqual(10, c, synctab.ConflictMatrix[0, 1]); AssertConfictMatrixModelEqual(20, c, synctab.ConflictMatrix[1, 0]); AssertConfictMatrixModelEqual(0, c, synctab.ConflictMatrix[2, 4]); AssertConfictMatrixModelEqual(50, c, synctab.ConflictMatrix[4, 2]); AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]); AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]); // Check properties that set cell availability in Conflict Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[0, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 0].IsEnabled); // Check properties that set cell availability in Gelijkstart Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart; Assert.IsFalse(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with gelijkstart Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled); // Check properties that set cell availability in Voorstart Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Voorstart; Assert.IsFalse(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 4].IsEnabled); // Assert this cannot be also set on the opposite side Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[0, 2].IsEnabled); // Naloop can go together with voorstart Assert.IsTrue(synctab.ConflictMatrix[2, 0].IsEnabled); // Check properties that set cell availability in Naloop Tab synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Naloop; Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling || synctab.ConflictMatrix[0, 1].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling || synctab.ConflictMatrix[1, 0].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling || synctab.ConflictMatrix[2, 4].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling || synctab.ConflictMatrix[4, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling || synctab.ConflictMatrix[3, 2].IsEnabled); Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling || synctab.ConflictMatrix[2, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 1].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[1, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[4, 3].IsEnabled); Assert.IsTrue(synctab.ConflictMatrix[3, 4].IsEnabled); controllervm.HasChanged = false; mainwinvm.CloseFileCommand.Execute(null); }
public void InterSGSerialization() { while (DataProvider.Instance.Controller != null) { Thread.Sleep(100); } // Setup variables SettingsProvider.Instance.Settings = new TLCGen.Models.Settings.TLCGenSettingsModel(); var mainwinvm = new MainWindowViewModel(); Assert.IsFalse(mainwinvm.HasController); Assert.IsTrue(mainwinvm.NewFileCommand.CanExecute(null)); mainwinvm.NewFileCommand.Execute(null); Assert.IsTrue(mainwinvm.HasController); var c = DataProvider.Instance.Controller; var controllervm = mainwinvm.ControllerVM; var fasentab = controllervm.FasenTabVM; var synctab = controllervm.CoordinatiesTabVM; Assert.IsTrue(c.Fasen.Count == 0); Assert.IsTrue(fasentab.AddFaseCommand.CanExecute(null)); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); fasentab.AddFaseCommand.Execute(null); Assert.IsTrue(c.Fasen.Count == 5); Assert.IsTrue(synctab.DisplayType == TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Conflict); Assert.IsTrue(synctab.ConflictMatrix != null); Assert.IsTrue(synctab.ConflictMatrix.GetLength(0) == 5); Assert.IsTrue(synctab.ConflictMatrix.GetLength(1) == 5); synctab.ConflictMatrix[0, 1].ConflictValue = "10"; synctab.ConflictMatrix[1, 0].ConflictValue = "20"; synctab.ConflictMatrix[2, 4].ConflictValue = "0"; synctab.ConflictMatrix[4, 2].ConflictValue = "50"; synctab.ConflictMatrix[3, 2].ConflictValue = "FK"; Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null); synctab.DisplayType = TLCGen.ViewModels.Enums.SynchronisatieTypeEnum.Gelijkstart; Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling); Assert.IsTrue(synctab.ConflictMatrix[1, 3].AllowCoupling); synctab.ConflictMatrix[1, 3].IsCoupled = true; Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart); Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart); Assert.IsFalse(synctab.ConflictMatrix[3, 1].HasNoCoupling); Assert.IsFalse(synctab.ConflictMatrix[1, 3].HasNoCoupling); Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null); // Simulate saving and opening var ser = new TLCGen.DataAccess.SerializeT <ControllerModel>(); var deser = new TLCGen.DataAccess.DeserializeT <ControllerModel>(); var doc = ser.SerializeToXmlDocument(c); controllervm.HasChanged = false; Assert.IsTrue(mainwinvm.CloseFileCommand.CanExecute(null)); mainwinvm.CloseFileCommand.Execute(null); Assert.IsFalse(mainwinvm.HasController); mainwinvm.SetController(deser.SerializeFromXmlDocument(doc)); Assert.IsTrue(mainwinvm.HasController); c = DataProvider.Instance.Controller; controllervm = new ControllerViewModel(mainwinvm, c); fasentab = controllervm.FasenTabVM; synctab = controllervm.CoordinatiesTabVM; synctab.BuildConflictMatrix(); Assert.AreEqual("10", synctab.ConflictMatrix[0, 1].ConflictValue); Assert.AreEqual("20", synctab.ConflictMatrix[1, 0].ConflictValue); Assert.AreEqual("0", synctab.ConflictMatrix[2, 4].ConflictValue); Assert.AreEqual("50", synctab.ConflictMatrix[4, 2].ConflictValue); Assert.AreEqual("FK", synctab.ConflictMatrix[3, 2].ConflictValue); Assert.AreEqual("FK", synctab.ConflictMatrix[2, 3].ConflictValue); Assert.IsTrue(TLCGen.Integrity.IntegrityChecker.IsConflictMatrixOK() == null); AssertConfictMatrixModelEqual(10, c, synctab.ConflictMatrix[0, 1]); AssertConfictMatrixModelEqual(20, c, synctab.ConflictMatrix[1, 0]); AssertConfictMatrixModelEqual(0, c, synctab.ConflictMatrix[2, 4]); AssertConfictMatrixModelEqual(50, c, synctab.ConflictMatrix[4, 2]); AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]); AssertConfictMatrixModelEqual(-2, c, synctab.ConflictMatrix[3, 2]); Assert.IsFalse(synctab.ConflictMatrix[0, 1].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[1, 0].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[2, 4].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[4, 2].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[3, 2].AllowCoupling); Assert.IsFalse(synctab.ConflictMatrix[2, 3].AllowCoupling); Assert.IsTrue(synctab.ConflictMatrix[1, 3].HasGelijkstart); Assert.IsTrue(synctab.ConflictMatrix[3, 1].HasGelijkstart); Assert.IsFalse(synctab.ConflictMatrix[3, 1].HasNoCoupling); Assert.IsFalse(synctab.ConflictMatrix[1, 3].HasNoCoupling); controllervm.HasChanged = false; mainwinvm.CloseFileCommand.Execute(null); }