Skip to content

Commit

Permalink
框架:转换long主键 test与其他
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyuyang committed Nov 26, 2013
1 parent 138b508 commit e1c051f
Show file tree
Hide file tree
Showing 19 changed files with 563 additions and 24 deletions.
4 changes: 2 additions & 2 deletions wojilu.Installer/InstallerController.cs
Expand Up @@ -142,7 +142,7 @@ public class InstallerController : ControllerBase {
updateSiteName( siteName );

// 5)安装app
int siteType = ctx.PostLong( "siteType" );
int siteType = ctx.PostInt( "siteType" );
initSiteApp( siteType, user );

echoAjaxOk();
Expand Down Expand Up @@ -410,7 +410,7 @@ public class InstallerController : ControllerBase {
return str;
}
catch (Exception ex) {
errors.Add( ex.Message );
errors.Add( ex.Message + " 请检查用户名或密码是否正确。" );
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion wojilu.Installer/Installers/HtmlInstallerHelper.cs
Expand Up @@ -69,7 +69,7 @@ public class HtmlInstallerHelper {
// 初始化当前app
private ContentApp initApp( MvcContext ctx, IMemberApp mapp ) {
IAppContext context = new AppContext();
int appId = mapp.AppOid;
long appId = mapp.AppOid;
context.Id = appId;

ContentApp app = ContentApp.findById( appId );
Expand Down
4 changes: 2 additions & 2 deletions wojilu.Test/Common/TreeTest.cs
Expand Up @@ -150,9 +150,9 @@ public class TreeTest {


public class Node : INode {
public int Id { get; set; }
public long Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
public long ParentId { get; set; }

public string Title {
get { return this.Name + this.Id + "....."; }
Expand Down
23 changes: 23 additions & 0 deletions wojilu.Test/Common/cvtTest.cs
Expand Up @@ -98,6 +98,29 @@ public class cvtTest {

}

[Test]
public void testLong()
{
// Int64.MaxValue=9223 37203 68547 75807

Assert.IsTrue( cvt.IsLong( "235" ) );
Assert.IsTrue( cvt.IsLong( "0" ) );
Assert.IsTrue( cvt.IsLong( "-235" ) );
Assert.IsFalse( cvt.IsLong( "fdd" ) );

Assert.IsTrue( cvt.IsLong( "354656982" ) );
Assert.IsTrue( cvt.IsLong( "-1354656982" ) );

Int64 maxValue = 9223372036854775807;
Assert.IsTrue( cvt.IsLong( maxValue.ToString() ) );
Assert.IsFalse( cvt.IsLong( "19223372036854775807" ) );

String idStr = "66677854129116241";
long[] ids = cvt.ToLongArray( idStr );
Assert.AreEqual( 1, ids.Length );
Assert.AreEqual( 66677854129116241, ids[0] );
}

[Test]
public void testToString() {

Expand Down
61 changes: 61 additions & 0 deletions wojilu.Test/Data/Entities.cs
Expand Up @@ -97,4 +97,65 @@ public class TProperty : CacheObject {

}


//--------------------------------------------------------

public class Book : CacheObject {
public string Weather { get; set; }
}


public class MenuMock : CacheObject, IComparable, INode {

//public User Creator { get; set; }
public String Creator { get; set; }

public int OrderId { get; set; }

[NotSave]
public int OwnerId {
get { return 0; }
set { }
}

[NotSave]
public String OwnerUrl {
get { return ""; }
set { }
}

[NotSave]
public String OwnerType {
get { return "site"; }
set { }
}

public long ParentId { get; set; }
public String RawUrl { get; set; }
public String Url { get; set; }

public String Style { get; set; }

public DateTime Created { get; set; }
public int OpenNewWindow { get; set; }


public int CompareTo( object obj ) {

MenuMock menu = obj as MenuMock;

if (OrderId > menu.OrderId) return -1;
if (OrderId < menu.OrderId) return 1;
if (base.Id > menu.Id) return 1;
if (base.Id < menu.Id) return -1;
return 0;
}

public void updateOrderId() {
this.update();
}

}


}
213 changes: 213 additions & 0 deletions wojilu.Test/Data/MemoryDBGeneric.cs
@@ -0,0 +1,213 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace wojilu.Test.Data {


[TestFixture]
public class MemoryDBGeneric {





[Test]
public void testFindById() {
Book book = cdb.findById<Book>( 5 );
Assert.IsNotNull( book );
Assert.AreEqual( "zhangsan5", book.Name );

Book nullBook = cdb.findById<Book>( 999999999 );
Assert.IsNull( nullBook );
}

[Test]
public void testFindAll() {

IList<Book> list = cdb.findAll<Book>();
Assert.AreEqual( 10, list.Count );
}

// 每次FindAll 得到的,都是缓存的副本,
// 并且 book.Delete() 只是移除缓存中的数据,对当前的副本(集合)并无影响
[Test]
public void testDeleteAll() {

IList<Book> all = cdb.findAll<Book>();

foreach (Book book in all) {
cdb.delete( book );
}

int result = cdb.findAll<Book>().Count;

Assert.AreEqual( result, 0 );
}

// 随机删除
[Test]
public void testDelete() {
Random rd = new Random();

for (int i = 0; i < 20; i++) {
int id = rd.Next( 1, 11 );
Console.WriteLine( "随机ID:" + id );
Book book = cdb.findById<Book>( id );
if (book != null) {
cdb.delete( book );
Console.WriteLine( "删除:" + id );
}
}

}

[Test]
public void testDelete3() {

IList<Book> all = cdb.findAll<Book>();
Assert.AreEqual( 10, all.Count );

int deleteCount = 0;
int bookCount = all.Count;
for (int i = 0; i < bookCount; i++) {
cdb.delete( all[i] );
deleteCount++;
}

Assert.AreEqual( bookCount, deleteCount );

IList<Book> results = cdb.findAll<Book>();
Assert.AreEqual( 0, results.Count );
}


// findBy (index test)
//----------------------------------------------------------------------------------------------

[Test]
public void testFindBy() {

IList<Book> books = cdb.findBy<Book>( "Name", "zhangsan5" );
Assert.AreEqual( 1, books.Count );
Book book = books[0];
Assert.AreEqual( "hao10", book.Weather );

IList<Book> books2 = cdb.findBy<Book>( "Weather", "hao10" );
Assert.AreEqual( 1, books2.Count );
Book book2 = books2[0];
Assert.AreEqual( "zhangsan5", book2.Name );
}

[Test]
public void testFindBy_Insert() {

Book newBook = new Book {
Name = "zhangsan5",
Weather = "hao6"
};
cdb.insert( newBook );

IList<Book> newBooks = cdb.findBy<Book>( "Name", "zhangsan5" );
Assert.AreEqual( 2, newBooks.Count );
Assert.AreEqual( "hao6", newBooks[1].Weather );

IList<Book> newBooks2 = cdb.findBy<Book>( "Weather", "hao6" );
Assert.AreEqual( 2, newBooks2.Count );
Assert.AreEqual( "zhangsan5", newBooks2[1].Name );

}

[Test]
public void testFindBy_Update() {

IList<Book> books = cdb.findBy<Book>( "Name", "zhangsan5" );
Assert.AreEqual( 1, books.Count );
Book book = books[0];

book.Name = "zhangsan8";
cdb.update( book );

IList<Book> newBooks = cdb.findBy<Book>( "Name", "zhangsan5" );
Assert.AreEqual( 0, newBooks.Count );

IList<Book> newBooks2 = cdb.findBy<Book>( "Name", "zhangsan8" );
Assert.AreEqual( 2, newBooks2.Count );
}

[Test]
public void testFindBy_Delete() {

IList<Book> books = cdb.findBy<Book>( "Name", "zhangsan5" );
Assert.AreEqual( 1, books.Count );
Book book = books[0];

cdb.delete( book );

IList<Book> newBooks = cdb.findBy<Book>( "Name", "zhangsan5" );
Assert.AreEqual( 0, newBooks.Count );

int allCount = cdb.findAll<Book>().Count;
Assert.AreEqual( 9, allCount );

}

[SetUp]
public void initData() {
Console.WriteLine( "------------------------------init data-------------------------------" );
for (int i = 0; i < 10; i++) {
Book book = new Book();
book.Name = "zhangsan" + (i + 1);
book.Weather = "hao" + ((i + 1) * 2);
cdb.insert( book );
}
}

[TearDown]
public void deleteAll() {
IList<Book> all = cdb.findAll<Book>();

foreach (Book book in all) {
cdb.delete( book );
}

}


[Test]
public void testMenuParentId() {

List<MenuMock> oldList = cdb.findAll<MenuMock>();
foreach (MenuMock menuMock in oldList) {
menuMock.delete();
}

for (int i = 0; i < 20; i++) {
MenuMock menu = new MenuMock();
menu.Name = "menu" + i;
menu.insert();
}


for (int i = 0; i < 20; i++) {
MenuMock menu = new MenuMock();
menu.Name = "menu" + i;
menu.ParentId = i + 1;
menu.insert();
}


List<MenuMock> list = cdb.findAll<MenuMock>();
Assert.AreEqual( 40, list.Count );

Tree<MenuMock> _tree = new Tree<MenuMock>( list );
var children = _tree.FindChildren( 3 );
Assert.AreEqual( 1, children.Count );
Assert.AreEqual( 23, children[0].getNode().Id );

}

}
}

0 comments on commit e1c051f

Please sign in to comment.