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