Exemplo n.º 1
0
        public void SetUp()
        {
            var connection = DbConnectionFactory.CreateTransient();

            dbContext      = new ItemsDbContext(connection);
            itemRepository = new ItemRepository(dbContext);
        }
Exemplo n.º 2
0
        protected async Task <ItemApiModel> SaveItemAsync(Item itemToSave)
        {
            using IServiceScope scope = Server.CreateScope();

            ItemsDbContext itemsDbContext = scope.ServiceProvider.GetRequiredService <ItemsDbContext>();

            itemsDbContext.Add(itemToSave);

            await itemsDbContext.SaveChangesAsync();

            return(new ItemApiModel
            {
                Id = itemToSave.Id,
                IsDone = itemToSave.IsDone,
                Text = itemToSave.Text,
                Priority = itemToSave.Priority
            });
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            var timer = Stopwatch.StartNew();

            var items = ApiCaller.GetItems <BaseModel>("delirium", "base");

            var db = new ItemsDbContext();
            //var deleted = db.Database.EnsureDeleted();
            var created = db.Database.EnsureCreated();

            //Console.WriteLine(deleted);
            Console.WriteLine(created);

            if (db.Bases.Any())
            {
                Console.WriteLine("Updating Items");
                db.Bases.UpdateRange(items);
                db.SaveChanges();
            }
            else
            {
                Console.WriteLine("Adding Items");
                db.Bases.AddRange(items);
                db.SaveChanges();
            }


            foreach (var accessoryModel in db.Bases.Where(a => a.Exalted > 1).OrderBy(a => a.Exalted))
            {
                Console.Write($"{accessoryModel.Name} ");

                foreach (var influence in accessoryModel.Influences)
                {
                    Console.Write($"{influence.ToString()} ");
                }
                Console.Write($"{accessoryModel.BaseItemLevel} {accessoryModel.Exalted} {accessoryModel.Id}");
                Console.Write("\n");
            }
            Console.WriteLine("Finished in {0}ms", timer.ElapsedMilliseconds);
        }
Exemplo n.º 4
0
        public TestServerFixture()
        {
            string projectRootPath = Path.Combine(
                Directory.GetCurrentDirectory(),
                "..", "..", "..", "..", "..", "src", "services", "Items", "TodoList.Items.API");

            IWebHostBuilder webHostBuilder = WebHost.CreateDefaultBuilder()
                                             .UseContentRoot(projectRootPath)
                                             .UseEnvironment(Environments.Development)
                                             .UseStartup <TestStartup>();

            Server = new TestServer(webHostBuilder);
            Client = Server.CreateClient();

            AsyncRetryPolicy retryPolicy = Policy
                                           .Handle <SqlException>()
                                           .WaitAndRetryAsync(3, retryNumber => TimeSpan.FromSeconds(retryNumber * 2), (exception, sleepDuration) => Console.WriteLine($"SQL Server connection retry, sleep duration: {sleepDuration}"));

            User?user = null;

            retryPolicy.ExecuteAsync(async() =>
            {
                using IServiceScope scope = Server.CreateScope();

                ItemsDbContext itemsDbContext = scope.ServiceProvider.GetRequiredService <ItemsDbContext>();

                await itemsDbContext.Database.MigrateAsync();

                user = await itemsDbContext.Users
                       .AsNoTracking()
                       .SingleAsync(u => u.IdentityId == 1);
            }).GetAwaiter().GetResult();

            User = user !;

            Server.Services.GetRequiredService <IOptions <RouteOptions> >().Value.SuppressCheckForUnhandledSecurityMetadata = true;
        }
Exemplo n.º 5
0
 public ItemsController(ItemsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 6
0
 public TestDataBuilder(ItemsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 7
0
 public ItemsService(ItemsDbContext db) : base(db)
 {
 }
Exemplo n.º 8
0
 public ItemRepository(ItemsDbContext dbContext) : base(dbContext)
 {
 }
Exemplo n.º 9
0
 protected BaseService(ItemsDbContext db)
 {
     _db = db;
 }
Exemplo n.º 10
0
        private ItemsDbContext _itemsDbContext; //= new ItemsDbContext();

        public ItemController(ItemsDbContext itemsDbContext)
        {
            _itemsDbContext = itemsDbContext;
        }
Exemplo n.º 11
0
 public DbBuilder(ItemsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 12
0
 protected RepositoryBase(ItemsDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 13
0
 public CraftableRepository(ItemsDbContext context)
 {
     _context = context;
 }
Exemplo n.º 14
0
 public BondRepository(ItemsDbContext context)
 {
     _context = context;
 }