public async Task CreateRecipientCorrectResipientHospitalDataEntityTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await SeedDataAsync(dbContext); var recipient = recipientRepository .All() .Where(u => u.Age == 85) .FirstOrDefault(); var recipientHospitalData = recipientHospitalDataRepository .All() .FirstOrDefault(); Assert.Equal(recipient.Id, recipientHospitalData.RecipientId); }
public async Task GetRecipientByIdShouldReturnCorrectlyTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await SeedDataAsync(dbContext); var recipient = recipientRepository.All().FirstOrDefault(); var result = service.GetById <RecipientInfoViewModel>(recipient.Id); Assert.NotNull(result); }
public async Task DeleteAsyncRecipientsCorrectlyTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await SeedDataAsync(dbContext); var hospital = hospitalDataRepository.All().FirstOrDefault(); var recipient = recipientRepository.All().FirstOrDefault(); await service.DeleteAsync(hospital.ApplicationUserId, recipient.Id); var result = service.TotalRecipients <RecipientInfoViewModel>(hospital.ApplicationUserId).Count(); Assert.Equal(0, result); }
public async Task CreateRecipientShouldReturnNotNullTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); // Seeding user var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", }; dbContext.Users.Add(user); // Seeding hospital var hospital = new HospitalData { ApplicationUserId = user.Id, Name = "HospitalName", Contact = new Contact { Phone = "123456789", Email = "*****@*****.**", }, Location = new Location { Country = "Bulgaria", City = "Sofia", AdressDescription = "Sofia", }, }; dbContext.HospitalData.Add(hospital); await dbContext.SaveChangesAsync(); await service.AddRecipientAsync(hospital.ApplicationUserId, "recipient1", "recipient1", "recipient1", 85, 500, EmergencyStatus.WithinWeek, BloodGroup.A, RhesusFactor.Negative); var result = recipientRepository .All() .Where(u => u.Age == 85) .FirstOrDefault(); Assert.NotNull(result); }
public async Task AddRequestForRecipientThrowsExceptionTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await service.AddRequestForRecipient("123", "456"); await Assert.ThrowsAsync <ArgumentException>(() => service.AddRequestForRecipient("123", "456")); }
public async Task GetRecipientByIdShouldThrowErrorTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await SeedDataAsync(dbContext); Assert.Throws <ArgumentException>(() => service.GetById <RecipientInfoViewModel>(null)); }
public void CreateRecipientNullTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); var user = recipientRepository .All() .Where(u => u.Age == 85) .FirstOrDefault(); Assert.Null(user); }
public async Task CreateRecipientShouldthrowExceptionDueToNullHospitalDataTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); var result = recipientRepository .All() .Where(u => u.Age == 85) .FirstOrDefault(); await Assert.ThrowsAsync <ArgumentException>(() => service.AddRecipientAsync("1", "recipient1", "recipient1", "recipient1", 85, 500, EmergencyStatus.WithinWeek, BloodGroup.A, RhesusFactor.Negative)); }
public async Task AddRequestForRecipientCorrectlyTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await service.AddRequestForRecipient("123", "456"); var result = recipientReques.All().Count(); Assert.Equal(1, result); }
public async Task DeleteAsyncRecipientsThrowsExceptionTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await SeedDataAsync(dbContext); var hospital = hospitalDataRepository.All().FirstOrDefault(); await Assert.ThrowsAsync <ArgumentException>(() => service.DeleteAsync(hospital.ApplicationUserId, "1")); }
public async Task AllHospitalRecipientsShouldReturnNullTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); MapperInitializer.InitializeMapper(); var recipientRepository = new EfDeletableEntityRepository <Recipient>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var recipientReques = new EfDeletableEntityRepository <RecipientRequest>(dbContext); var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext); var service = new RecipientsService( recipientRepository, hospitalDataRepository, recipientReques, recipientHospitalDataRepository); await SeedDataAsync(dbContext); var result = service.AllHospitalRecipients <RecipientInfoViewModel>(null).Count(); Assert.Equal(0, result); }