コード例 #1
0
 private void Seed()
 {
     //Seed our DB with this method
     //example of using block
     using (var context = new Entity.wssdbContext(options))
     {
         //this makes sure that the state of the db gets recreated each time to maintain the modularity of the test
         context.Database.EnsureDeleted();
         context.Database.EnsureCreated();
         context.Customers.AddRange
         (
             new Entity.Customer {
             Id    = 1,
             CName = "Auryn"
         },
             new Entity.Customer {
             Id    = 2,
             CName = "Melix"
         },
             new Entity.Customer {
             Id    = 3,
             CName = "Roaringsheep"
         }
         );
         context.SaveChanges();
     }
 }
コード例 #2
0
        public void GetAllCustomersShouldReturnAllCustomers()
        {
            using (var context = new Entity.wssdbContext(options))
            {
                //Arrange the test context
                CustomerRepoDB _repo = new CustomerRepoDB(context, mapper);

                //Act
                var customers = _repo.GetAllCustomers();
                //Assert
                Assert.Equal(3, customers.Count);
            }
        }
コード例 #3
0
 public void AddCustomerShouldAddCustomer()
 {
     using (var context = new Entity.wssdbContext(options))
     {
         CustomerRepoDB _repo = new CustomerRepoDB(context, mapper);
         //Act with a test context
         _repo.AddNewCustomer
         (
             new Model.Customer("Test User")
         );
     }
     //use a diff context to check if changes persist to db
     using (var assertContext = new Entity.wssdbContext(options))
     {
         //Assert with a different context
         var result = assertContext.Customers.FirstOrDefault(cust => cust.Id == 4);
         Assert.NotNull(result);
         Assert.Equal("Test User", result.CName);
     }
 }
コード例 #4
0
 public ProductRepoDB(Entity.wssdbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
コード例 #5
0
 public CustomerRepoDB(Entity.wssdbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
コード例 #6
0
 public LocationRepoDB(Entity.wssdbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }