public void InitListViewTestNull()
 {
     Assert.ThrowsException <ArgumentNullException>(() =>
     {
         var testClass = new PropertyListView();
         testClass.InitListView(null);
     });
 }
        private static PropertyListView InitListView()
        {
            var testClass     = new PropertyListView();
            var listviewItems = new TestListViewClassCollection();

            testClass.InitListView(listviewItems);
            return(testClass);
        }
        public void PropertyListViewTestWithoutPropertyGrid()
        {
            // Arrange

            // Act
            var testClass = new PropertyListView();

            // Assert
            Assert.IsNull(testClass.PropertyGrid);
        }
        public void AddItemTestWithoutInit()
        {
            // Arrange
            var testClass = new PropertyListView();

            // Act
            testClass.AddItem();

            // Assert
            Assert.IsNull(testClass.DataSource);
        }
        public void PropertyListViewTestNull()
        {
            // Arrange

            // Act
            var testClass = new PropertyListView()
            {
                PropertyGrid = null,
            };

            // Assert
            Assert.IsNull(testClass.PropertyGrid);
        }
        public void InitListViewTest()
        {
            // Arrange
            Type expectedItemType = typeof(TestListViewClass);
            var  propertyGrid     = new PropertyGrid();

            // Act
            var testClass = new PropertyListView {
                PropertyGrid = propertyGrid
            };
            var listviewItems = new TestListViewClassCollection();

            testClass.InitListView(listviewItems);

            // Assert
            Assert.AreEqual(listviewItems, testClass.DataSource);
            Assert.AreEqual(expectedItemType, testClass.ItemType);
            Assert.IsNull(testClass.PropertyGrid.SelectedObject);
            // Columns
            Assert.AreEqual("IntData", testClass.ListView.Columns[0].Text);
            Assert.AreEqual("StringData", testClass.ListView.Columns[1].Text);
            Assert.AreEqual("PointData", testClass.ListView.Columns[2].Text);
            Assert.AreEqual("EnumData", testClass.ListView.Columns[3].Text);
            // testlistview1
            Assert.AreEqual("100", testClass.ListView.Items[0].Text);
            Assert.AreEqual("testString100", testClass.ListView.Items[0].SubItems[1].Text);
            Assert.AreEqual("{X=1,Y=1}", testClass.ListView.Items[0].SubItems[2].Text);
            Assert.AreEqual("Enum1", testClass.ListView.Items[0].SubItems[3].Text);
            // testlistview2
            Assert.AreEqual("200", testClass.ListView.Items[1].Text);
            Assert.AreEqual("testString200", testClass.ListView.Items[1].SubItems[1].Text);
            Assert.AreEqual("{X=2,Y=2}", testClass.ListView.Items[1].SubItems[2].Text);
            Assert.AreEqual("Enum2", testClass.ListView.Items[1].SubItems[3].Text);
            // testlistview3
            Assert.AreEqual("300", testClass.ListView.Items[2].Text);
            Assert.AreEqual("testString300", testClass.ListView.Items[2].SubItems[1].Text);
            Assert.AreEqual("{X=3,Y=3}", testClass.ListView.Items[2].SubItems[2].Text);
            Assert.AreEqual("Enum3", testClass.ListView.Items[2].SubItems[3].Text);
        }
