Esempio n. 1
0
        public async Task CancelAppointmentAsync_WithValidId_ShouldDeleteAppointment()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var repository       = new DbRepository <Appointment>(dbContext);
            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new AppointmentService(repository, ratingRepository);

            var appointment = new Appointment
            {
                Id        = 41,
                ClinicId  = 1,
                DentistID = "1",
            };

            dbContext.Appointments.Add(appointment);
            dbContext.SaveChanges();

            await service.CancelAppointmentAsync(41);

            var result = dbContext.Appointments
                         .CountAsync()
                         .GetAwaiter()
                         .GetResult();

            Assert.Equal(0, result);
        }
Esempio n. 2
0
        public void GetRatingForAppointment_WithNonExistingRatingRecord_ShouldThrowException()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var rating1 = new Rating
            {
                Id              = 1,
                AppointmentId   = 1,
                RatingByDentist = 6
            };

            var rating2 = new Rating
            {
                Id              = 2,
                AppointmentId   = 2,
                RatingByDentist = 10
            };

            dbContext.Ratings.Add(rating1);
            dbContext.Ratings.Add(rating2);
            dbContext.SaveChanges();

            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new RatingService(ratingRepository);

            Assert.Throws <InvalidOperationException>(() => service.GetRatingForAppointment(3));
        }
Esempio n. 3
0
        public void GetClinicById_WithValidId_ShouldReturnClinic()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);
            var clinic    = new Clinic
            {
                Id   = 10,
                Name = "Clinic 10"
            };
            var clinic2 = new Clinic
            {
                Id   = 11,
                Name = "clinic 11"
            };

            dbContext.Clinics.Add(clinic);
            dbContext.Clinics.Add(clinic2);
            dbContext.SaveChanges();

            var repository = new DbRepository <Clinic>(dbContext);
            var service    = new ClinicService(repository);
            var result     = service.GetClinicById(11);

            Assert.Same(clinic2, result);
        }
Esempio n. 4
0
        public void GetAllRatingsForPatientByDentist_WithInvalidRatings_ShouldReturnEmptyRatingsCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var rating = new Rating
            {
                Id              = 1,
                DentistId       = "1",
                PatientId       = "2",
                RatingByDentist = 10
            };

            var rating2 = new Rating
            {
                Id              = 2,
                DentistId       = "1",
                PatientId       = "1",
                RatingByDentist = 0
            };

            dbContext.Ratings.Add(rating);
            dbContext.Ratings.Add(rating2);
            dbContext.SaveChanges();

            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new RatingService(ratingRepository);
            var result           = service.GetAllRatingsForDentistByPatient("1", "1");

            Assert.Empty(result);
        }
Esempio n. 5
0
        public void GetAllPatientDentists_WithValidIdAndNoDentists_ShouldReturnEmptyDentistCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext   = new DentHubContext(options);
            var appointment = new Appointment
            {
                PatientId = "1",
                DentistID = "1"
            };
            var appointment2 = new Appointment
            {
                PatientId = "1",
                DentistID = "2",
            };
            var appointment3 = new Appointment
            {
                PatientId = "1",
                DentistID = "2",
            };
            var dentist1 = new DentHubUser
            {
                Id          = "1",
                SpecialtyId = 1,
                Email       = "*****@*****.**",
                FirstName   = "Test",
                LastName    = "LastName",
                IsActive    = true,
                PhoneNumber = "1234",
                UserName    = "******",
            };
            var dentist2 = new DentHubUser
            {
                Id          = "2",
                SpecialtyId = 2,
                Email       = "*****@*****.**",
                FirstName   = "Test2",
                LastName    = "LastName2",
                IsActive    = true,
                PhoneNumber = "123456",
                UserName    = "******",
            };

            dbContext.Appointments.Add(appointment);
            dbContext.Appointments.Add(appointment2);
            dbContext.Appointments.Add(appointment3);
            dbContext.DentHubUsers.Add(dentist1);
            dbContext.DentHubUsers.Add(dentist2);
            dbContext.SaveChanges();

            var userRepository        = new DbRepository <DentHubUser>(dbContext);
            var appointmentRepository = new DbRepository <Appointment>(dbContext);
            var ratingRepository      = new DbRepository <Rating>(dbContext);
            var appointmentService    = new AppointmentService(appointmentRepository, ratingRepository);
            var service = new DentistService(userRepository, appointmentService);
            var result  = service.GetAllPatientDentists("5");

            Assert.Empty(result);
        }
