コード例 #1
0
        public LightLoanDbContextTest()
        {
            dateTime             = new DateTime(3001, 1, 1);
            _datetimeServiceMock = new Mock <IDatetimeService>();
            _datetimeServiceMock.Setup(m => m.Now).Returns(dateTime);

            userId           = Guid.NewGuid();
            _userServiceMock = new Mock <IUserService>();
            _userServiceMock.Setup(m => m.UserId).Returns(userId);

            var options = new DbContextOptionsBuilder <LightLoanDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            _dbContext = new LightLoanDbContext(_userServiceMock.Object, _datetimeServiceMock.Object, options);

            testId = Guid.NewGuid();
            Branch branch = new Branch {
                Id      = testId, Name = "Test Branch For Change",
                Address = new Address {
                    Id      = 1,
                    Line1   = "Line1 Test",
                    Line2   = "Line2 Test",
                    City    = "City Test",
                    Country = "Country Test",
                    Status  = (char)Domain.Enums.Status.New
                },
                Phone1     = "Test Phone 1", Phone2 = "Test Phone 2",
                HashValue1 = "Test Hash value 1", HashValue2 = "Test Hash value 2"
            };

            _dbContext.Branches.Add(branch);
            _dbContext.SaveChanges();
        }
コード例 #2
0
        public static LightLoanDbContext Create()
        {
            var dateTime             = new DateTime(3001, 1, 1);
            var _datetimeServiceMock = new Mock <IDatetimeService>();

            _datetimeServiceMock.Setup(m => m.Now).Returns(dateTime);

            var userId           = Guid.NewGuid();
            var _userServiceMock = new Mock <IUserService>();

            _userServiceMock.Setup(m => m.UserId).Returns(userId);

            var options = new DbContextOptionsBuilder <LightLoanDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            var _dbContext = new LightLoanDbContext(_userServiceMock.Object, _datetimeServiceMock.Object, options);

            _dbContext.Database.EnsureCreated();

            return(_dbContext);
        }
コード例 #3
0
 public static void Destroy(LightLoanDbContext dbContext)
 {
     dbContext.Database.EnsureDeleted();
     dbContext.Dispose();
 }
コード例 #4
0
 public CommandTestBase()
 {
     _dbContext = LightLoanDbContextFactory.Create();
 }