public static IServiceCollection AddMockedServices(this IServiceCollection services) { var categoryService = Substitute.For <ICategoryService>(); categoryService.GetCategories().Returns(listCategories); var newsService = Substitute.For <INewsService>(); newsService.AddAsync(Arg.Any <News>()).Returns(Task.FromResult(1)); newsService.DeleteAsync(Arg.Any <int>()).Returns(Task.FromResult(1)); var news = new News { Image = System.IO.File.ReadAllBytes($"{AppDomain.CurrentDomain.BaseDirectory}/Image/sampleimage.jpg") }; newsService.DeleteAsync(Arg.Is(ValidNewsId)).Returns(Task.FromResult(1)); newsService.GetById(Arg.Is(ValidNewsId)).Returns(Task.FromResult(news)); var options = new DbContextOptionsBuilder <SoftNewsContext>() .UseSqlite("Filename=TestDatabase.db") .Options; var dbContext = new SoftNewsContext(options); services.AddSingleton(dbContext); services.AddSingleton(categoryService); return(services.AddSingleton(newsService)); }
public CategoryRepository(SoftNewsContext dbContext) => this.dbContext = dbContext;
public AuthRepository(DbContext.SoftNewsContext context) { this.context = context; }
public NewsRepository(SoftNewsContext context) { this.context = context; }