public async Task TestEditTextTemplateAsyncMethod() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("testDb3"); var virtualDbContext = new ApplicationDbContext(optionsBuilder.Options); IEFRepository <TextTemplate> textTemplateRepository = new EFRepository <TextTemplate>(virtualDbContext); IEFRepository <Obituary> obituaryRepository = new EFRepository <Obituary>(virtualDbContext); var textService = new TextsService(textTemplateRepository, obituaryRepository); await textService.AddTextToDbAsync("text test 1"); await textService.AddTextToDbAsync("text test 2"); await textTemplateRepository.SaveChangesAsync(); var textId = textTemplateRepository.All() .Select(t => t.Id).FirstOrDefault(); await textService.EditTextTemplateAsync(textId, "new edited text"); await textTemplateRepository.SaveChangesAsync(); var text = textTemplateRepository.All() .Select(t => t.Text).FirstOrDefault(); Assert.Equal("new edited text", text); }
public void TestReturnFirtsTextMethod() { var textService = new TextsService(textTemplateRepo.Object, obituaryRepo.Object); var text = textService.ReturnFirtsText(); Assert.Equal("Text test 1", text); }
public void TestGetTextByIdMethod() { var textService = new TextsService(textTemplateRepo.Object, obituaryRepo.Object); var text = textService.GetTextById("ttId1"); Assert.Equal("Text test 1", text); }
public void TestShowAllTextsMethod() { var textService = new TextsService(textTemplateRepo.Object, obituaryRepo.Object); var textsCount = textService.ShowAllTexts().Count(); Assert.Equal(2, textsCount); }
public async Task TestAddTextToDbAsyncMethod() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("testDb"); var virtualDbContext = new ApplicationDbContext(optionsBuilder.Options); IEFRepository <TextTemplate> textTemplateRepository = new EFRepository <TextTemplate>(virtualDbContext); IEFRepository <Obituary> obituaryRepository = new EFRepository <Obituary>(virtualDbContext); var textService = new TextsService(textTemplateRepository, obituaryRepository); await textService.AddTextToDbAsync("text test 1"); await textService.AddTextToDbAsync("text test 2"); await textTemplateRepository.SaveChangesAsync(); var dbCount = textTemplateRepository.All().Count(); Assert.Equal(2, dbCount); }