public async Task Initialize() { Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; var schema = new DBSchema("common_database"); schema.Generate(new[] { typeof(Customer).Assembly, typeof(User).Assembly }); DBService.Schems.Add(schema); Assert.IsNotNull(schema); Assert.IsNotNull(Book.DBTable); Assert.IsNotNull(UserGroup.DBTable); Assert.IsNotNull(GroupPermission.DBTable); Assert.IsNotNull(User.DBTable); Assert.IsNotNull(Position.DBTable); Assert.IsNotNull(UserReg.DBTable); Assert.IsNotNull(Company.DBTable); DBService.Save(); schema.Connection = new DBConnection { Name = "test.common", System = DBSystem.SQLite, DataBase = "test.common" }; schema.DropDatabase(); schema.CreateDatabase(); var group = new UserGroup() { Number = "GP1", Name = "Group1" }; await group.Save(); var position = new Position() { Code = "PS1", Name = "Position" }; var user = new User() { Login = "******", Name = "Test User", Password = "******", Position = position, AuthType = UserAuthType.Internal, Access = new AccessValue(new[] { new AccessItem(group, AccessType.Create) }) }; await user.Save(); await User.StartSession("test", "UserCommon1!"); await GroupPermission.CachePermission(); }
private void ToolDBGenerateClick(object sender, EventArgs e) { var assemblyList = new SelectableList <AsseblyCheck>(); string[] asseblies = Directory.GetFiles(Helper.GetDirectory(), "*.dll"); foreach (string dll in asseblies) { AssemblyDefinition assemblyDefinition = null; try { assemblyDefinition = AssemblyDefinition.ReadAssembly(dll); } catch { continue; } var moduleAttribute = assemblyDefinition.CustomAttributes .Where(item => item.AttributeType.Name == nameof(AssemblyMetadataAttribute)) .Select(item => item.ConstructorArguments.Select(sitem => sitem.Value.ToString()) .ToArray()); if (moduleAttribute.Any(item => item[0] == "module")) { assemblyList.Add(new AsseblyCheck(Assembly.LoadFile(dll))); } } var list = new LayoutList { AllowCheck = true, CheckRecursive = true, AutoToStringFill = true, GenerateToString = true, GenerateColumns = false, ListSource = assemblyList }; var window = new ToolWindow { Title = "Select Assembly", Target = list }; window.Show(this, Point.Zero); window.ButtonAcceptClick += (s, a) => { var schema = new DBSchema("NewSchema"); schema.Generate(assemblyList.Where(p => p.Check).Select(p => p.Assembly)); DBService.Schems.Add(schema); ShowNewItem(schema); }; }
private async void ORMTestClick(object sender, EventArgs e) { var list = new DataExplorer(); dock.Put(list); await Task.Run(() => { var schema = DBSchema.Generate(typeof(User).Assembly, "common_data"); schema.Connection = new DBConnection { Name = "test.common", System = DBSystem.SQLite, DataBase = "test.common.sqlite" }; schema.DropDatabase(); schema.CreateDatabase(); }).ConfigureAwait(false); }
public void SchemaSerialization() { var schem = DBSchema.Generate(GetType().Assembly, SchemaName); var file = "data.xml"; Serialization.Serialize(DBService.Schems, file); DBService.Schems.Clear(); Serialization.Deserialize(file, DBService.Schems); Assert.AreEqual(2, DBService.Schems.Count); Assert.AreEqual(2, schem.Tables.Count); var table = schem.Tables[EmployerTableName]; Assert.IsNotNull(table); Assert.IsInstanceOf <DBTable <Employer> >(table); var column = table.Columns["id"]; Assert.IsNotNull(column); Assert.AreEqual(typeof(int), column.DataType); }
public async void Generate(DBConnection connection) { Assert.AreEqual(true, connection.CheckConnection(), $"Connection Fail!"); schema = DBSchema.Generate(GetType().Assembly, SchemaName); Assert.IsNotNull(schema, "Attribute Generator Fail. On Schema"); Assert.IsNotNull(Employer.DBTable, "Attribute Generator Fail. On Employer Table"); Assert.IsNotNull(Position.DBTable, "Attribute Generator Fail. On Position Table"); var idColumn = Employer.DBTable.Columns["id"]; Assert.IsNotNull(idColumn, "Attribute Generator Fail. On Column Employer Id"); var positionColumn = Employer.DBTable.Columns["positionid"]; Assert.IsNotNull(positionColumn, "Attribute Generator Fail. On Column Employer Position"); Assert.IsNotNull(positionColumn.ReferenceTable, "Attribute Generator Fail. On Column Employer Position Reference"); schema.Connection = connection; schema.DropDatabase(); schema.CreateDatabase(); var result = schema.GetTablesInfo(connection.Schema, EmployerTableName); Assert.IsTrue(result.Count() == 1, "Generate Sql Table / Get Information Fail."); result = schema.GetTablesInfo(connection.Schema, PositionTableName); Assert.IsTrue(result.Count() == 1, "Generate Sql Table / Get Information Fail."); //Insert var employer = new Employer() { Identifier = $"{1:8}", Lodar = true, Age = 40, Height = 180, LongId = 120321312321L, Weight = 123.12333F, DWeight = 123.1233433424434D, Salary = 231323.32M, Name = "Ivan", Access = new AccessValue(new[] { new AccessItem(AccessValue.Groups.First(i => i.Id == 1), AccessType.Read), new AccessItem(AccessValue.Groups.First(i => i.Id == 2), AccessType.Admin), new AccessItem(AccessValue.Groups.First(i => i.Id == 3), AccessType.Create) }) }; Assert.AreEqual(employer.Type, EmployerType.Type2, "Default Value & Enum"); employer.GenerateId(); Assert.NotNull(employer.Id, "Id Generator Fail"); await employer.Save(); var qresult = schema.Connection.ExecuteQResult($"select * from {EmployerTableName}"); Assert.AreEqual(1, qresult.Values.Count, "Insert sql Fail"); Assert.AreEqual(employer.Id, qresult.Get(0, "id"), "Insert sql Fail Int"); Assert.AreEqual(employer.Identifier, qresult.Get(0, "identifier"), "Insert sql Fail String"); Assert.AreEqual((int?)employer.Type, qresult.Get(0, "typeid"), "Insert sql Fail Enum"); Assert.AreEqual(employer.Age, qresult.Get(0, "age"), "Insert sql Fail Byte"); Assert.AreEqual(employer.Height, qresult.Get(0, "height"), "Insert sql Fail Short"); Assert.AreEqual(employer.LongId, qresult.Get(0, "longid"), "Insert sql Fail Long"); Assert.AreEqual(employer.Weight, qresult.Get(0, "weight"), "Insert sql Fail Float"); Assert.AreEqual(employer.DWeight, qresult.Get(0, "dweight"), "Insert sql Fail Double"); Assert.AreEqual(employer.Salary, qresult.Get(0, "salary"), "Insert sql Fail Decimal"); var lodar = qresult.Get(0, "lodar").ToString(); Assert.IsTrue(lodar == "1" || lodar == "True", "Insert sql Fail Bool"); Assert.IsInstanceOf <byte[]>(qresult.Get(0, "group_access"), "Insert sql Fail Byte Array"); var accessValue = new AccessValue((byte[])qresult.Get(0, "group_access")); Assert.AreEqual(3, accessValue.Items.Count(), "Insert sql Fail Byte Array"); Assert.AreEqual(true, accessValue.Items.ElementAt(0).Read, "Insert sql Fail Byte Array"); Assert.AreEqual(true, accessValue.Items.ElementAt(1).Admin, "Insert sql Fail Byte Array"); Assert.AreEqual(false, accessValue.Items.ElementAt(2).Delete, "Insert sql Fail Byte Array"); Employer.DBTable.Clear(); Assert.AreEqual(0, Employer.DBTable.Count, "Clear table Fail"); //Insert Several Position.DBTable.Add(new Position() { Code = "1", Name = "First Position" }); Position.DBTable.Add(new Position() { Code = "2", Name = "Second Position" }); var position = new Position() { Id = 0, Code = "3", Name = "Group Position" }; position.Attach(); var sposition = new Position() { Code = "4", Parent = position, Name = "Sub Group Position" }; sposition.Attach(); //Select from internal Index Position.DBTable.Add(new Position() { Code = "t1", Name = "Null Index" }); Position.DBTable.Add(new Position() { Code = "t2", Name = "Null Index" }); Position.DBTable.Add(new Position() { Code = "t3", Name = "Null Index" }); var nullIds = Position.DBTable.Select(Position.DBTable.PrimaryKey, CompareType.Is, null).ToList(); Assert.AreEqual(6, nullIds.Count, "Select by null Fail"); await Position.DBTable.Save(); Position.DBTable.Clear(); var positions = Position.DBTable.Load(); Assert.AreEqual(7, positions.Count(), "Insert/Read several Fail"); //GetById employer = Employer.DBTable.LoadById(1); Assert.IsNotNull(employer, "GetById Fail"); position = Position.DBTable.LoadById(4); Assert.IsNotNull(position, "GetById Fail"); //Update employer.Position = position; await employer.Save(); qresult = schema.Connection.ExecuteQResult($"select * from {EmployerTableName}"); Assert.AreEqual(4, qresult.Get(0, "positionid"), "Update sql Fail"); connection.ExecuteQuery(@"create table test_table( id int primary key, test_date date, test_varchar varchar(512), test_numeric numeric(20,10))"); result = schema.GetTablesInfo(connection.Schema, "test_table"); schema.GenerateTablesInfo(result); var table = schema.Tables["test_table"] as DBTable <DBItem>; Assert.IsNotNull(table, "DBInformation Load Fail"); table.Load().LastOrDefault(); for (int i = 0; i < 1000; i++) { var row = table.NewItem(); row["id"] = i; row["test_date"] = DateTime.Now.AddDays(-i); row["test_varchar"] = "string value " + i; row["test_numeric"] = i / 1000M; table.Add(row); } await table.Save(); table.Clear(); int c = 0; foreach (var item in table.Load(string.Empty)) { if (++c == 5) { break; } } }
public async Task Initialize() { Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; var schema = new DBSchema("wf_customer"); schema.Generate(new[] { typeof(User).Assembly, typeof(Customer).Assembly }); Assert.IsNotNull(Location.DBTable); Assert.IsNotNull(Address.DBTable); Assert.IsNotNull(Customer.DBTable); Assert.IsNotNull(CustomerAddress.DBTable); Assert.IsNotNull(PersoneIdentify.DBTable); Assert.IsNotNull(CustomerReference.DBTable); DBService.Save(); schema.Connection = new DBConnection { Name = "test.common", DataBase = "test.common", System = DBSystem.SQLite }; schema.DropDatabase(); schema.CreateDatabase(); Location.DBTable.Add(new Continent { Code = "AF", Name = "Africa" }); Location.DBTable.Add(new Continent { Code = "AN", Name = "Antarctica" }); Location.DBTable.Add(new Continent { Code = "AS", Name = "Asia" }); Location.DBTable.Add(new Continent { Code = "EU", Name = "Europa" }); Location.DBTable.Add(new Continent { Code = "EUAS", Name = "Eurasia" }); Location.DBTable.Add(new Continent { Code = "NA", Name = "North america" }); Location.DBTable.Add(new Continent { Code = "OC", Name = "Oceania" }); Location.DBTable.Add(new Continent { Code = "SA", Name = "South america" }); var russia = new Country { Parent = Location.DBTable.LoadByCode("EUAS"), Code = "RU", Name = "Russia" }; Location.DBTable.Add(russia); var ruble = new Currency { Parent = russia, Code = "RUB", Name = "Ruble" }; Location.DBTable.Add(ruble); Assert.AreEqual(1, DBTable.GetTable <Country>().Count); Assert.AreEqual(1, DBTable.GetTable <Currency>().Count); await Location.DBTable.Save(); Assert.AreEqual(1, DBTable.GetTable <Country>().Count); Assert.AreEqual(1, DBTable.GetTable <Currency>().Count); Location.DBTable.Clear(); Location.DBTable.Load().LastOrDefault(); Assert.AreEqual(1, DBTable.GetTable <Country>().Count); Assert.AreEqual(1, DBTable.GetTable <Currency>().Count); }