Beispiel #1
0
        public void CreateSubject()
        {
            var res = controller.Create();

            Assert.IsInstanceOfType(res, typeof(ViewResult));
            var viewRes = res as ViewResult;

            Assert.IsInstanceOfType(viewRes.Model, typeof(Subject));
            //Assert.IsTrue(viewRes.ViewBag.Create);
        }
Beispiel #2
0
        public void Create_ModelIsValid_ReturnsCreatedAtAction()
        {
            //Arrange
            _subjectService.Setup(s => s.CreateEntityAsync(_subject));

            //Act
            var actionResult = _subjectController.Create(_subject);

            //Assert
            actionResult.Result.Should().BeOfType <CreatedAtActionResult>();
        }
Beispiel #3
0
        public void AddSubject()
        {
            IList <Subject> subjects = GetSubjects();
            Subject         subject  = new Subject()
            {
                Name = "Chemistry"
            };

            SubjectController controller = new SubjectController(subjects);

            ActionResult result = controller.Create(subject);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirect = (RedirectToRouteResult)result;

            Assert.IsTrue(string.IsNullOrEmpty(redirect.RouteName));
            Assert.IsTrue(redirect.RouteValues.ContainsKey("id"));
            Assert.AreEqual(subject.Id, redirect.RouteValues["id"]);
            Assert.IsTrue(redirect.RouteValues.ContainsKey("action"));
            Assert.AreEqual("Details", redirect.RouteValues["action"]);

            Assert.IsTrue(subjects.Any(s => s.Name == "Chemistry"));
            Assert.AreNotEqual(0, subject.Id);
        }
Beispiel #4
0
        /// <summary>
        /// Occurs when the Button control is clicked. Adds a new Subject.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnAddSubject_Click(object sender, EventArgs e)
        {
            //adds a subject to the grades datagrid
            int result = 0;

            if (selectedUser.Id == currentUser.Id)
            {
                if (!string.IsNullOrWhiteSpace(txtSubjectName.Text))
                {
                    if (txtSubjectName.Text.Length > 64)
                    {
                        MessageBox.Show("Naam van het vak is te lang.");
                    }
                    else
                    {
                        result = subjectController.Create(new Subject()
                        {
                            RowIndex = Convert.ToUInt32(dgvGrades.RowCount),
                            UserId   = selectedUser.Id,
                            Name     = txtSubjectName.Text
                        });

                        switch (result)
                        {
                        case 0:
                            MessageBox.Show("Er bestaat al een vak met dezelfde naam.");
                            break;

                        case 1:
                            LoadToGrid(typeof(Grade));
                            lblInsertName.Visible = false;
                            break;

                        case 2:
                            MessageBox.Show("Onbekend probleem bij het verbinden met de database.");
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    lblInsertName.Visible = true;
                }
            }
            else
            {
                MessageBox.Show("Kan vakken voor andere gebruikers niet toevoegen.");
            }

            txtSubjectName.Text = "";
        }
Beispiel #5
0
        /// <summary>
        /// Occurs when the Button control is clicked. Adds a new Subject.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnAddSubject_Click(object sender, EventArgs e)
        {
            //adds a subject to the grades datagrid
            int result = 0;

            if (!string.IsNullOrWhiteSpace(txtSubjectName.Text))
            {
                if (txtSubjectName.Text.Length > 64)
                {
                    MessageBox.Show("Naam van het vak is te lang.");
                }
                else
                {
                    result = subjectController.Create(new Subject()
                    {
                        RowIndex = Convert.ToUInt32(dgvGrades.RowCount),
                        Name     = txtSubjectName.Text
                    });

                    if (result != 2)
                    {
                        LoadToGrid(typeof(Grade));
                        lblInsertName.Visible = false;
                    }
                    else
                    {
                        MessageBox.Show("Er bestaat al een vak met dezelfde naam.");
                    }
                }
            }
            else
            {
                lblInsertName.Visible = true;
            }

            txtSubjectName.Text = "";
        }