/// <summary> /// Creates a task database in the given location, if a project database already exists, false is returned /// <para>Regardless of database creation, the datasource will be registered and available</para> /// </summary> /// <param name="projectName"></param> /// <param name="projectLocation"></param> public bool CreateProjectDatabase(string projectName, string projectLocation) { var databaseLocation = Path.Combine(projectLocation, $"{projectName}.{NULAH_DB_EXTENSION}"); var databaseCreated = _sqliteProvider.CreateOrRegisterDataSource(projectName, databaseLocation); // Track the new task list database in the application settings database if this is the first time we're creating it if (databaseCreated == true) { _sqliteProvider.CreateTable <Task>(projectName); // Create metadata _sqliteProvider.CreateTable <NulahDBMeta>(projectName); var nulahDBMetaPropertyList = NulahStandardLib.GetPropertiesForType <NulahDBMeta>(); var dbMetadata = new NulahDBMeta { IsProjectDatabase = true, ProjectName = projectName, ProjectOriginalLocation = projectLocation, TaskListName = projectName // TODO: Maybe add override to this later for project task lists? }; _sqliteProvider.Insert <NulahDBMeta>(projectName, $"INSERT INTO [{nameof(NulahDBMeta)}] ({string.Join(", ", nulahDBMetaPropertyList.Select(x => $"[{ x.Name}]"))}) VALUES ({string.Join(",", nulahDBMetaPropertyList.Select(x => $"@{x.Name}"))})", dbMetadata ); CreateDatabaseEntry(databaseLocation); } return(databaseCreated); }
public void Insert_OrderCrudOperation() { // Arrange var provider = new SqliteProvider(_context); // Act // Insert test order detail. provider.Insert(new Order { Latitude = Latitude, Longitude = Longitude, OrderTitle = OrderTitle, Status = Status }); // Fetch inserted order detail. var orders = provider.GetAll(); // Validate Assert.Equal(1, orders.Count); Assert.Equal(Latitude, orders.First().Latitude); Assert.Equal(Longitude, orders.First().Longitude); Assert.Equal(OrderTitle, orders.First().OrderTitle); Assert.Equal(Status, orders.First().Status); // Fetch Order var orders1 = provider.GetAll().First(); // Update Order var newOrder = new Order { Id = orders1.Id, Latitude = Latitude2, Longitude = Longitude2, Status = orders1.Status, OrderTitle = orders1.OrderTitle }; provider.Update(newOrder); // Fetching Updated Order var orders2 = provider.GetAll(); // Validate Assert.Equal(1, orders2.Count); Assert.Equal(Latitude2, orders2.First().Latitude); Assert.Equal(Longitude2, orders2.First().Longitude); Assert.Equal(OrderTitle, orders2.First().OrderTitle); Assert.Equal(Status, orders2.First().Status); // Remove Test Records foreach (var order in orders) { provider.Remove(order); } // Fetch order detail. var orders3 = provider.GetAll(); // Validate Assert.Equal(0, orders3.Count); }