Ejemplo n.º 1
0
        public async Task CreateTableObjectShouldSaveTheTableObjectInTheDatabaseAndReturnTheId()
        {
            // Arrange
            SQLiteConnection database = new SQLiteConnection(databasePath);
            int  tableId = 4;
            Guid uuid    = Guid.NewGuid();

            var tableObjectData = new TableObjectData
            {
                table_id = tableId,
                uuid     = uuid,
                file     = false
            };
            var tableObject = tableObjectData.ToTableObject();

            // Act
            await Dav.Database.CreateTableObjectAsync(tableObject);

            // Assert
            var tableObjectFromDatabase = database.Get <TableObject>(tableObject.Id);

            Assert.AreEqual(tableId, tableObjectFromDatabase.TableId);
            Assert.AreEqual(tableObject.Id, tableObjectFromDatabase.Id);
            Assert.AreEqual(uuid, tableObjectFromDatabase.Uuid);
            Assert.IsFalse(tableObjectFromDatabase.IsFile);
        }
Ejemplo n.º 2
0
        public async Task UpdateTableObjectShouldUpdateTheTableObjectInTheDatabase()
        {
            // Arrange
            Guid uuid            = Guid.NewGuid();
            int  tableId         = 5;
            var  tableObjectData = new TableObjectData
            {
                uuid     = uuid,
                table_id = tableId
            };
            var tableObject = tableObjectData.ToTableObject();

            // Save the tableObject in the db and create a new table object with the same uuid but different values
            await Dav.Database.CreateTableObjectAsync(tableObject);

            var newTableObjectData = new TableObjectData
            {
                uuid     = uuid,
                table_id = tableId
            };
            var newTableObject = newTableObjectData.ToTableObject();

            // Act
            await Dav.Database.UpdateTableObjectAsync(newTableObject);

            // Assert
            var tableObjectFromDatabase = await Dav.Database.GetTableObjectAsync(uuid);

            Assert.AreEqual(tableId, tableObjectFromDatabase.TableId);
            Assert.AreEqual(tableObject.Id, tableObjectFromDatabase.Id);
        }
Ejemplo n.º 3
0
        public async Task UpdateTableObjectShouldNotThrowAnExceptionWhenTheTableObjectDoesNotExist()
        {
            // Arrange
            var tableObjectData = new TableObjectData
            {
                table_id = -2,
                uuid     = Guid.NewGuid()
            };
            var tableObject = tableObjectData.ToTableObject();

            // Act
            await Dav.Database.UpdateTableObjectAsync(tableObject);
        }
Ejemplo n.º 4
0
        public async Task CreateTableObjectWithPropertiesShouldSaveTheTableObjectAndItsPropertiesInTheDatabase()
        {
            // Arrange
            SQLiteConnection database = new SQLiteConnection(databasePath);
            int    tableId            = 4;
            Guid   uuid = Guid.NewGuid();
            string firstPropertyName   = "page1";
            string secondPropertyName  = "page2";
            string firstPropertyValue  = "Hello World";
            string secondPropertyValue = "Hallo Welt";
            Dictionary <string, string> propertiesDictionary = new Dictionary <string, string>
            {
                { firstPropertyName, firstPropertyValue },
                { secondPropertyName, secondPropertyValue }
            };

            var tableObjectData = new TableObjectData
            {
                table_id   = tableId,
                uuid       = uuid,
                file       = false,
                properties = propertiesDictionary
            };
            var tableObject = tableObjectData.ToTableObject();

            // Act
            await Dav.Database.CreateTableObjectWithPropertiesAsync(tableObject);

            // Assert
            var tableObjectFromDatabase = database.Get <TableObject>(tableObject.Id);

            Assert.AreEqual(tableId, tableObjectFromDatabase.TableId);
            Assert.AreEqual(tableObject.Id, tableObjectFromDatabase.Id);
            Assert.AreEqual(uuid, tableObjectFromDatabase.Uuid);
            Assert.IsFalse(tableObjectFromDatabase.IsFile);

            var firstPropertyFromDatabase = database.Get <Property>(tableObject.Properties[0].Id);

            Assert.AreEqual(tableObjectFromDatabase.Id, firstPropertyFromDatabase.TableObjectId);
            Assert.AreEqual(firstPropertyName, firstPropertyFromDatabase.Name);
            Assert.AreEqual(firstPropertyValue, firstPropertyValue);

            var secondPropertyFromDatabase = database.Get <Property>(tableObject.Properties[1].Id);

            Assert.AreEqual(tableObjectFromDatabase.Id, secondPropertyFromDatabase.TableObjectId);
            Assert.AreEqual(secondPropertyName, secondPropertyFromDatabase.Name);
            Assert.AreEqual(secondPropertyValue, secondPropertyFromDatabase.Value);
        }