Exemplo n.º 1
0
        public void GetAllShouldReturnIcollectionInputModel()
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

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

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

            var specialityModels = new List <Speciality>
            {
                new Speciality {
                    Id = 1, Name = "Dentist"
                },
                new Speciality {
                    Id = 2, Name = "Anesthesiologist"
                },
            };

            context.Specialities.AddRange(specialityModels);
            context.SaveChanges();

            //// Act
            var resultSpecialities = service.GetAll <SpecialityInputModel>().GetAwaiter().GetResult();

            //// Assert
            Assert.AreEqual(true, resultSpecialities is ICollection <SpecialityInputModel>);
        }
Exemplo n.º 2
0
        public void CreateShouldThrowErrorWithSameId()
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

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

            using var context = new S2DentDbContext(options);
            var service    = new SpecialitiesService(context);
            var speciality = new Speciality {
                Id = 1, Name = "TestName"
            };

            context.Specialities.Add(speciality);
            context.SaveChanges();

            //// Act
            var testSpeciality = new Speciality {
                Id = 1, Name = "TestSpeciality"
            };


            //// Assert
            Assert.That(() =>
                        service.Create(testSpeciality).GetAwaiter().GetResult(),
                        Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Speciality already exists."));
        }
Exemplo n.º 3
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."));
        }
Exemplo n.º 4
0
        public void GetOneShouldReturnTheRightData(int id, string name)
        {
            //// Arrange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

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

            var speciality = new Speciality
            {
                Id   = id,
                Name = name,
            };

            using (var context = new S2DentDbContext(options))
            {
                context.Specialities.Add(speciality);
                context.SaveChanges();
            }

            using (var context = new S2DentDbContext(options))
            {
                //// Act
                var service     = new SpecialitiesService(context);
                var resultModel = service.GetOne <SpecialityViewModel>(id).GetAwaiter().GetResult();

                //// Assert
                Assert.AreEqual(speciality.Id, resultModel.Id);
                Assert.AreEqual(speciality.Name, resultModel.Name);
                Assert.AreEqual(true, resultModel is SpecialityViewModel);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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."));
        }
Exemplo n.º 8
0
        public void GetAllShouldReturnICollection()
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(
                typeof(DoctorViewModel).GetTypeInfo().Assembly);

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

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

            var inputDoctors = new List <Doctor>()
            {
                new Doctor {
                    FirstName = "Ivan", ThirdName = "Zlatev"
                },
                new Doctor {
                    FirstName = "Peshi", ThirdName = "Georgiev"
                },
            };

            context.Doctors.AddRange(inputDoctors);
            context.SaveChanges();

            //// Act
            var resultDoctors = service.GetAll <DoctorViewModel>().GetAwaiter().GetResult();

            //// Assert
            Assert.AreEqual(true, resultDoctors is ICollection <DoctorViewModel>);
        }
Exemplo n.º 9
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."));
        }
Exemplo n.º 10
0
        public void EditDoctorShouldChangeSpecility()
        {
            //// Arange
            var options = new DbContextOptionsBuilder <S2DentDbContext>()
                          .UseInMemoryDatabase(nameof(EditDoctorShouldChangeSpecility))
                          .Options;

            using var context = new S2DentDbContext(options);
            var service = new DoctorsService(context);
            var doctor  = new Doctor
            {
                Id         = Guid.NewGuid().ToString(),
                FirstName  = "John",
                MiddleName = "Doe",
                ThirdName  = "Johnson",
                IsDeleted  = false,
                Speciality = new Speciality
                {
                    Id   = 1,
                    Name = "Doctor"
                }
            };

            var editSpeciality = new Speciality
            {
                Id   = 2,
                Name = "Pediatritian",
            };

            context.Specialities.Add(editSpeciality);
            context.Doctors.Add(doctor);
            context.SaveChanges();

            //// Act
            var editDoctor = new Doctor
            {
                Id         = doctor.Id,
                FirstName  = doctor.FirstName,
                MiddleName = doctor.MiddleName,
                ThirdName  = doctor.ThirdName,
                IsDeleted  = false,
                Speciality = editSpeciality,
            };

            service.EditDoctorInfo(editDoctor).GetAwaiter().GetResult();
            var resultDoctor =
                context.Doctors.SingleOrDefault(x => x.Id == editDoctor.Id && x.IsDeleted == false);

            Assert.AreEqual(editSpeciality.Id, resultDoctor.Speciality.Id);
            Assert.AreEqual(editSpeciality.Name, resultDoctor.Speciality.Name);
        }
Exemplo n.º 11
0
        public void GetByIdShouldReturnInputModelProperly(
            string firstName, string middleName,
            string lastName, string email,
            string description, int speciality,
            string specailityName, string phone)
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(
                typeof(DoctorViewModel).GetTypeInfo().Assembly);

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

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

            var specialityModel = new Speciality {
                Id = speciality, Name = specailityName
            };

            var doctor = new Doctor
            {
                Id          = Guid.NewGuid().ToString(),
                FirstName   = firstName,
                MiddleName  = middleName,
                ThirdName   = lastName,
                Email       = email,
                Description = description,
                Speciality  = specialityModel,
                PhoneNumber = phone,
            };

            context.Doctors.Add(doctor);
            context.Specialities.Add(specialityModel);
            context.SaveChanges();

            //// Act
            var resultDoctor = service.GetById <DoctorInputModel>(doctor.Id).GetAwaiter().GetResult();

            //// Assert
            Assert.AreEqual(doctor.FirstName, resultDoctor.FirstName);
            Assert.AreEqual(doctor.MiddleName, resultDoctor.MiddleName);
            Assert.AreEqual(doctor.ThirdName, resultDoctor.ThirdName);
            Assert.AreEqual(doctor.Email, resultDoctor.Email);
            Assert.AreEqual(doctor.Description, resultDoctor.Description);
            Assert.AreEqual(doctor.Speciality.Id, resultDoctor.SpecialityId);
            Assert.AreEqual(doctor.PhoneNumber, resultDoctor.PhoneNumber);
            Assert.AreEqual(doctor.Id, resultDoctor.Id);
            Assert.AreEqual(typeof(DoctorInputModel), resultDoctor.GetType());
        }