Esempio n. 6
0
        public void GetRatingForAppointment_WithInValidAppointmentAndRating_ShouldReturnRating()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var rating1 = new Rating
            {
                Id              = 1,
                AppointmentId   = 1,
                RatingByDentist = 6
            };

            var rating2 = new Rating
            {
                Id              = 2,
                AppointmentId   = 2,
                RatingByDentist = 10
            };

            dbContext.Ratings.Add(rating1);
            dbContext.Ratings.Add(rating2);
            dbContext.SaveChanges();

            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new RatingService(ratingRepository);
            var result           = service.GetRatingForAppointment(1);

            Assert.Equal(rating1, result);
        }
Esempio n. 7
0
        public void GetAllActiveDentists_WithValidDentists_ShouldReturnDentistsCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var dentist = new DentHubUser
            {
                Id          = "1",
                IsActive    = true,
                FirstName   = "Dentist 1",
                LastName    = "Test",
                SpecialtyId = 1,
            };

            var dentist2 = new DentHubUser
            {
                Id          = "2",
                IsActive    = true,
                FirstName   = "Dentist 2",
                LastName    = "Test2",
                SpecialtyId = 2,
            };

            var dentist3 = new DentHubUser
            {
                Id          = "3",
                IsActive    = false,
                FirstName   = "Dentist 3",
                LastName    = "Test3",
                SpecialtyId = 3,
            };

            var dentist4 = new DentHubUser
            {
                Id          = "4",
                IsActive    = true,
                FirstName   = "Dentist 4",
                LastName    = "Test4",
                SpecialtyId = 44,
            };

            dbContext.DentHubUsers.Add(dentist);
            dbContext.DentHubUsers.Add(dentist2);
            dbContext.DentHubUsers.Add(dentist3);
            dbContext.DentHubUsers.Add(dentist4);
            dbContext.SaveChanges();

            var userRepository        = new DbRepository <DentHubUser>(dbContext);
            var appointmentRepository = new DbRepository <Appointment>(dbContext);
            var ratingRepository      = new DbRepository <Rating>(dbContext);
            var appointmentService    = new AppointmentService(appointmentRepository, ratingRepository);
            var service = new DentistService(userRepository, appointmentService);
            var result  = service.GetAllActiveDentists();

            Assert.Equal(new DentHubUser[] { dentist, dentist2, dentist4 }, result);
        }
Esempio n. 8
0
        public void GetPatientFiles_WithInvalidFiles_ShouldReturnEmptyPatientFileCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var patient = new DentHubUser
            {
                Id        = "1",
                IsActive  = true,
                FirstName = "Patient 1",
                LastName  = "Test",
            };

            var patient2 = new DentHubUser
            {
                Id        = "2",
                IsActive  = true,
                FirstName = "Patient 2",
                LastName  = "Test2"
            };

            var file1 = new PatientFile
            {
                Id        = 1,
                PatientId = "1"
            };

            var file2 = new PatientFile
            {
                Id        = 2,
                PatientId = "1"
            };

            var file3 = new PatientFile
            {
                Id        = 3,
                PatientId = "2"
            };

            dbContext.DentHubUsers.Add(patient);
            dbContext.DentHubUsers.Add(patient2);
            dbContext.PatientFiles.Add(file1);
            dbContext.PatientFiles.Add(file2);
            dbContext.PatientFiles.Add(file3);
            dbContext.SaveChanges();

            var patuientFilesRepository = new DbRepository <PatientFile>(dbContext);
            var service = new PatientFileService(patuientFilesRepository);
            var result  = service.GetPatientFiles("3");

            Assert.Empty(result);
        }
Esempio n. 9
0
 private static void SeedSpecialties(DentHubContext dbContext, string[][] specialties)
 {
     foreach (var specialty in specialties)
     {
         var newSpecialty = new Specialty
         {
             Name        = specialty[0],
             Description = specialty[1]
         };
         dbContext.Specialties.Add(newSpecialty);
         dbContext.SaveChanges();
     }
 }
Esempio n. 10
0
        public void GetAverageDentistRating_WithValidDentistIdAndNoRatings_ShouldReturnNotRated()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var rating1 = new Rating
            {
                Id              = 1,
                PatientId       = "1",
                DentistId       = "2",
                RatingByPatient = 6
            };

            var rating2 = new Rating
            {
                Id              = 2,
                PatientId       = "1",
                DentistId       = "3",
                RatingByPatient = 10
            };
            var rating3 = new Rating
            {
                Id              = 3,
                PatientId       = "1",
                DentistId       = "4",
                RatingByPatient = 8
            };
            var rating4 = new Rating
            {
                Id              = 4,
                PatientId       = "1",
                DentistId       = "5",
                RatingByPatient = 6
            };

            dbContext.Ratings.Add(rating1);
            dbContext.Ratings.Add(rating2);
            dbContext.Ratings.Add(rating3);
            dbContext.Ratings.Add(rating4);
            dbContext.SaveChanges();

            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new RatingService(ratingRepository);
            var result           = service.GetAverageDentistRating("1");

            Assert.Equal("Not Rated", result);
        }
