Пример #1
0
        public async Task Create(Speciality speciality)
        {
            if (dbContext.Specialities.Any(x => x.Name.ToLower() == speciality.Name.ToLower() || x.Id == speciality.Id))
            {
                throw new ArgumentException("Speciality already exists.");
            }

            await dbContext.Specialities.AddAsync(speciality);

            await dbContext.SaveChangesAsync();
        }
Пример #2
0
        public void EditShouldWorkProperly(string specialityName, bool isDeleted)
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(typeof(SpecialityViewModel).GetTypeInfo().Assembly);

            var options = new DbContextOptionsBuilder <S2DentDbContext>().UseInMemoryDatabase(nameof(EditShouldWorkProperly)).Options;

            using var context = new S2DentDbContext(options);
            var service = new SpecialitiesService(context);

            var speciality = new Speciality {
                Id = 1, Name = "Dentist", IsDeleted = false
            };

            context.Specialities.Add(speciality);
            context.SaveChangesAsync().GetAwaiter().GetResult();

            var editSpeciality = new Speciality {
                Id = 1, Name = specialityName, IsDeleted = isDeleted
            };

            //// Act
            service.Edit(editSpeciality).GetAwaiter().GetResult();

            //// Assert
            var specialityModel = context.Specialities.FirstOrDefault(x => x.Id == 1);

            Assert.AreEqual(specialityName, specialityModel.Name);
            Assert.AreEqual(isDeleted, specialityModel.IsDeleted);
        }
Пример #3
0
        public void EditShouldThrowError()
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(typeof(SpecialityViewModel).GetTypeInfo().Assembly);

            var options = new DbContextOptionsBuilder <S2DentDbContext>().UseInMemoryDatabase(nameof(EditShouldThrowError)).Options;

            using var context = new S2DentDbContext(options);
            var service = new SpecialitiesService(context);

            var speciality = new Speciality {
                Id = 1, Name = "Dentist", IsDeleted = false
            };

            context.Specialities.Add(speciality);
            context.SaveChangesAsync().GetAwaiter().GetResult();

            var editSpeciality = new Speciality {
                Id = 2, Name = "Anesthesiologis", IsDeleted = false
            };

            //// Assert
            Assert.That(() =>
                        service.Edit(editSpeciality).GetAwaiter().GetResult(),
                        Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Speciality does not exist."));
        }
Пример #4
0
        public void DeleteDoctorShouldWorkProperly()
        {
            //// Arrange
            var options = new DbContextOptionsBuilder <S2DentDbContext>()
                          .UseInMemoryDatabase(nameof(DeleteShouldTrhowException))
                          .Options;

            using var context = new S2DentDbContext(options);
            var service = new DoctorsService(context);
            var doctor  = new Doctor
            {
                Id         = Guid.NewGuid().ToString(),
                FirstName  = "TestDoctor",
                MiddleName = "TestDoctors",
                ThirdName  = "FamilyName",
                IsDeleted  = false,
            };

            context.Doctors.Add(doctor);
            context.SaveChangesAsync().GetAwaiter().GetResult();

            //// Act
            service.Delete(doctor.Id).GetAwaiter().GetResult();

            //// Assert
            var doctorModel = context.Doctors.FirstOrDefault(x => x.Id == doctor.Id);

            Assert.AreEqual(true, doctorModel.IsDeleted);
        }
Пример #5
0
        public void DeleteShouldTrhowException(string id, bool isDeleted)
        {
            //// Arrange
            var options = new DbContextOptionsBuilder <S2DentDbContext>()
                          .UseInMemoryDatabase(nameof(DeleteShouldTrhowException))
                          .Options;

            using var context = new S2DentDbContext(options);

            var service = new DoctorsService(context);
            var doctor  = new Doctor
            {
                Id         = Guid.NewGuid().ToString(),
                FirstName  = "TestDoctor",
                MiddleName = "TestDoctors",
                ThirdName  = "FamilyName",
                IsDeleted  = isDeleted,
            };

            context.Doctors.Add(doctor);
            context.SaveChangesAsync().GetAwaiter().GetResult();

            //// Assert
            Assert.That(
                () => service.Delete(id).GetAwaiter().GetResult(),
                Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Doctor does not exist."));
            Assert.That(
                () => service.Delete(doctor.Id).GetAwaiter().GetResult(),
                Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Doctor does not exist."));
        }
Пример #6
0
        public void GetByIdShouldThrowErrorWhenEntityIsDeleted()
        {
            AutoMapperConfig.RegisterMappings(
                typeof(DoctorViewModel).GetTypeInfo().Assembly);

            var options = new DbContextOptionsBuilder <S2DentDbContext>()
                          .UseInMemoryDatabase(nameof(GetByIdShouldThrowErrorWhenEntityIsDeleted))
                          .Options;

            using var context = new S2DentDbContext(options);
            var service = new DoctorsService(context);

            var doctor = new Doctor
            {
                Id        = Guid.NewGuid().ToString(),
                IsDeleted = true,
            };

            context.Doctors.AddAsync(doctor);
            context.SaveChangesAsync();

            Assert.That(
                () => service.GetById <DoctorViewModel>(doctor.Id).GetAwaiter().GetResult(),
                Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Doctor does not exist."));
        }
Пример #7
0
        public void EditDoctorShouldThrowException(string id, bool isDeleted)
        {
            //// Arange
            var options = new DbContextOptionsBuilder()
                          .UseInMemoryDatabase(nameof(EditDoctorShouldThrowException))
                          .Options;
            var context = new S2DentDbContext(options);
            var service = new DoctorsService(context);
            var doctor  = new Doctor
            {
                Id         = Guid.NewGuid().ToString(),
                FirstName  = "SomeFirstName",
                MiddleName = "SomeMiddleName",
                IsDeleted  = isDeleted,
            };

            context.Doctors.Add(doctor);
            context.SaveChangesAsync().GetAwaiter().GetResult();

            //// Act
            var testInputDoctor = new Doctor
            {
                Id         = id,
                FirstName  = doctor.FirstName,
                MiddleName = doctor.MiddleName,
                IsDeleted  = false
            };

            var secondTestInputDoctor = new Doctor
            {
                Id         = doctor.Id,
                FirstName  = doctor.FirstName,
                MiddleName = doctor.MiddleName,
                IsDeleted  = doctor.IsDeleted,
            };

            //// Assert
            Assert.That(
                () => service.EditDoctorInfo(testInputDoctor).GetAwaiter().GetResult(),
                Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Doctor does not exist."));
            Assert.That(
                () => service.EditDoctorInfo(secondTestInputDoctor).GetAwaiter().GetResult(),
                Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Doctor does not exist."));
        }
Пример #8
0
 public async Task Create(Doctor doctor, string password)
 {
     doctor.PasswordHash = GetHashedPassword(password);
     dbContext.Doctors.Add(doctor);
     await dbContext.SaveChangesAsync();
 }