Exemplo n.º 12
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."));
        }
Exemplo n.º 13
0
        public void EditDoctorShowldChangeBasicProperties(
            string id, string firstName, string middleName,
            string lastName)
        {
            //// Arange
            var options = new DbContextOptionsBuilder <S2DentDbContext>()
                          .UseInMemoryDatabase(nameof(EditDoctorShowldChangeBasicProperties))
                          .Options;

            using var context = new S2DentDbContext(options);
            var service = new DoctorsService(context);
            var doctor  = new Doctor
            {
                Id         = id,
                FirstName  = "John",
                MiddleName = "Doe",
                ThirdName  = "Johnson",
                IsDeleted  = false,
            };

            context.Doctors.Add(doctor);
            context.SaveChanges();

            //// Act
            var editDoctor = new Doctor
            {
                Id         = id,
                FirstName  = firstName,
                MiddleName = middleName,
                ThirdName  = lastName,
            };

            service.EditDoctorInfo(editDoctor).GetAwaiter().GetResult();

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

            Assert.AreEqual(editDoctor.Id, doctorModel.Id);
            Assert.AreEqual(editDoctor.FirstName, doctorModel.FirstName);
            Assert.AreEqual(editDoctor.MiddleName, doctorModel.MiddleName);
            Assert.AreEqual(editDoctor.ThirdName, doctorModel.ThirdName);
        }
Exemplo n.º 14
0
        public void CreateShouldCreateOject(string name)
        {
            //// Arange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

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

            using var context = new S2DentDbContext(options);
            var service    = new SpecialitiesService(context);
            var speciality = new Speciality {
                Name = name
            };

            //// Act
            service.Create(speciality).GetAwaiter().GetResult();

            //// Assert
            Assert.AreEqual(true, context.Specialities.Any(x => x.Name == speciality.Name));
        }
Exemplo n.º 15
0
        public void GetAllShouldWorkProperly()
        {
            //// Arrange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

            var options = new DbContextOptionsBuilder <S2DentDbContext>()
                          .UseInMemoryDatabase(nameof(GetAllShouldWorkProperly))
                          .Options;
            var specialityModels = new List <Speciality>()
            {
                new Speciality {
                    Id = 1, Name = "Anesthesiologist", IsDeleted = false
                },
                new Speciality {
                    Id = 2, Name = "Orthodontologist", IsDeleted = false
                },
                new Speciality {
                    Id = 3, Name = "Dentists", IsDeleted = true
                },
            };

            using (var context = new S2DentDbContext(options))
            {
                context.Specialities.AddRange(specialityModels);
                context.SaveChanges();
            }

            using (var context = new S2DentDbContext(options))
            {
                //// Assert
                var service      = new SpecialitiesService(context);
                var specialities = service.GetAll <SpecialityViewModel>().GetAwaiter().GetResult();

                Assert.AreEqual(specialityModels[0].Name, specialities.FirstOrDefault(x => x.Id == 1).Name);
                Assert.AreEqual(specialityModels[1].Name, specialities.FirstOrDefault(x => x.Id == 2).Name);
                Assert.AreEqual(2, specialities.Count());
            }
        }
Exemplo n.º 16
0
        public void GetOneShouldReturnTheRightType()
        {
            //// Arrange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

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

            using (var context = new S2DentDbContext(options))
            {
                var speciality = new Speciality
                {
                    Id   = 2,
                    Name = "Dentist",
                };

                if (!context.Specialities.Any(x => x.Name == speciality.Name))
                {
                    context.Specialities.Add(speciality);
                    context.SaveChanges();
                }
            }

            using (var context = new S2DentDbContext(options))
            {
                //// Act
                var service    = new SpecialitiesService(context);
                var viewModel  = service.GetOne <SpecialityViewModel>(2).GetAwaiter().GetResult();
                var inputModel = service.GetOne <SpecialityInputModel>(2).GetAwaiter().GetResult();

                //// Assert
                Assert.AreEqual(true, viewModel is SpecialityViewModel);
                Assert.AreEqual(true, inputModel is SpecialityInputModel);
            }
        }
Exemplo n.º 17
0
        public void GetOneShouldThrowException(
            [Range(-1, 1)] int intId)
        {
            //// Arrange
            AutoMapperConfig.RegisterMappings(
                typeof(SpecialityViewModel).GetTypeInfo().Assembly);

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

            using (var context = new S2DentDbContext(options))
            {
                var speciality = new Speciality
                {
                    Id   = 2,
                    Name = "Dentist",
                };

                if (!context.Specialities.Any(x => x.Name == speciality.Name))
                {
                    context.Specialities.Add(speciality);
                    context.SaveChanges();
                }
            }

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

                //// Assert
                Assert.That(
                    () => service.GetOne <SpecialityViewModel>(intId).GetAwaiter().GetResult(),
                    Throws.TypeOf <ArgumentException>().With.Message.EqualTo("Speciality does not exist."));
            }
        }
Exemplo n.º 18
0
 public DoctorsService(S2DentDbContext context)
 {
     dbContext = context;
 }
Exemplo n.º 19
0
 public SpecialitiesService(S2DentDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 20
0
 public NewsService(S2DentDbContext context)
 {
     this.dbContext = context;
 }