public async Task ReturnCorrectAmount()
        {
            // setup in-memory database
            var dbContextOptions = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <VmDbContext>().UseInMemoryDatabase("VMDB");
            var dbContext        = new VmDbContext(dbContextOptions.Options);

            // seed some data
            DataSeedingHelper.Seed(dbContext);

            var service = new VendingMachineService(dbContext);
            var product = (await service.GetProductsAsync()).First();

            var change   = new Dictionary <decimal, int>();
            var payCoins = new Dictionary <decimal, int>();

            payCoins.Add(0.1m, 5);
            payCoins.Add(1.0m, 2);

            var ok = await service.PurchaseAsync(product.Id, payCoins, change);

            Assert.True(ok);

            var changeSum = change.ToList().Sum(x => x.Key * x.Value);
            var paiedSum  = payCoins.ToList().Sum(x => x.Key * x.Value);

            Assert.Equal(changeSum, paiedSum - product.Price);
        }
Ejemplo n.º 2
0
        public MaisCadastrosContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <MaisCadastrosContext>();

            optionsBuilder.UseSqlServer(@"Data Source=(localdb)\\MSSQLLocalDB;Integrated Security=True; MultipleActiveResultSets=True;");

            return(new MaisCadastrosContext(optionsBuilder.Options));
        }
Ejemplo n.º 3
0
        protected ApplicationDbContext GetDbContext()
        {
            var options = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            return(new ApplicationDbContext(options));
        }
Ejemplo n.º 4
0
        public AssetContext CreateDbContext(string[] args)
        {
            var builder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <AssetContext>();

            var connectionString = @"Data Source=SQLAPP;Initial Catalog=Asset;Trusted_Connection=True;";

            builder.UseSqlServer(connectionString);

            return(new AssetContext(builder.Options));
        }
Ejemplo n.º 5
0
        public BaseController()
        {
            var connection = @"Server=BUSWGVMINDEV3\MSSQLSERVER12;Database=RoomPlannerDev;User Id=roomplanner;Password=roomplanner123";

            var builder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <RoomPlannerDevContext>();

            builder.UseSqlServer(connection);

            Context = new RoomPlannerDevContext(builder.Options);
        }
Ejemplo n.º 6
0
        public DataContext CreateDbContext(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
                                               .SetBasePath(System.IO.Directory.GetCurrentDirectory())
                                               .AddJsonFile("appsettings.json")
                                               .Build();
            var builder          = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <DataContext>();
            var connectionString = configuration.GetConnectionString("StoreConnectionString");

            builder.UseSqlServer(connectionString);
            return(new DataContext(builder.Options));
        }
Ejemplo n.º 7
0
        private EposDbContext GetWasteDbContext()
        {
            var options = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <EposDbContext>();

            options.UseSqlServer(
                this.connectionString,
                options =>
            {
                options.CommandTimeout(20);     // secs
            });

            return(new EposDbContext(options.Options));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Constrcuts a new instance of a data repository
        /// </summary>
        /// <param name="context"></param>
        public DataRepository(DatabaseContext context, IAuthenticationService authService, IConfiguration config)
        {
            this._db = context;

            //Multitenancy Implimentation
            var tenant = authService.GetTenantName();

            if (!String.IsNullOrEmpty(tenant))
            {
                //use other conn string
                var optionsBuilder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlServer(config.GetConnectionString(tenant));
                _db = new DatabaseContext(optionsBuilder.Options);
            }
        }
Ejemplo n.º 9
0
        public static Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext> TestDbContextOptions()
        {
            // Create a new service provider to create a new in-memory database.
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            // Create a new options instance using an in-memory database and
            // IServiceProvider that the context should resolve all of its
            // services from.
            var builder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("LMS_Zenith")
                          .UseInternalServiceProvider(serviceProvider);

            return(builder.Options);
        }
        public static Microsoft.EntityFrameworkCore.DbContextOptions <DbContext> CreateNewContextOptions()
        {
            // Create a fresh service provider, and therefore a fresh
            // InMemory database instance.
            var serviceProvider = new Microsoft.Extensions.DependencyInjection.ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            // Create a new options instance telling the context to use an
            // InMemory database and the new service provider.
            var builder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <DbContext>();

            builder.UseInMemoryDatabase()
            .UseInternalServiceProvider(serviceProvider);

            return(builder.Options);
        }
Ejemplo n.º 11
0
        public void Setup()
        {
            SqliteCommand    sqlite_cmd;
            SqliteConnection sqlite_conn = new SqliteConnection(@"Data Source=../../../database/phonebook.db");

            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();

            sqlite_cmd.CommandText = "DROP Table 'phonebook_entries'";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = "DROP Table 'entry'";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = "DROP Table 'phonebook'";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = "DROP Table 'user'";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = @"CREATE TABLE 'entry' (
                    'Id'  INTEGER PRIMARY KEY AUTOINCREMENT,
                    'Name'   TEXT NOT NULL,
                    'PhoneNumber'  TEXT NOT NULL
                    )";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = @"CREATE TABLE 'user' (
                        'Id'  INTEGER PRIMARY KEY AUTOINCREMENT,
                        'Username'  TEXT NOT NULL UNIQUE,
                        'Password'  TEXT NOT NULL,
                        'created_date' TEXT NOT NULL,
                        'Name'   TEXT NOT NULL
                        )";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = @"CREATE TABLE 'phonebook' (
                        'Id'  INTEGER PRIMARY KEY AUTOINCREMENT,
                        'Name'   TEXT NOT NULL,
                        'UserId' INTEGER NOT NULL,
                        FOREIGN KEY('UserId') REFERENCES 'user'('Id')
                        )";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_cmd.CommandText = @"CREATE TABLE 'phonebook_entries' (
                        'phonebook_id' INTEGER NOT NULL,
                        'entry_id'  INTEGER NOT NULL,
                        FOREIGN KEY('phonebook_id') REFERENCES 'phonebook'('Id'),
                        PRIMARY KEY('phonebook_id','entry_id'),
                        FOREIGN KEY('entry_id') REFERENCES 'entry'('Id')
                        )";
            sqlite_cmd.ExecuteNonQuery();

            sqlite_conn.Close();

            var optionsBuilder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <PhonebookContext>();

            optionsBuilder.UseSqlite("Data Source=../../../database/phonebook.db");
            dbContext = new PhonebookContext(optionsBuilder.Options);


            repo      = new PhonebookRepository(dbContext);
            auth_repo = new AuthenticationRepository(dbContext);
        }