Exemplo n.º 1
0
        public void TestAddItem()
        {
            // Arrange
            ComponentCtrl cCtrl = new ComponentCtrl();
            EventCtrl     eCtrl = new EventCtrl();
            UserCtrl      uCtrl = new UserCtrl();
            var           u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");

            // Act
            var evnt     = eCtrl.CreateEvent("E Title", "E Desc", 42, 42, 42, "E Location", DateTime.Now.AddDays(5), true, u);
            var category = cCtrl.CreateCategory("Cat Name", "Cat desc", null);

            eCtrl.AddCategory(evnt, category);
            var category2 = cCtrl.CreateCategory("Cat2 Name2", "Cat2 desc2", category);

            eCtrl.AddCategory(evnt, category2);
            var item = cCtrl.CreateItem("Item Name", "Item Desc", 42, category2, evnt);

            eCtrl.AddItem(evnt, category2, item);

            // Assert
            var foundCategory = cCtrl.FindCategoryById(category2.Id);
            var foundItem     = ((Item)((Category)evnt.Components[1]).Components[0]);

            Assert.IsNotNull(foundItem);
            Assert.IsTrue(foundCategory.Components.Count == 1);
            Assert.IsTrue(foundCategory.Components[0].Id == foundItem.Id);
        }
Exemplo n.º 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int id = this.GetIdInDvg();

            if (id > 0)
            {
                if (MessageBox.Show("Esta operação é irreversível. Deseja continuar?", "Confirmação de exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        string message = ComponentCtrl.Delete(id);
                        UpdateDgvComponents();
                    }
                    catch (AggregateException ex)
                    {
                        MessageBox.Show("Aplicação servidora não responde: " + ex.Message);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Problema na solicitação: " + ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("Nenhum item selecionado!");
            }
        }
Exemplo n.º 3
0
        public void TestCreateCategory()
        {
            // Arrange
            ComponentCtrl cCtrl       = new ComponentCtrl();
            string        title       = "Category name";
            string        description = "Category description";

            // Act
            var cat = cCtrl.CreateCategory(title, description, null);

            // Assert
            var foundCategory = cCtrl.FindCategoryById(cat.Id);

            Assert.IsTrue(foundCategory.Title == title);
            Assert.IsTrue(foundCategory.Description == description);
        }
Exemplo n.º 4
0
        public void UpdateDgvComponents()
        {
            dgvComponents.AutoGenerateColumns = false;

            try
            {
                dgvComponents.DataSource = ComponentCtrl.GetAll();
            }
            catch (AggregateException ex)
            {
                MessageBox.Show("Aplicação servidora não responde: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problema na solicitação: " + ex.Message);
            }
        }
Exemplo n.º 5
0
        public void SystemTestAddCategoryToCategory()
        {
            EventCtrl     eCtrl   = new EventCtrl();
            ComponentCtrl cCtrl   = new ComponentCtrl();
            UserCtrl      uCtrl   = new UserCtrl();
            IService      service = new Service();

            User  u = uCtrl.CreateUser("System Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");
            Event e = service.CreateEvent("System Test Event", "Test", 2, 20, 100, "Right here", DateTime.Now.AddHours(5), true, u);

            service.AddCategoryToEvent(e.Id, "System Test Cat 1", "Cat 1", null);
            e = service.FindEventById(e.Id);

            service.AddCategoryToEvent(e.Id, "System Test Cat 2", "Cat 2",
                                       e.Components.Where(c => c.Title == "System Test Cat 1" && c is Category).FirstOrDefault());

            Assert.IsTrue(true);
        }
Exemplo n.º 6
0
        public FormProductForm(FormProduct formProduct, int Id = 0)
        {
            InitializeComponent();

            this.formProduct = formProduct;

            this.tbId.Enabled = false;

            productComponents = null;

            try
            {
                if (Id > 0)
                {
                    DTO.Product product = ProductCtrl.GetById(Id);

                    this.tbId.Text     = Id.ToString();
                    tbName.Text        = product.Name;
                    tbDescription.Text = product.Description;
                    tbAmount.Text      = product.Amount.ToString();
                    tbPrice.Text       = product.Price.ToString("0.00");
                    this.tbId.ReadOnly = true;

                    productComponents = (from component in product.Components select component.Id).ToList();
                }

                componentsList = ComponentCtrl.GetAll();
                foreach (var component in componentsList)
                {
                    clbComponents.Items.Add(component.Name, productComponents != null && productComponents.Contains(component.Id));
                }

                this.tbName.Select();
            }
            catch (AggregateException ex)
            {
                MessageBox.Show("Aplicação servidora não responde: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problema na solicitação: " + ex.Message);
            }
        }
Exemplo n.º 7
0
        public void TestAddCategoryToCategory()
        {
            // Arrange
            EventCtrl     eCtrl = new EventCtrl();
            ComponentCtrl cCtrl = new ComponentCtrl();
            UserCtrl      uCtrl = new UserCtrl();
            var           u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");
            var           e     = eCtrl.CreateEvent("Testing Event", "Test", 2, 20, 100, "Right here", DateTime.Now.AddHours(5), true, u);
            var           c1    = cCtrl.CreateCategory("Testing Category Lvl 1", "Test", null);

            // Act
            eCtrl.AddCategory(e, c1);

            var c2 = cCtrl.CreateCategory("Testing Category Lvl 2", "Test", c1);
            var e2 = eCtrl.FindById(e.Id);

            eCtrl.AddCategory(e2, c2);

            Assert.IsTrue(c2.Parent.Id == c1.Id);
            Assert.IsTrue(c2.EventId == e.Id);
        }
Exemplo n.º 8
0
        public void TestAddComponent()
        {
            // Arrange
            EventCtrl eCtrl = new EventCtrl();
            UserCtrl  uCtrl = new UserCtrl();
            var       u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");

            var e = eCtrl.CreateEvent("Event", "Evently event",
                                      2, 20, 100, "Right here", DateTime.Now, true, u);
            Category c = new ComponentCtrl().CreateCategory("Cat", "CateCat", null);

            //Act
            eCtrl.AddCategory(e, c);

            //Assert
            var foundEvent = eCtrl.FindById(e.Id);

            Assert.IsTrue(foundEvent.Components.Count == 1);
            var foundComponent = foundEvent.Components.First();

            Assert.IsTrue(c.Id == foundComponent.Id);
            Assert.IsTrue(foundComponent is Category); // it returns true if an instance is in the inheritance tree
        }