Source

mongo-dart / tests / objectory / PersistentObjectTest.dart

#library("PersistenObjectTests");
#import("../../lib/objectory/ObjectoryLib_vm.dart");
#import("../../lib/bson/bson.dart");
#import('../../../../dart/dart-sdk/lib/unittest/unittest.dart');
#source("DomainModel.dart");
testAuthorCreation(){
  Author author = new Author();
  author.name = 'vadim';
  author.age = 99;
  author.email = 'sdf';
  expect(author.getKeys()[0]).equals("_id");
  expect(author.getKeys()[1]).equals("name");
  expect(author.getKeys()[2]).equals("age");
  expect(author.getKeys().last()).equals("email");
  expect(author.getKeys().length).equals(4);
  expect(author.name).equals('VADIM'); // converted to uppercase by custom  setter;
}

testSetDirty(){
  Author author = new Author();
  author.name = "Vadim";
  expect(author.dirtyFields.length).equals(1);
  expect(author.isDirty()).isTrue();  
}
testCompoundObject(){
  Person person = new Person();  
  person.address.cityName = 'Tyumen';
  person.address.streetName = 'Elm';  
  person.firstName = 'Dick';
  Map map = person.map;
  expect(map["address"]["streetName"]).equals("Elm");
  expect(person.address.parent).equals(person);
  expect(person.address.pathToMe).equals("address");
  expect(person.isDirty()).isTrue();
  expect(person.address.isDirty()).isTrue();
}
testFailOnSettingUnsavedLinkObject(){
  Person son = new Person();  
  Person father = new Person();  
  ;
  Expect.throws(()=>son.father = father,reason:"Link object must be saved (have ObjectId)");
}  
testFailOnAbsentProperty(){
  IAuthor author = new Author();
  Expect.throws(()=>author.sdfsdfsdfgdfgdf,reason:"Must fail on missing property getter");
}

main(){
  registerClasses();  
  group("PersistenObjectTests", ()  {
    test("testAuthorCreation",testAuthorCreation);
    test("testSetDirty",testSetDirty);
    test("testCompoundObject",testCompoundObject);
    test("testFailOnAbsentProperty",testFailOnAbsentProperty);
    test("testFailOnSettingUnsavedLinkObject",testFailOnSettingUnsavedLinkObject);    
  });  

}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.