static void Main(string[] args) { var myRootClass = new MyRootClass(); myRootClass.Increment(); Console.WriteLine(myRootClass.CountExceeded()); Console.ReadKey(); }
public void test_root_count_exceeded_false() { var mockChildClass = new Mock <IChildClass>(); mockChildClass.Setup(x => x.TotalNumbers()).Returns(1); var myObject = new MyRootClass(mockChildClass.Object); myObject.Increment(); Assert.AreEqual(false, myObject.CountExceeded()); }
public void SerializeDocument(string filename) { // Creates a new XmlSerializer. XmlSerializer s = new XmlSerializer(typeof(MyRootClass)); // Writing the file requires a StreamWriter. TextWriter myWriter = new StreamWriter(filename); // zkušební data // Creates an instance of the class to serialize. MyRootClass myRootClass = new MyRootClass(); /* Uses a basic method of creating an XML array: Create and * populate a string array, and assign it to the * MyStringArray property. */ string [] myString = { "Hello", "world", "!" }; myRootClass.MyStringArray = myString; /* Uses a more advanced method of creating an array: * create instances of the Item and BookItem, where BookItem * is derived from Item. */ Item item1 = new Item(); BookItem item2 = new BookItem(); // Sets the objects' properties. item1.ItemName = "Widget1"; item1.ItemCode = "w1"; item1.ItemPrice = 231; item1.ItemQuantity = 3; item2.ItemCode = "w2"; item2.ItemPrice = 123; item2.ItemQuantity = 7; item2.ISBN = "34982333"; item2.Title = "Book of Widgets"; item2.Author = "John Smith"; // Fills the array with the items. Item [] myItems = { item1, item2 }; // Sets the class's Items property to the array. myRootClass.Items = myItems; // konec zkušebních dat /* Serializes the class, writes it to disk, and closes * the TextWriter. */ s.Serialize(myWriter, myRootClass); myWriter.Close(); }
public void test_root_count_exceeded_true() { var mockChildClass = new Mock <IChildClass>(); mockChildClass.Setup(x => x.TotalNumbers()).Returns(12); IOCContainer.Instance.Clear(); IOCContainer.Instance.AddObject("IChildClass", mockChildClass.Object); var myObject = new MyRootClass(); myObject.Increment(); Assert.AreEqual(true, myObject.CountExceeded()); }
private async static Task <MyRootClass> GetCarddetails() { MyRootClass cardDetails = new MyRootClass { scheme = "visa", type = "debit", brand = "Visa/Dankort", prepaid = false, country = new Country { name = "CaD", currency = "DKK" }, bank = new Bank { name = "Jyske Bank", url = "www.jyskebank.dk", phone = "+4589893300", city = "Hjørring" } }; return(cardDetails); }
const int PagePoolSize = 32 * 1024 * 1024; // database cache size static public void Main(string[] args) { // get instance of the storage Storage db = StorageFactory.Instance.CreateStorage(); // open the database db.Open("simple.dbs", PagePoolSize); MyRootClass root = (MyRootClass)db.Root; // get storage root if (root == null) { // Root is not yet defined: stotage is not initialized root = new MyRootClass(db); // create root object db.Root = root; // register root object } // Create instance of the persistent capable class. // Created instance is not automatically stored in the database: Perst uses // "Persistence by reachability" apporach, which means that persistent capable class with // be automatically stored in the database when reference to it is assigned to some other // persistent object (including collections). MyPersistentClass obj = new MyPersistentClass(1, "A.B", "Hello world", MyEnum.First); // It is responsibility of programmer in Perst to maintain indices: add crearted object // to the proper indices, exclude it from the indices when key fields are changed or object // is deleted. root.intKeyIndex.Put(obj); // add object to index on intKey field root.strKeyIndex.Put(obj); // add object to index in strKey field // To explictiely specify value of the key it is necessary to create instance of // org.garret.perst.Key class which overloaded constructor will create key of correspondent type root.foreignIndex.Put(new Key(1001), obj); // Commit current transaction. It should not be done after insertion of each object since // transaction commit is expensibe operation and too frequent commits leans to bad performance. // It is preferrable to group sequence of logicaslly relation operations into one transaction db.Commit(); // Locate object by key. Since index is unique it is possible to use get method which returns // single object or null if object with such key is not found int intKeyVal = 1; #if USE_GENERICS obj = root.intKeyIndex[intKeyVal]; #else obj = (MyPersistentClass)root.intKeyIndex[intKeyVal]; #endif Console.WriteLine("Exact match search by intKey: " + obj); // Since strKeyIndex is not unique, it is necessary to user GenericIndex.get method which returns // array of objects. It takes minimal and maximal value of the key as parameters. // In case of strict match search, the same key should be specified as minimam and maximim string strKeyValue = "A.B"; #if USE_GENERICS MyPersistentClass[] result = root.strKeyIndex[strKeyValue, strKeyValue]; #else object[] result = root.strKeyIndex[strKeyValue, strKeyValue]; #endif for (int i = 0; i < result.Length; i++) { Console.WriteLine("Exact match search by strKey: " + result[i]); } // Get iterator through records belonging to specified key range in ascent order foreach (MyPersistentClass o in root.foreignIndex.Range( new Key(100, true), // inclusive low boundary new Key(10000, false), // exclusive high boundary IterationOrder.AscentOrder)) // ascent order { Console.WriteLine("Range search by foreign key: " + o); } // Locate all objects which strKey starts with prefix "A." foreach (MyPersistentClass o in root.strKeyIndex.StartsWith("A.")) { Console.WriteLine("Search by prefix: " + o); } // Locate all objects which strKey is prefix of "A.B.C" result = root.strKeyIndex.PrefixSearch("A.B.C"); for (int i = 0; i < result.Length; i++) { Console.WriteLine("Locate prefix: " + result[i]); } // To update object it is necessary first to exclude it from the index: root.intKeyIndex.Remove(obj); // ... then update the field obj.IntKey = 2; // ... and insert it in the index once again root.intKeyIndex.Put(obj); // When object is removed, it should be first excluded from all indices root.intKeyIndex.Remove(obj); // when object is removed from field index, it is not neccesary explicitely specify key root.strKeyIndex.Remove(obj); root.foreignIndex.Remove(1001, obj); // ... and here key has to be explicitely specified obj.Deallocate(); // explicit deallocation of object (Perst garbage collection can be used instead of explicit deallocation // Close the database db.Close(); }