Skip to content
Permalink
Browse files

更新单元测试

  • Loading branch information...
Kation committed Sep 24, 2017
1 parent 52d89dd commit bff477ccd5b78b1bfcb006e2d59533e83bc63ca6
Showing with 27 additions and 0 deletions.
  1. +23 −0 test/DataUnitTest/CURDTest.cs
  2. +4 −0 test/DataUnitTest/Category.cs
@@ -32,6 +32,29 @@ public async Task AddAndRemoveTest()
await database.SaveAsync();
Assert.Equal(0, await categoryContext.CountAsync(categoryContext.Query()));
});
await env.Run(async sp =>
{
var database = sp.GetService<IDatabaseContext>();
var categoryContext = database.GetContext<Category>();
Assert.Equal(0, await categoryContext.CountAsync(categoryContext.Query()));
var category = categoryContext.Create();
category.Name = "Parent";
categoryContext.Add(category);
await database.SaveAsync();
});
await env.Run(async sp =>
{
var database = sp.GetService<IDatabaseContext>();
var categoryContext = database.GetContext<Category>();
Assert.Equal(1, await categoryContext.CountAsync(categoryContext.Query()));
var parent = await categoryContext.Query().FirstOrDefaultAsync(t => t.Name == "Parent");
var category = categoryContext.Create();
category.Name = "Test";
category.Parent = parent;
categoryContext.Add(category);
await database.SaveAsync();
Assert.Equal(2, await categoryContext.CountAsync(categoryContext.Query()));
});
}

[Fact]
@@ -11,6 +11,10 @@ public class Category : EntityBase, ICategory
public virtual string Name { get; set; }

public virtual ICollection<User> Users { get; set; }

public Guid? ParentId { get; set; }
private Category _Parent;
public virtual Category Parent { get { return _Parent; } set { _Parent = value; ParentId = value?.Index; } }

ICollection<IUser> ICategory.Users
{

0 comments on commit bff477c

Please sign in to comment.
You can’t perform that action at this time.