예제 #1
0
        /// <summary>
        /// Might not actually need this?
        /// </summary>
        /// <param name="args"></param>
        private static void RunMigration(string[] args)
        {
            if (args.Any(_ => _.ToLower().StartsWith(Constants.MigrationUtility.ConnectionStringArg)))
            {
                var arg = args.First(_ => _.ToLower().StartsWith(Constants.MigrationUtility.ConnectionStringArg));
                var connectionString = arg.Replace("--connection-string=", string.Empty);

                var context = new MyBeerCellarContext(connectionString);

                try
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Applying migrations...");
                    context.Database.Migrate();
                    Console.WriteLine("Migrations applied successfully");
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Exception caught while applying migrations:");
                    Console.WriteLine();
                    Console.WriteLine(e);
                    Console.ResetColor();
                    throw;
                }
            }
        }
예제 #2
0
        protected BaseContextUnitTest()
        {
            // Hopefully using new guid in the db name will eliminate the inconsistent test failures :\
            var builder = new DbContextOptionsBuilder <MyBeerCellarContext>()
                          .UseInMemoryDatabase($"MyBeerCellar{Guid.NewGuid()}");

            Context = new MyBeerCellarContext(builder.Options);
        }
예제 #3
0
        public void Constructor_Should_Throw_ArgumentNullException_When_Context_Is_Null()
        {
            // Arrange
            MyBeerCellarContext context = null;
            Action ctor = () => new CellarItemController(context,
                                                         _mockMapper.Object);

            // Act + Assert
            ctor.Should()
            .Throw <ArgumentNullException>();
        }
 public BeerStyleController(MyBeerCellarContext context, IMapper mapper)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _mapper  = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }