コード例 #1
0
        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));
        }
コード例 #2
0
 public CategoryRepository(SoftNewsContext dbContext)
 => this.dbContext = dbContext;
コード例 #3
0
 public AuthRepository(DbContext.SoftNewsContext context)
 {
     this.context = context;
 }
コード例 #4
0
 public NewsRepository(SoftNewsContext context)
 {
     this.context = context;
 }