Esempio n. 11
0
        public void GetAppointmentPatient_WithValidAppointmentIdAndPatient_ShouldReturnPatient()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext   = new DentHubContext(options);
            var appointment = new Appointment
            {
                Id        = 1,
                PatientId = "1",
                DentistID = "1"
            };

            var patient1 = new DentHubUser
            {
                Id          = "1",
                Email       = "*****@*****.**",
                FirstName   = "Test",
                LastName    = "LastName",
                IsActive    = true,
                PhoneNumber = "1234",
                UserName    = "******",
            };
            var patient2 = new DentHubUser
            {
                Id          = "2",
                Email       = "*****@*****.**",
                FirstName   = "Test2",
                LastName    = "LastName2",
                IsActive    = true,
                PhoneNumber = "123456",
                UserName    = "******",
            };

            dbContext.Appointments.Add(appointment);
            dbContext.DentHubUsers.Add(patient1);
            dbContext.DentHubUsers.Add(patient2);
            dbContext.SaveChanges();

            var userRepository        = new DbRepository <DentHubUser>(dbContext);
            var appointmentRepository = new DbRepository <Appointment>(dbContext);
            var ratingRepository      = new DbRepository <Rating>(dbContext);
            var appointmentService    = new AppointmentService(appointmentRepository, ratingRepository);
            var service = new PatientService(userRepository, appointmentService);
            var result  = service.GetAppointmentPatient(1);

            Assert.Equal(patient1, result);
        }
Esempio n. 12
0
        public void GetAllActive_WithInvalidClinics_ShouldReturnEmptyClinicsCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var clinic = new Clinic
            {
                Id       = 10,
                IsActive = true,
                Name     = "Clinic 1",
            };
            var dentist = new DentHubUser
            {
                Id       = "1",
                IsActive = false,
                ClinicId = 1
            };

            var clinic2 = new Clinic
            {
                Id       = 2,
                IsActive = false,
                Name     = "Clinic 2",
            };
            var dentist2 = new DentHubUser
            {
                Id       = "2",
                IsActive = true,
                ClinicId = 2
            };

            dbContext.Clinics.Add(clinic);
            dbContext.Clinics.Add(clinic2);
            dbContext.DentHubUsers.Add(dentist);
            dbContext.DentHubUsers.Add(dentist2);
            dbContext.SaveChanges();

            var repository = new DbRepository <Clinic>(dbContext);
            var service    = new ClinicService(repository);
            var result     = service.GetAllActive();

            Assert.Empty(result);
        }
Esempio n. 13
0
 private static void SeedClinics(DentHubContext dbContext, string[][] clinics)
 {
     foreach (var clinic in clinics)
     {
         var newClinic = new Clinic
         {
             //Id = int.Parse(clinic[0]),
             Name         = clinic[1],
             Street       = clinic[2],
             City         = clinic[3],
             Country      = clinic[4],
             PostalCode   = clinic[5],
             WorkingHours = clinic[6]
         };
         dbContext.Clinics.Add(newClinic);
         dbContext.SaveChanges();
     }
     ;
 }
Esempio n. 14
0
        public async Task CreateFileAsync_WithValidPrerequisites_ShouldCreateFile()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var patientFile = new PatientFile
            {
                CreatedById = "1",
                DateCreated = new DateTime(2019, 1, 1, 10, 30, 0),
                Description = "description",
                FileType    = FileType.Assesment,
                Name        = "Name",
                PatientId   = "1",
                FileUrl     = "examplefile.com/pic/1564",
            };

            var createdById = "1";
            var dateCreated = new DateTime(2019, 1, 1, 10, 30, 0);
            var description = "description";
            var fileType    = FileType.Assesment;
            var name        = "Name";
            var patientId   = "1";
            var fileUrl     = "examplefile.com/pic/1564";

            dbContext.PatientFiles.Add(patientFile);
            dbContext.SaveChanges();

            var patientFileRepository = new DbRepository <PatientFile>(dbContext);
            var service = new PatientFileService(patientFileRepository);
            await service.CreateFileAsync(name,
                                          fileType, patientId, fileUrl,
                                          description, createdById, dateCreated);

            var result = dbContext.PatientFiles
                         .FirstOrDefaultAsync(f => f.FileUrl == fileUrl)
                         .GetAwaiter()
                         .GetResult();

            Assert.Equal(patientFile, result);
        }
