コード例 #1
0
            public void GetProductCategoryById_IncludeParent_Success()
            {
                // Arrange
                CreateTestData();

                // Act
                ProductCategory result;

                using (var context = new TinyShoppingCartDbContext(_options))
                {
                    context.Database.UseTransaction(_transaction);
                    var repository = new ProductCategoryRepository(context);

                    IQueryInclude queryObj = new QueryInclude {
                        IncludeProperties = "Parent"
                    };
                    result = repository.GetById(3, queryObj);
                }

                // Assert
                Assert.NotNull(result);
                Assert.Equal <int>(3, result.Id);
                Assert.True(result.Name == "Clothes");
                Assert.NotNull(result.Parent);
                Assert.Equal <string>("Men", result.Parent.Name);
            }
コード例 #2
0
            public void GetProductCategoryById_HaveTracking_Success()
            {
                // Arrange
                CreateTestData();

                // Act
                ProductCategory result;

                using (var context = new TinyShoppingCartDbContext(_options))
                {
                    context.Database.UseTransaction(_transaction);
                    var repository = new ProductCategoryRepository(context);

                    IQueryInclude queryObj = new QueryInclude {
                        IsTracking = true
                    };
                    result      = repository.GetById(3, queryObj);
                    result.Name = "Test";
                    context.SaveChanges();

                    result = repository.GetById(3, queryObj);
                }

                // Assert
                Assert.NotNull(result);
                Assert.Equal <int>(3, result.Id);
                Assert.True(result.Name == "Test");
                Assert.Null(result.Parent);
            }
コード例 #3
0
        public ProductCategoryRepositoryFixture()
        {
            string connectionString = string.Format("Data Source=TinyShoppingCartDB_ProductCategoryTests_{0}.db", Guid.NewGuid());

            Connection = new SqliteConnection(connectionString);
            Connection.Open();

            var builder = new DbContextOptionsBuilder <TinyShoppingCartDbContext>();

            builder.UseSqlite(Connection);

            ContextOptions = builder.Options;

            _context = new TinyShoppingCartDbContext(ContextOptions);
            _context.Database.EnsureCreated();
        }
コード例 #4
0
            private void CreateTestData()
            {
                using (var context = new TinyShoppingCartDbContext(_options))
                {
                    var dbSet = context.Set <ProductCategory>();
                    dbSet.Add(new ProductCategory {
                        Id = 1, Name = "Men"
                    });
                    dbSet.Add(new ProductCategory {
                        Id = 2, Name = "Women"
                    });
                    dbSet.Add(new ProductCategory {
                        Id = 3, Name = "Clothes", ParentId = 1
                    });

                    context.Database.UseTransaction(_transaction);
                    context.SaveChanges();
                }
            }
コード例 #5
0
            public void GetProductCategoryById_QueryObjectIsNull_Success()
            {
                // Arrange
                CreateTestData();

                // Act
                ProductCategory result;

                using (var context = new TinyShoppingCartDbContext(_options))
                {
                    context.Database.UseTransaction(_transaction);
                    var repository = new ProductCategoryRepository(context);
                    result = repository.GetById(3);
                }

                // Assert
                Assert.NotNull(result);
                Assert.Equal <int>(3, result.Id);
                Assert.True(result.Name == "Clothes");
                Assert.Null(result.Parent);
            }
コード例 #6
0
 public Repository(TinyShoppingCartDbContext dbContext) : base(dbContext)
 {
 }
コード例 #7
0
 public RepositoryWithTypedId(TinyShoppingCartDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = dbContext.Set <TEntity>();
 }
コード例 #8
0
 public UnitOfWork(TinyShoppingCartDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #9
0
 public ProductCategoryRepository(TinyShoppingCartDbContext dbContext) : base(dbContext)
 {
 }