示例#1
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);
        }
示例#2
0
        public async Task GetClinicById_WithInvalidId_ShouldReturnException()
        {
            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   = 20,
                Name = "Clinic 20"
            };
            var clinic2 = new Clinic
            {
                Id   = 21,
                Name = "Clinic 21"
            };

            dbContext.Clinics.Add(clinic);
            dbContext.Clinics.Add(clinic2);
            await dbContext.SaveChangesAsync();

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

            Assert.Throws <ArgumentException>(() => service.GetClinicById(22));
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
        public async Task GetAppointmentById_WithInvalidId_ShouldReturnException()
        {
            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        = 7,
                ClinicId  = 1,
                DentistID = "2",
                PatientId = "3",
                Status    = Status.Booked
            };
            var appointment2 = new Appointment
            {
                Id        = 8,
                ClinicId  = 1,
                DentistID = "2",
                PatientId = "3",
                Status    = Status.Booked
            };

            dbContext.Appointments.Add(appointment);
            dbContext.Appointments.Add(appointment2);
            await dbContext.SaveChangesAsync();

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

            Assert.Throws <ArgumentException>(() => service.GetAppointmentById(9));
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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));
        }
示例#9
0
        public async Task CreateAppointment_WithParameters_ShouldCreateAppointment()
        {
            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        = "1",
                ClinicId  = 1,
                FirstName = "Test",
                LastName  = "Dentist",
            };
            var timeStart = new DateTime(2019, 05, 05, 10, 0, 0);
            var timeEnd   = new DateTime(2019, 05, 05, 10, 30, 0);

            Assert.NotNull(service.CreateAppointment(user,
                                                     timeStart, timeEnd));
            var result = await dbContext.Appointments.CountAsync();

            Assert.Equal(1, result);
        }
示例#10
0
        public static void Seed(DentHubContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            var userManager = serviceProvider.GetRequiredService <UserManager <DentHubUser> >();

            Seed(dbContext, roleManager, userManager);

            SeedAdmin(GlobalConstants.AdminUserName, GlobalConstants.AdministratorRoleName, userManager, roleManager);

            SeedSpecialties(dbContext, GlobalConstants.Specialties);

            SeedClinics(dbContext, GlobalConstants.Clinics);

            SeedDentists(dbContext, GlobalConstants.Dentists, userManager, roleManager);

            SeedPatients(dbContext, GlobalConstants.Patients, userManager, roleManager);
        }
示例#11
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);
        }
示例#12
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);
        }
示例#13
0
        public void GetClinicById_WithEmptyClinicSet_ShouldReturnException()
        {
            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 <Clinic>(dbContext);
            var service    = new ClinicService(repository);

            Assert.Throws <ArgumentException>(() => service.GetClinicById(7));
        }
示例#14
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();
     }
 }
示例#15
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);
        }
示例#16
0
        public void GetPatientById_WithEmptyPatientSet_ShouldReturnException()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);

            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);

            Assert.Throws <ArgumentException>(() => service.GetPatientById("7"));
        }
示例#17
0
        public static void Seed(DentHubContext dbContext, RoleManager <IdentityRole> roleManager, UserManager <DentHubUser> userManager)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (roleManager == null)
            {
                throw new ArgumentNullException(nameof(roleManager));
            }

            SeedRoles(roleManager);
            //SeedAdmin(DentHub.Common.GlobalConstants.AdminUserName, "Administrator", userManager, roleManager);
        }
示例#18
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);
        }
示例#19
0
        public async Task BookAppointmentAsync_WithValidId_ShouldMakeAppointmentStatusBooked()
        {
            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        = "1",
                SSN       = "123456",
                FirstName = "Test",
                LastName  = "Patient",
            };

            var appointment = new Appointment
            {
                Id        = 20,
                ClinicId  = 1,
                DentistID = "1",
                PatientId = null,
                Status    = Status.Offering,
            };

            dbContext.Appointments.Add(appointment);
            dbContext.DentHubUsers.Add(user);
            await dbContext.SaveChangesAsync();

            await service
            .BookAppointmentAsync(20, user);

            var result = dbContext.Appointments
                         .FirstOrDefaultAsync(a => a.Id == 20)
                         .GetAwaiter()
                         .GetResult();

            Assert.Equal("Booked", result
                         .Status
                         .ToString());
            Assert.Equal("1", result
                         .PatientId);
        }
示例#20
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);
        }
示例#21
0
        private static void SeedDentists(DentHubContext dbContext, string[][] dentists, UserManager <DentHubUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            foreach (var dentist in dentists)
            {
                var user = new DentHubUser
                {
                    UserName    = dentist[1],
                    FirstName   = dentist[3],
                    LastName    = dentist[4],
                    Email       = dentist[1],
                    Clinic      = dbContext.Clinics.FirstOrDefault(c => c.Name == dentist[5]),
                    SpecialtyId = dbContext.Specialties.FirstOrDefault(s => s.Name == dentist[6]).Id
                };

                var userResult = userManager.CreateAsync(user, dentist[2]).GetAwaiter().GetResult();
                var role       = roleManager.FindByNameAsync(dentist[0]).GetAwaiter().GetResult();

                //if (role == null)
                //{
                //    var result = roleManager.CreateAsync(new IdentityRole(roleName)).GetAwaiter().GetResult();

                //    if (!result.Succeeded)
                //    {
                //        throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description)));
                //    }
                //}

                //if (user == null)
                //{
                //	var result = userManager.CreateAsync(new DentHubUser(GlobalConstants.AdminUserName)).GetAwaiter().GetResult();

                //	if (!result.Succeeded)
                //	{
                //		throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description)));
                //	}
                //}

                if (userResult.Succeeded)
                {
                    var resultRole      = userManager.AddToRoleAsync(user, role.Name).GetAwaiter().GetResult();
                    var resultClaimRole = userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Dentist")).GetAwaiter().GetResult();
                }
            }
        }
示例#22
0
        private static void SeedPatients(DentHubContext dbContext, string[][] patients, UserManager <DentHubUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            foreach (var patient in patients)
            {
                var user = new DentHubUser
                {
                    UserName  = patient[1],
                    FirstName = patient[3],
                    LastName  = patient[4],
                    Email     = patient[1],
                    SSN       = patient[5],
                };

                var userResult = userManager.CreateAsync(user, patient[2]).GetAwaiter().GetResult();
                var role       = roleManager.FindByNameAsync(patient[0]).GetAwaiter().GetResult();

                //if (role == null)
                //{
                //    var result = roleManager.CreateAsync(new IdentityRole(roleName)).GetAwaiter().GetResult();

                //    if (!result.Succeeded)
                //    {
                //        throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description)));
                //    }
                //}

                //if (user == null)
                //{
                //	var result = userManager.CreateAsync(new DentHubUser(GlobalConstants.AdminUserName)).GetAwaiter().GetResult();

                //	if (!result.Succeeded)
                //	{
                //		throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description)));
                //	}
                //}

                if (userResult.Succeeded)
                {
                    var resultRole      = userManager.AddToRoleAsync(user, role.Name).GetAwaiter().GetResult();
                    var resultClaimRole = userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Patient")).GetAwaiter().GetResult();
                }
            }
        }
示例#23
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();
     }
     ;
 }
示例#24
0
        public async Task GetAllPatientAppointments_WithValidId_ShouldReturnAppointments()
        {
            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        = 11,
                ClinicId  = 1,
                DentistID = "1",
                PatientId = "1",
                Status    = Status.Booked
            };
            var appointment2 = new Appointment
            {
                Id        = 12,
                ClinicId  = 1,
                DentistID = "2",
                PatientId = "1",
                Status    = Status.Booked
            };
            var appointment3 = new Appointment
            {
                Id        = 13,
                ClinicId  = 1,
                DentistID = "2",
                PatientId = "2",
                Status    = Status.Booked
            };

            dbContext.Appointments.Add(appointment);
            dbContext.Appointments.Add(appointment2);
            dbContext.Appointments.Add(appointment3);
            await dbContext.SaveChangesAsync();

            var repository       = new DbRepository <Appointment>(dbContext);
            var ratingRepository = new DbRepository <Rating>(dbContext);
            var service          = new AppointmentService(repository, ratingRepository);
            var result           = service.GetAllPatientAppointments("1");

            Assert.Equal(new Appointment[] { appointment, appointment2 }, result);
        }
示例#25
0
        public async Task GetPatientById_WithValidId_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 patient   = new DentHubUser
            {
                Id          = "1",
                SSN         = "123456",
                Email       = "*****@*****.**",
                FirstName   = "Test",
                LastName    = "LastName",
                IsActive    = true,
                PhoneNumber = "1234",
                UserName    = "******",
            };
            var patient2 = new DentHubUser
            {
                Id          = "2",
                SSN         = "1234567",
                Email       = "*****@*****.**",
                FirstName   = "Test2",
                LastName    = "LastName2",
                IsActive    = true,
                PhoneNumber = "123456",
                UserName    = "******",
            };

            dbContext.DentHubUsers.Add(patient);
            dbContext.DentHubUsers.Add(patient2);
            await dbContext.SaveChangesAsync();

            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.GetPatientById("2");

            Assert.Same(patient2, result);
        }
示例#26
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);
        }
示例#27
0
        public async Task GetDentistById_WithValidIdAndNoSpecialty_ShouldReturnException()
        {
            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          = "20",
                SpecialtyId = 1,
                Email       = "*****@*****.**",
                FirstName   = "Test",
                LastName    = "LastName",
                IsActive    = false,
                PhoneNumber = "1234",
                UserName    = "******",
            };
            var dentist2 = new DentHubUser
            {
                Id          = "21",
                Specialty   = null,
                Email       = "*****@*****.**",
                FirstName   = "Test2",
                LastName    = "LastName2",
                IsActive    = true,
                PhoneNumber = "123456",
                UserName    = "******",
            };

            dbContext.DentHubUsers.Add(dentist);
            dbContext.DentHubUsers.Add(dentist2);
            await dbContext.SaveChangesAsync();

            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);

            Assert.Throws <ArgumentException>(() => service.GetDentistById("21"));
        }
示例#28
0
        public async Task GetPatientById_WithValidIdAndNoSSN_ShouldReturnException()
        {
            var options = new DbContextOptionsBuilder <DentHubContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())  // Give a Unique name to the DB
                          .Options;
            var dbContext = new DentHubContext(options);
            var patient5  = new DentHubUser
            {
                Id          = "5",
                SSN         = "123456",
                Email       = "*****@*****.**",
                FirstName   = "Test5",
                LastName    = "LastName5",
                IsActive    = false,
                PhoneNumber = "1234",
                UserName    = "******",
            };
            var patient6 = new DentHubUser
            {
                Id          = "6",
                SSN         = null,
                Email       = "*****@*****.**",
                FirstName   = "Test6",
                LastName    = "LastName6",
                IsActive    = true,
                PhoneNumber = "123456",
                UserName    = "******",
            };

            dbContext.DentHubUsers.Add(patient5);
            dbContext.DentHubUsers.Add(patient6);
            await dbContext.SaveChangesAsync();

            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);

            Assert.Throws <ArgumentException>(() => service.GetPatientById("6"));
        }
示例#29
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);
        }
示例#30
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);
        }