Esempio n. 15
0
        public void DuplicateOfferingExists_WithNoDuplicates_ShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var repository       = new DbRepository <Appointment>(dbContext);
            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new AppointmentService(repository, ratingRepository);

            var user = new DentHubUser()
            {
                Id        = "2",
                FirstName = "Test2",
                LastName  = "Dentist",
            };

            var appointment = new Appointment
            {
                Id        = 31,
                ClinicId  = 1,
                DentistID = "2",
                TimeStart = new DateTime(2019, 05, 05, 10, 0, 0),
                TimeEnd   = new DateTime(2019, 05, 05, 10, 30, 0),
                Status    = Status.Offering,
            };

            dbContext.Appointments.Add(appointment);
            dbContext.DentHubUsers.Add(user);
            dbContext.SaveChanges();

            var timeStart = new DateTime(2019, 05, 05, 10, 30, 0);
            var timeEnd   = new DateTime(2019, 05, 05, 11, 00, 0);

            var result = service.DuplicateOfferingExists
                             (user, timeStart, timeEnd);

            Assert.False(result);
        }
Esempio n. 16
0
        public void GetAllActiveDentists_WithInvalidDentists_ShouldReturnEmptyDentistsCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var patient = new DentHubUser
            {
                Id        = "1",
                IsActive  = false,
                FirstName = "Patient 1",
                LastName  = "Test",
                SSN       = "123"
            };

            var patient2 = new DentHubUser
            {
                Id        = "2",
                IsActive  = true,
                FirstName = "Dentist 2",
                LastName  = "Test2",
                SSN       = null,
            };

            dbContext.DentHubUsers.Add(patient);
            dbContext.DentHubUsers.Add(patient2);
            dbContext.SaveChanges();

            var userRepository        = new DbRepository <DentHubUser>(dbContext);
            var appointmentRepository = new DbRepository <Appointment>(dbContext);
            var ratingRepository      = new DbRepository <Rating>(dbContext);
            var appointmentService    = new AppointmentService(appointmentRepository, ratingRepository);
            var service = new PatientService(userRepository, appointmentService);
            var result  = service.GetAllActivePatients();

            Assert.Empty(result);
        }
Esempio n. 17
0
        public async Task GetFileUrl_WithInvalidFileId_ShouldShouldThrowException()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var patientFile = new PatientFile
            {
                CreatedById = "1",
                DateCreated = new DateTime(2019, 1, 1, 10, 30, 0),
                Description = "description",
                FileType    = FileType.Assesment,
                Name        = "Name",
                PatientId   = "1",
                FileUrl     = "examplefile.com/pic/1564",
            };

            var createdById = "1";
            var dateCreated = new DateTime(2019, 1, 1, 10, 30, 0);
            var description = "description";
            var fileType    = FileType.Assesment;
            var name        = "Name";
            var patientId   = "1";
            var fileUrl     = "examplefile.com/pic/1564";

            dbContext.PatientFiles.Add(patientFile);
            dbContext.SaveChanges();

            var patientFileRepository = new DbRepository <PatientFile>(dbContext);
            var service = new PatientFileService(patientFileRepository);
            await service.CreateFileAsync(name,
                                          fileType, patientId, fileUrl,
                                          description, createdById, dateCreated);

            Assert.Throws <ArgumentException>(() => service.GetFileUrl(2));
        }
Esempio n. 18
0
        public void GetAllDentistPatients_WithInvalidPatients_ShouldReturnEmptyPatientsCollection()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            var patient = new DentHubUser
            {
                Id        = "10",
                IsActive  = true,
                FirstName = "Patient 1",
                LastName  = "Test",
            };

            var patient2 = new DentHubUser
            {
                Id        = "11",
                IsActive  = false,
                FirstName = "Patient 2",
                LastName  = "Test",
            };

            var dentist = new DentHubUser
            {
                Id          = "13",
                ClinicId    = 14,
                IsActive    = false,
                FirstName   = "Dentist",
                LastName    = "Test",
                SpecialtyId = 3,
            };
            var appointment1 = new Appointment
            {
                Id        = 1,
                PatientId = "11",
                DentistID = "14",
            };
            var appointment2 = new Appointment
            {
                Id        = 2,
                PatientId = "12",
                DentistID = "15",
            };
            var appointment3 = new Appointment
            {
                Id        = 3,
                PatientId = "11",
                DentistID = "16",
            };

            dbContext.DentHubUsers.Add(dentist);
            dbContext.DentHubUsers.Add(patient);
            dbContext.DentHubUsers.Add(patient2);
            dbContext.Appointments.Add(appointment1);
            dbContext.Appointments.Add(appointment2);
            dbContext.Appointments.Add(appointment3);
            dbContext.SaveChanges();

            var userRepository        = new DbRepository <DentHubUser>(dbContext);
            var appointmentRepository = new DbRepository <Appointment>(dbContext);
            var ratingRepository      = new DbRepository <Rating>(dbContext);
            var appointmentService    = new AppointmentService(appointmentRepository, ratingRepository);
            var service = new PatientService(userRepository, appointmentService);
            var result  = service.GetAllDentistPatients("13");

            Assert.Empty(result);
        }