Beispiel #1
0
        public PatientRepository(BefordingTestContext context, IUserInfoService userInfoService, ILogRepository logRepository)
        {
            _context         = context;
            _userInfoService = userInfoService;
            _logRepository   = logRepository;

            UserId = _userInfoService.UserId;
        }
Beispiel #2
0
        public async void AddLogTest()
        {
            var options = new DbContextOptionsBuilder <BefordingTestContext>()
                          .UseInMemoryDatabase(databaseName: "BefordingTestDb")
                          .Options;
            var context = new BefordingTestContext(options);

            var repository = new LogRepository(context, _userServiceMock.Object);

            await repository.AddLog("123", "Test message");

            Assert.True(context.Logs.FirstOrDefault(x => x.UserId == "123") != null);
        }
 private async void fillMockDatabase(int numberOfElements, BefordingTestContext context)
 {
     for (int i = 0; i < numberOfElements; i++)
     {
         var dummyHospital = new HospitalProfile()
         {
             Address        = "" + i,
             NameOfHospital = "UUU",
             Rate           = i
         };
         context.Profiles.Add(dummyHospital);
         await context.SaveChangesAsync();
     }
 }
        public async void DeleteProfileTest()
        {
            var options = new DbContextOptionsBuilder <BefordingTestContext>()
                          .UseInMemoryDatabase(databaseName: "BefordingTestDb")
                          .Options;
            var context = new BefordingTestContext(options);

            var repository = new ProfileRepository(context, _userInfoServiceMock.Object, _logRepositoryMock.Object);

            fillMockDatabase(5, context);

            await repository.DeleteProfile(2);

            Assert.True(context.Profiles.FirstOrDefault(x => x.Id == 2) == null);
        }
        public async void CreateProfileTest()
        {
            var options = new DbContextOptionsBuilder <BefordingTestContext>()
                          .UseInMemoryDatabase(databaseName: "BefordingTestDb")
                          .Options;
            var context = new BefordingTestContext(options);

            var repository = new ProfileRepository(context, _userInfoServiceMock.Object, _logRepositoryMock.Object);

            var dummyHospitalVM = new HospitalProfileVM()
            {
                Address        = "a",
                NameOfHospital = "UUU",
                Rate           = 1
            };
            var result = await repository.CreateProfile(dummyHospitalVM);

            Assert.True(result.GetType() == typeof(HospitalProfile));
            Assert.True(result.Id == 1);
        }
Beispiel #6
0
        public async void IntegrationTestDeleteProfile()
        {
            var options = new DbContextOptionsBuilder <BefordingTestContext>()
                          .UseInMemoryDatabase(databaseName: "BefordingTestDb")
                          .Options;
            var context = new BefordingTestContext(options);

            var logRepository = new LogRepository(context, _userInfoServiceMock.Object);

            var profileRepository = new ProfileRepository(context, _userInfoServiceMock.Object, logRepository);

            var dummyHospital = new HospitalProfile()
            {
                Address        = "Address",
                NameOfHospital = "UUU",
                Rate           = 0
            };

            context.Profiles.Add(dummyHospital);
            await context.SaveChangesAsync();

            Assert.True(context.Profiles.FirstOrDefaultAsync(x => x.Address == "Address") != null);
            Assert.True(context.Profiles.FirstOrDefaultAsync(x => x.Id == 1) != null);
            Assert.True(await context.Profiles.CountAsync() == 1);

            await profileRepository.DeleteProfileAdmin(1);

            Assert.True(await context.Profiles.CountAsync() == 0);

            Assert.True(await context.Logs.CountAsync() == 0);

            context.Profiles.Add(dummyHospital);
            await context.SaveChangesAsync();

            await profileRepository.DeleteProfileAdmin(-1);

            Assert.True(await context.Logs.CountAsync() == 1);
        }
Beispiel #7
0
 public LogRepository(BefordingTestContext context, IUserInfoService userInfoService)
 {
     _context         = context;
     _userInfoService = userInfoService;
 }