Exemple #7
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            switch (comboTypes.SelectedIndex)
            {
            case 0:     // Persons
                Person p = this.Program.Find(new Person(textSearch.Text));
                if (p == null)
                {
                    goto Error;
                }
                PersonView pv = new PersonView(p, this);
                pv.onDispose += (person) => {
                    p = person;
                };
                pv.ShowDialog();
                goto Finish;

            case 1:     // Cadastral Area
                CadastralArea c = null;
                if (Int32.TryParse(textSearch.Text, out int search))
                {
                    c = new CadastralArea(search);
                    c = this.Program.Find(new CadastralAreaByID(new CadastralArea(search)));
                }
                else
                {
                    c = new CadastralArea(0, textSearch.Text);
                    c = this.Program.Find(new CadastralAreaByName(c));
                }
                if (c == null)
                {
                    goto Error;
                }
                CadastralView cv = new CadastralView(c);
                cv.onDispose += (cArea, oldName) =>
                {
                    if (oldName != c.Name)
                    {
                        this.Program.UpdateCadastralArea(c, oldName);
                    }
                };
                cv.ShowDialog();
                goto Finish;

            case 2:     // Property list
                InputDialog id = new InputDialog("Catastral area:");
                id.onDispose += (caId) =>
                {
                    if (caId != "")
                    {
                        CadastralArea ca = null;
                        if (Int32.TryParse(caId, out int s))
                        {
                            ca = this.Program.Find(new CadastralAreaByID(new CadastralArea(s, "")));
                        }
                        else
                        {
                            ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, caId)));
                        }
                        if (ca != null)
                        {
                            PropertyList pl = ca.FindPropertyList(textSearch.Text);
                            if (pl == null)
                            {
                                MessageBox.Show("Property list with this id does not exist");
                            }
                            else
                            {
                                PropertyListView plv = new PropertyListView(pl, this);
                                plv.ShowDialog();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this id/name does not exist");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have to write something");
                    }
                };
                id.ShowDialog();
                goto Finish;

            case 3:     // Property
                InputDialog id2 = new InputDialog("Catastral area:");
                id2.onDispose += (caId) =>
                {
                    if (caId != "")
                    {
                        CadastralArea ca = null;
                        if (Int32.TryParse(caId, out int s))
                        {
                            ca = this.Program.Find(new CadastralAreaByID(new CadastralArea(s, "")));
                        }
                        else
                        {
                            ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, caId)));
                        }
                        if (ca != null)
                        {
                            Property prop = ca.FindProperty(textSearch.Text);
                            if (prop == null)
                            {
                                MessageBox.Show("Property with this id does not exist");
                            }
                            else
                            {
                                PropertyView propv = new PropertyView(prop);
                                propv.ShowDialog();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this id/name does not exist");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have to write something");
                    }
                };
                id2.ShowDialog();
                goto Finish;
            }

Error:
            MessageBox.Show("Could not find specified item");
            Finish :;
        }
Exemple #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            switch (comboTypes.SelectedIndex)
            {
            case 0 :    // Persons
                PersonView pv = new PersonView(null, this);
                pv.onDispose += (person) =>
                {
                    if (this.Program.AddPerson(person))
                    {
                        MessageBox.Show("Person was successfully added!");
                        this.InitPersons();
                    }
                    else
                    {
                        MessageBox.Show("Person could not be added, probably already added!");
                    }
                };
                pv.ShowDialog();
                break;

            case 1:     // Cadastral Area
                CadastralView cv = new CadastralView();
                cv.onDispose += (cArea, name) =>
                {
                    if (this.Program.AddCadastralArea(cArea))
                    {
                        MessageBox.Show("Cadastral area was successfully added!");
                        this.InitCadastralAreas();
                    }
                    else
                    {
                        MessageBox.Show("Cadastral area could not be added, probably already added!");
                    }
                };
                cv.ShowDialog();
                break;

            case 2:     // Property list
                InputDialog id = new InputDialog("Catastral area name:");
                id.onDispose += (search) =>
                {
                    if (search != "")
                    {
                        CadastralArea ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, (string)search)));
                        if (ca != null)
                        {
                            PropertyListView plv = new PropertyListView(new PropertyList(-1, ca), this);
                            plv.onDispose += (pl) =>
                            {
                                if (pl.ID >= 0)
                                {
                                    if (this.Program.AddPropertyList(pl))
                                    {
                                        MessageBox.Show("Property list was successfully added!");
                                    }
                                    else
                                    {
                                        MessageBox.Show("Cadastral area could not be added, probably already added!");
                                    }
                                }
                            };
                            plv.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this name does not exist");
                        }
                    }
                };
                id.ShowDialog();
                break;

            default:
                MessageBox.Show("This option is not supported");
                break;
            }
        }