Example #1
0
        public async void ReturnCreateView()
        {
            var result = await sut.Create();

            var vr = Assert.IsType <ViewResult>(result);

            Assert.Equal("Create", vr.ViewName);
        }
Example #2
0
        public void CanAppointmentControllerCreate_AppointIsAdded()
        {
            //arrange
            var mockServRepo = new Mock <IServiceProviderRepository>();
            var mockAppRepo  = new Mock <IAppointmentRepository>();
            var mockCustRepo = new Mock <ICustomerRepository>();
            var controller   = new AppointmentController(mockAppRepo.Object,
                                                         mockCustRepo.Object, mockServRepo.Object);
            var testApp = new Appointment()
            {
                AppTime     = DateTime.Now,
                Id          = 0,
                Description = "This is a test appointment",
                CustomerId  = 1,
                ProviderId  = 1
            };

            //mocking setting up to a mock database
            mockAppRepo.Setup(x => x.isAppointmentAvailable(testApp)).Returns(true);
            mockCustRepo.Setup(x => x.ThisCustomerExists(testApp.CustomerId)).Returns(true);
            mockServRepo.Setup(x => x.ThisProviderExists(testApp.ProviderId)).Returns(true);
            //act
            var result = controller.Create(testApp);

            //assert
            if (testApp != null)
            {
                Assert.IsType <ViewResult>(result);
            }
        }
        public void GetCreateShouldReturnView()
        {
            //Arrange
            var controller = new AppointmentController(null, null);
            var name       = "Gosho";
            // Act
            var result = controller.Create(name);

            // Assert
            result.Should().BeOfType <ViewResult>();
        }
        public void CanAppointmentControllerCreate()
        {
            //arrange
            var controller = new AppointmentController();
            var testApp    = new Appointment();

            //act
            var result = controller.Create(testApp);

            //assert
            Assert.NotNull(testApp);
            Assert.IsType <RedirectToActionResult>(result);
        }
Example #5
0
        public void AppointmentCreate_TakesAnAppointmentModel_ReturnsARedirectToActionResult()
        {
            //assemble
            var testAppointmentController = new AppointmentController();

            //act
            var result = testAppointmentController.Create(new AppointmentModel {
                Id = 5, AppointmentTime = new DateTime(2018, 8, 8, 10, 0, 0), Client = new CustomerModel(), Provider = new ServiceProviderModel(), Service = "Fake"
            });

            //assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
Example #6
0
        public async Task Appointment_ShouldCreateNewAppointmentAsync()
        {
            // Assemble
            var context = new ApplicationContext(DbAssembly().Options);
            var appointmentController = new AppointmentController(context, new AppointmentBookingService());
            var appointment           = new Appointment()
            {
                Customer        = new Customer(),
                ServiceProvider = new ServiceProvider(),
                Day             = 0,
                Time            = 0
            };

            // Act
            await appointmentController.Create(appointment);

            // Assert
            Assert.NotEmpty(context.Appointments);
        }
        /// <summary>
        /// Occurs when the value of a cell changes. Adds a new Appointment if there wasn't no value. Edit an existing Appointment if the value changed. Deletes an existing Appointment if the value is empty.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DataGridViewCellEventArgs"/> instance containing the event data.</param>
        private void dgvAppointments_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > -1 && e.RowIndex > -1)
            {
                int                    result = 0;
                Appointment            query  = null;
                uint?                  id     = null;
                List <DataGridViewRow> rows   = (from row in dgvAppointments.Rows.Cast <DataGridViewRow>()
                                                 select row).ToList();

                switch (e.ColumnIndex)
                {
                case 0:
                    if (selectedUser.Id == currentUser.Id)
                    {
                        if (string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value)) != true && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex + 1, e.RowIndex].Value)) == true)
                        {
                            if (Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value).Length > 64)
                            {
                                MessageBox.Show("De naam van de afspraak is te lang.");
                            }
                            else
                            {
                                result = appointmentController.Create(new Appointment()
                                {
                                    UserId = currentUser.Id,
                                    Name   = Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value),
                                });
                            }
                        }
                        else
                        {
                            query = (from appointment in appointments
                                     where appointment.Id == Convert.ToUInt32(dgvAppointments[dgvAppointments.ColumnCount - 1, e.RowIndex].Value)
                                     select appointment).FirstOrDefault();

                            query.Name = Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value);

                            if (query.Name.Length > 64)
                            {
                                MessageBox.Show("De naam van de afspraak is te lang.");
                            }
                            else
                            {
                                if (query != null)
                                {
                                    result = appointmentController.Edit(query);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Kan afspraken voor andere gebruikers niet toevoegen/wijzigen.");
                    }
                    break;

                case 1:
                    if (string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex, e.RowIndex].Value)) != true && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex - 1, e.RowIndex].Value)) == true)
                    {
                        result = appointmentController.Create(new Appointment()
                        {
                            UserId = currentUser.Id,
                            Date   = Convert.ToDateTime(dgvAppointments[e.ColumnIndex, e.RowIndex].Value)
                        });
                    }
                    else
                    {
                        query = (from appointment in appointments
                                 where appointment.Id == Convert.ToUInt32(dgvAppointments[dgvAppointments.ColumnCount - 1, e.RowIndex].Value)
                                 select appointment).FirstOrDefault();

                        query.Date = Convert.ToDateTime(dgvAppointments[e.ColumnIndex, e.RowIndex].Value);

                        if (query != null)
                        {
                            result = appointmentController.Edit(query);
                        }
                    }
                    break;

                case 2:
                    if (selectedUser.Id == currentUser.Id)
                    {
                        if (e.RowIndex < dgvAppointments.RowCount - 1 && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex - 1, e.RowIndex].Value)) == false && string.IsNullOrEmpty(Convert.ToString(dgvAppointments[e.ColumnIndex - 2, e.RowIndex].Value)) == false)
                        {
                            id = (from row in rows
                                  where Convert.ToBoolean(row.Cells["verwijderen?"].Value) == true
                                  select Convert.ToUInt32(row.Cells[dgvAppointments.ColumnCount - 1].Value)).FirstOrDefault();

                            query = (from appointment in appointments
                                     where appointment.Id == id
                                     select appointment).FirstOrDefault();

                            if (query != null)
                            {
                                result = appointmentController.Delete(query);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Kan afspraken voor andere gebruikers niet verwijderen.");
                    }
                    break;

                default:
                    break;
                }

                LoadToGrid(typeof(Appointment));
            }
        }