public async Task CreateWithUuidTableIdAndFileShouldCreateNewTableObject()
        {
            // Arrange
            int      tableId     = 4;
            Guid     uuid        = Guid.NewGuid();
            FileInfo file        = new FileInfo(Path.Combine(Utils.GetProjectDirectory(), "Assets", "image.jpg"));
            string   newFilePath = Path.Combine(Utils.GetDavDataPath(), tableId.ToString(), uuid.ToString());

            // Act
            var tableObject = await TableObject.CreateAsync(uuid, tableId, file);

            // Assert
            Assert.AreEqual(tableId, tableObject.TableId);
            Assert.AreEqual(uuid, tableObject.Uuid);
            Assert.IsTrue(tableObject.IsFile);
            Assert.AreEqual(newFilePath, tableObject.File.FullName);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(uuid);

            Assert.IsNotNull(tableObject2);
            Assert.AreEqual(tableObject.TableId, tableObject2.TableId);
            Assert.AreEqual(tableObject.Id, tableObject2.Id);
            Assert.AreEqual(tableObject.Uuid, tableObject2.Uuid);
            Assert.AreEqual(newFilePath, tableObject2.File.FullName);
            Assert.AreEqual(tableObject.Properties.Find(prop => prop.Name == "ext").Value, file.Extension.Replace(".", ""));
        }
Esempio n. 2
0
        public static async Task AddSoundAsync(Guid uuid, string name, string soundUuid, List <string> categoryUuids)
        {
            // Create TableObject with sound informations and TableObject with the Soundfile
            var properties = new List <Property>
            {
                new Property {
                    Name = FileManager.SoundTableNamePropertyName, Value = name
                },
                new Property {
                    Name = FileManager.SoundTableFavouritePropertyName, Value = bool.FalseString
                },
                new Property {
                    Name = FileManager.SoundTableSoundUuidPropertyName, Value = soundUuid
                }
            };

            if (categoryUuids != null)
            {
                properties.Add(new Property {
                    Name = FileManager.SoundTableCategoryUuidPropertyName, Value = string.Join(",", categoryUuids)
                });
            }

            await TableObject.CreateAsync(uuid, FileManager.SoundTableId, properties);
        }
        public async Task DeleteShouldDeleteTheTableObjectImmediatelyWhenTheUserIsNotLoggedIn()
        {
            // Arrange
            int             tableId        = 4;
            Guid            uuid           = Guid.NewGuid();
            List <Property> propertiesList = new List <Property>
            {
                new Property {
                    Name = "page1", Value = "Hello World"
                },
                new Property {
                    Name = "page2", Value = "Hallo Welt"
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            int firstPropertyId  = tableObject.Properties[0].Id;
            int secondPropertyId = tableObject.Properties[1].Id;

            // Act
            await tableObject.DeleteAsync();

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

            Assert.IsNull(tableObjectFromDatabase);

            var firstPropertyFromDatabase = await Dav.Database.GetPropertyAsync(firstPropertyId);

            Assert.IsNull(firstPropertyFromDatabase);

            var secondPropertyFromDatabase = await Dav.Database.GetPropertyAsync(secondPropertyId);

            Assert.IsNull(secondPropertyFromDatabase);
        }
        public async Task DeleteTableObjectImmediatelyWithUuidShouldDeleteTheTableObjectAndItsPropertiesImmediately()
        {
            // Arrange
            int  tableId    = 4;
            Guid uuid       = Guid.NewGuid();
            var  properties = new List <Property>
            {
                new Property {
                    Name = "test", Value = "test"
                },
                new Property {
                    Name = "bla", Value = "bla"
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, properties);

            int firstPropertyId  = tableObject.Properties[0].Id;
            int secondPropertyId = tableObject.Properties[1].Id;

            // Act
            await Dav.Database.DeleteTableObjectImmediatelyAsync(uuid);

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

            Assert.IsNull(tableObjectFromDatabase);

            var firstPropertyFromDatabase = await Dav.Database.GetPropertyAsync(firstPropertyId);

            Assert.IsNull(firstPropertyFromDatabase);

            var secondPropertyFromDatabase = await Dav.Database.GetPropertyAsync(secondPropertyId);

            Assert.IsNull(secondPropertyFromDatabase);
        }
        public async Task DeleteShouldSetTheUploadStatusOfTheTableObjectToDeletedWhenTheUserIsLoggedIn()
        {
            // Arrange
            davClassLibrary.Dav.IsLoggedIn  = true;
            davClassLibrary.Dav.AccessToken = Constants.testerXTestAppAccessToken;

            int             tableId        = 4;
            Guid            uuid           = Guid.NewGuid();
            List <Property> propertiesList = new List <Property>
            {
                new Property {
                    Name = "page1", Value = "Hello World"
                },
                new Property {
                    Name = "page2", Value = "Hallo Welt"
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            // Act
            await tableObject.DeleteAsync();

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

            Assert.IsNotNull(tableObject2);
            Assert.AreEqual(TableObjectUploadStatus.Deleted, tableObject2.UploadStatus);
        }
        public async Task RemovePropertyShouldRemoveThePropertyFromThePropertiesListAndDeleteItFromTheDatabase()
        {
            // Arrange
            int             tableId        = 4;
            Guid            uuid           = Guid.NewGuid();
            string          propertyName   = "page1";
            string          propertyValue  = "Hello World";
            List <Property> propertiesList = new List <Property>
            {
                new Property {
                    Name = propertyName, Value = propertyValue
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            // Act
            await tableObject.RemovePropertyAsync(propertyName);

            // Assert
            Assert.AreEqual(0, tableObject.Properties.Count);
            Assert.IsNull(tableObject.GetPropertyValue(propertyName));

            var tableObject2 = await Dav.Database.GetTableObjectAsync(tableObject.Uuid);

            Assert.NotNull(tableObject2);
            Assert.AreEqual(0, tableObject2.Properties.Count);
            Assert.IsNull(tableObject2.GetPropertyValue(propertyName));
        }
        public async Task DeleteTableObjectImmediatelyWithTableObjectShouldDeleteTheTableObjectAndItsPropertiesImmediately()
        {
            // Arrange
            int             tableId        = 6;
            Guid            uuid           = Guid.NewGuid();
            List <Property> propertiesList = new List <Property>
            {
                new Property {
                    Name = "page1", Value = "Good day"
                },
                new Property {
                    Name = "page2", Value = "Guten Tag"
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            int firstPropertyId  = tableObject.Properties[0].Id;
            int secondPropertyId = tableObject.Properties[1].Id;

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

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

            Assert.IsNull(tableObjectFromDatabase);

            var firstPropertyFromDatabase = await Dav.Database.GetPropertyAsync(firstPropertyId);

            Assert.IsNull(firstPropertyFromDatabase);

            var secondPropertyFromDatabase = await Dav.Database.GetPropertyAsync(secondPropertyId);

            Assert.IsNull(secondPropertyFromDatabase);
        }
        public async Task GetPropertyValueShouldReturnTheValueOfTheProperty()
        {
            // Arrange
            int             tableId        = 4;
            Guid            uuid           = Guid.NewGuid();
            string          propertyName   = "page1";
            string          propertyValue  = "Hello World";
            List <Property> propertiesList = new List <Property>
            {
                new Property {
                    Name = propertyName, Value = propertyValue
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            Assert.AreEqual(tableObject.Properties.Count, 1);
            Assert.AreEqual(tableObject.Properties[0].Name, propertyName);
            Assert.AreEqual(tableObject.Properties[0].Value, propertyValue);

            // Act
            string newPropertyValue = tableObject.GetPropertyValue(propertyName);

            // Assert
            Assert.AreEqual(propertyValue, newPropertyValue);
        }
        public async Task SetPropertyValueShouldUpdateAnExistingPropertyAndSaveItInTheDatabase()
        {
            // Arrange
            int             tableId          = 4;
            Guid            uuid             = Guid.NewGuid();
            string          propertyName     = "page1";
            string          oldPropertyValue = "Hello World";
            string          newPropertyValue = "Hallo Welt";
            List <Property> propertiesList   = new List <Property>
            {
                new Property {
                    Name = propertyName, Value = oldPropertyValue
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            Assert.AreEqual(tableObject.Properties.Count, 1);
            Assert.AreEqual(tableObject.Properties[0].Name, propertyName);
            Assert.AreEqual(tableObject.Properties[0].Value, oldPropertyValue);

            // Act
            await tableObject.SetPropertyValueAsync(propertyName, newPropertyValue);

            // Assert
            Assert.AreEqual(tableObject.Properties.Count, 1);
            Assert.AreEqual(tableObject.Properties[0].Name, propertyName);
            Assert.AreEqual(tableObject.Properties[0].Value, newPropertyValue);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(uuid);

            Assert.AreEqual(tableObject2.Properties.Count, 1);
            Assert.AreEqual(tableObject2.Properties[0].Name, propertyName);
            Assert.AreEqual(tableObject2.Properties[0].Value, newPropertyValue);
        }
Esempio n. 10
0
        public async Task GetPropertiesOfTableObjectShouldReturnAllPropertiesOfTheTableObject()
        {
            // Arrange
            Guid            uuid                = Guid.NewGuid();
            int             tableId             = 3;
            string          firstPropertyName   = "page1";
            string          secondPropertyName  = "page2";
            string          firstPropertyValue  = "Hello World";
            string          secondPropertyValue = "Hallo Welt";
            List <Property> properties          = new List <Property>
            {
                new Property {
                    Name = firstPropertyName, Value = firstPropertyValue
                },
                new Property {
                    Name = secondPropertyName, Value = secondPropertyValue
                }
            };
            var tableObject = await TableObject.CreateAsync(uuid, tableId, properties);

            // Act
            var propertiesList = await Dav.Database.GetPropertiesOfTableObjectAsync(tableObject.Id);

            // Assert
            Assert.AreEqual(firstPropertyName, propertiesList[0].Name);
            Assert.AreEqual(firstPropertyValue, propertiesList[0].Value);
            Assert.AreEqual(secondPropertyName, propertiesList[1].Name);
            Assert.AreEqual(secondPropertyValue, propertiesList[1].Value);
        }
Esempio n. 11
0
        public async Task CreateWithUuidTableIdAndPropertiesShouldCreateNewTableObject()
        {
            // Arrange
            var             tableId        = 4;
            Guid            uuid           = Guid.NewGuid();
            List <Property> propertiesList = new List <Property>
            {
                new Property {
                    Name = "page1", Value = "Hallo Welt"
                },
                new Property {
                    Name = "page2", Value = "Hello World"
                }
            };

            // Act
            var tableObject = await TableObject.CreateAsync(uuid, tableId, propertiesList);

            // Assert
            Assert.AreEqual(tableId, tableObject.TableId);
            Assert.AreEqual(uuid, tableObject.Uuid);
            Assert.AreEqual(propertiesList, tableObject.Properties);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(uuid);

            Assert.IsNotNull(tableObject2);
            Assert.AreEqual(tableObject.TableId, tableObject2.TableId);
            Assert.AreEqual(tableObject.Id, tableObject2.Id);
            Assert.AreEqual(tableObject.Uuid, tableObject2.Uuid);
        }
Esempio n. 12
0
        public static async Task SetCategoryOrderAsync(List <Guid> uuids)
        {
            // Check if the order already exists
            List <TableObject> tableObjects = await GetAllOrdersAsync();

            TableObject tableObject = tableObjects.Find(obj => obj.GetPropertyValue(FileManager.OrderTableTypePropertyName) == FileManager.CategoryOrderType);

            if (tableObject == null)
            {
                // Create a new table object
                List <Property> properties = new List <Property>
                {
                    // Set the type property
                    new Property {
                        Name = FileManager.OrderTableTypePropertyName, Value = FileManager.CategoryOrderType
                    }
                };

                int i = 0;
                foreach (var uuid in uuids)
                {
                    properties.Add(new Property {
                        Name = i.ToString(), Value = uuid.ToString()
                    });
                    i++;
                }

                await TableObject.CreateAsync(Guid.NewGuid(), FileManager.OrderTableId, properties);
            }
            else
            {
                // Update the existing object
                int i = 0;
                Dictionary <string, string> newProperties = new Dictionary <string, string>();
                foreach (var uuid in uuids)
                {
                    newProperties.Add(i.ToString(), uuid.ToString());
                    i++;
                }
                await tableObject.SetPropertyValuesAsync(newProperties);

                // Remove the properties that are outside of the uuids range
                List <string> removedProperties = new List <string>();
                foreach (var property in tableObject.Properties)
                {
                    if (int.TryParse(property.Name, out int propertyIndex) && propertyIndex >= uuids.Count)
                    {
                        removedProperties.Add(property.Name);
                    }
                }

                for (int j = 0; j < removedProperties.Count; j++)
                {
                    await tableObject.RemovePropertyAsync(removedProperties[j]);
                }
            }
        }
Esempio n. 13
0
        public async Task TableObjectExistsShouldReturnTrueIfTheTableObjectExists()
        {
            // Arrange
            int tableId     = 5;
            var tableObject = await TableObject.CreateAsync(tableId);

            // Act
            bool tableObjectExists = await Dav.Database.TableObjectExistsAsync(tableObject.Uuid);

            // Assert
            Assert.IsTrue(tableObjectExists);
        }
Esempio n. 14
0
        public async Task GetPropertyValueShouldReturnNullIfThePropertyDoesNotExist()
        {
            // Arrange
            int    tableId      = 4;
            string propertyName = "page1";
            var    tableObject  = await TableObject.CreateAsync(tableId);

            // Act
            var value = tableObject.GetPropertyValue(propertyName);

            Assert.IsNull(value);
        }
Esempio n. 15
0
 public static async Task AddCategoryAsync(Guid uuid, string name, string icon)
 {
     List <Property> properties = new List <Property>
     {
         new Property {
             Name = FileManager.CategoryTableNamePropertyName, Value = name
         },
         new Property {
             Name = FileManager.CategoryTableIconPropertyName, Value = icon
         }
     };
     await TableObject.CreateAsync(uuid, FileManager.CategoryTableId, properties);
 }
Esempio n. 16
0
        public async Task SetFileShouldNotWorkWhenTheTableObjectIsNotAFile()
        {
            // Arrange
            int      tableId     = 3;
            FileInfo file        = new FileInfo(Path.Combine(Utils.GetProjectDirectory(), "Assets", "image.jpg"));
            var      tableObject = await TableObject.CreateAsync(tableId);

            // Act
            await tableObject.SetFileAsync(file);

            // Assert
            var tableObject2 = await Dav.Database.GetTableObjectAsync(tableObject.Uuid);

            Assert.IsFalse(tableObject2.IsFile);
            Assert.IsNull(tableObject2.File);
        }
Esempio n. 17
0
        public async Task DeleteTableObjectWithTableObjectShouldSetTheUploadStatusToDeleted()
        {
            // Arrange
            int  tableId     = 4;
            Guid uuid        = Guid.NewGuid();
            var  tableObject = await TableObject.CreateAsync(uuid, tableId);

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

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

            Assert.AreEqual(TableObjectUploadStatus.Deleted, tableObjectFromDatabase.UploadStatus);
            Assert.AreEqual(tableObject.Id, tableObjectFromDatabase.Id);
        }
Esempio n. 18
0
        public async Task GetTableObjectShouldReturnTheTableObject()
        {
            // Arrange
            Guid uuid        = Guid.NewGuid();
            int  tableId     = 4;
            var  tableObject = await TableObject.CreateAsync(uuid, tableId);

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

            // Assert
            Assert.AreEqual(tableObject.Id, tableObjectFromDatabase.Id);
            Assert.AreEqual(tableObject.TableId, tableObjectFromDatabase.TableId);
            Assert.AreEqual(tableObject.Uuid, tableObjectFromDatabase.Uuid);
            Assert.AreEqual(tableObject.UploadStatus, tableObjectFromDatabase.UploadStatus);
        }
Esempio n. 19
0
        public async Task GetAllTableObjectsShouldReturnAllTableObjectsExceptDeletedOnes()
        {
            // Arrange
            var tableObjects = new List <TableObject>
            {
                await TableObject.CreateAsync(Guid.NewGuid(), 13),
                await TableObject.CreateAsync(Guid.NewGuid(), 13),
                await TableObject.CreateAsync(Guid.NewGuid(), 12)
            };
            await tableObjects[0].SetUploadStatusAsync(TableObjectUploadStatus.Deleted);

            // Act
            var allTableObjects = await Dav.Database.GetAllTableObjectsAsync(false);

            // Assert
            Assert.AreEqual(tableObjects.Count - 1, allTableObjects.Count);
        }
Esempio n. 20
0
        public async Task SetPropertyValuesShouldUpdateExistingPropertiesAndSaveThemInTheDatabase()
        {
            // Arrange
            Guid            uuid                   = Guid.NewGuid();
            var             tableId                = 4;
            var             firstPropertyName      = "page1";
            var             oldFirstPropertyValue  = "test";
            var             newFirstPropertyValue  = "testtest";
            var             secondPropertyName     = "page2";
            var             oldSecondPropertyValue = "blabla";
            var             newSecondPropertyValue = "blablub";
            List <Property> properties             = new List <Property>
            {
                new Property {
                    Name = firstPropertyName, Value = oldFirstPropertyValue
                },
                new Property {
                    Name = secondPropertyName, Value = oldSecondPropertyValue
                }
            };

            var tableObject = await TableObject.CreateAsync(uuid, tableId, properties);

            Dictionary <string, string> newProperties = new Dictionary <string, string>
            {
                { firstPropertyName, newFirstPropertyValue },
                { secondPropertyName, newSecondPropertyValue }
            };

            // Act
            await tableObject.SetPropertyValuesAsync(newProperties);

            // Assert
            Assert.AreEqual(newFirstPropertyValue, tableObject.GetPropertyValue(firstPropertyName));
            Assert.AreEqual(newSecondPropertyValue, tableObject.GetPropertyValue(secondPropertyName));

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

            Assert.IsNotNull(tableObjectFromDatabase);
            Assert.AreEqual(2, tableObjectFromDatabase.Properties.Count);
            Assert.AreEqual(firstPropertyName, tableObjectFromDatabase.Properties[0].Name);
            Assert.AreEqual(newFirstPropertyValue, tableObjectFromDatabase.Properties[0].Value);
            Assert.AreEqual(secondPropertyName, tableObjectFromDatabase.Properties[1].Name);
            Assert.AreEqual(newSecondPropertyValue, tableObjectFromDatabase.Properties[1].Value);
        }
Esempio n. 21
0
        public async Task CreateWithTableIdShouldCreateNewTableObject()
        {
            // Arrange
            int tableId = 4;

            // Act
            var tableObject = await TableObject.CreateAsync(tableId);

            // Assert
            Assert.AreEqual(tableId, tableObject.TableId);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(tableObject.Uuid);

            Assert.IsNotNull(tableObject2);
            Assert.AreEqual(tableObject.Id, tableObject2.Id);
            Assert.AreEqual(tableObject.TableId, tableObject2.TableId);
            Assert.AreEqual(tableObject.Uuid, tableObject2.Uuid);
        }
Esempio n. 22
0
        public async Task DeleteImmediatelyShouldDeleteTheTableObjectAndItsFile()
        {
            // Arrange
            int      tableId     = 4;
            Guid     uuid        = Guid.NewGuid();
            FileInfo file        = new FileInfo(Path.Combine(Utils.GetProjectDirectory(), "Assets", "icon.ico"));
            var      tableObject = await TableObject.CreateAsync(uuid, tableId, file);

            string filePath = tableObject.File.FullName;

            // Act
            await tableObject.DeleteImmediatelyAsync();

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

            Assert.IsFalse(File.Exists(filePath));
            Assert.IsNull(tableObjectFromDatabase);
        }
Esempio n. 23
0
        public async Task GetAllTableObjectsWithTableIdShouldReturnAlltableObjectsOfTheTableExceptDeletedOnes()
        {
            // Arrange
            int tableId      = 4;
            var tableObjects = new List <TableObject>
            {
                await TableObject.CreateAsync(Guid.NewGuid(), tableId),
                await TableObject.CreateAsync(Guid.NewGuid(), tableId),
                await TableObject.CreateAsync(Guid.NewGuid(), tableId),
                await TableObject.CreateAsync(Guid.NewGuid(), 3),
            };
            await tableObjects[0].SetUploadStatusAsync(TableObjectUploadStatus.Deleted);

            // Act
            var allTableObjects = await Dav.Database.GetAllTableObjectsAsync(tableId, false);

            // Assert
            Assert.AreEqual(tableObjects.Count - 2, allTableObjects.Count);
        }
Esempio n. 24
0
        public async Task SetUploadStatusShouldUpdateTheUploadStatusOfTheTableObjectAndSaveItInTheDatabase()
        {
            // Arrange
            int tableId     = 4;
            var tableObject = await TableObject.CreateAsync(tableId);

            TableObjectUploadStatus newUploadStatus = TableObjectUploadStatus.Updated;

            Assert.AreEqual(TableObjectUploadStatus.New, tableObject.UploadStatus);

            // Act
            await tableObject.SetUploadStatusAsync(newUploadStatus);

            // Assert
            Assert.AreEqual(newUploadStatus, tableObject.UploadStatus);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(tableObject.Uuid);

            Assert.IsNotNull(tableObject);
            Assert.AreEqual(newUploadStatus, tableObject2.UploadStatus);
        }
Esempio n. 25
0
        public async Task SetPropertyValuesShouldCreateNewPropertiesAndSaveThemInTheDatabase()
        {
            // Arrange
            Guid uuid                = Guid.NewGuid();
            var  tableId             = 4;
            var  firstPropertyName   = "page1";
            var  secondPropertyName  = "page2";
            var  firstPropertyValue  = "test";
            var  secondPropertyValue = "blablabla";

            var tableObject = await TableObject.CreateAsync(uuid, tableId);

            Dictionary <string, string> newProperties = new Dictionary <string, string>
            {
                { firstPropertyName, firstPropertyValue },
                { secondPropertyName, secondPropertyValue }
            };

            // Act
            await tableObject.SetPropertyValuesAsync(newProperties);

            // Assert
            Assert.AreEqual(firstPropertyValue, tableObject.GetPropertyValue(firstPropertyName));
            Assert.AreEqual(secondPropertyValue, tableObject.GetPropertyValue(secondPropertyName));

            // Make sure the properties have ids
            Assert.AreNotEqual(0, tableObject.Properties[0].Id);
            Assert.AreNotEqual(0, tableObject.Properties[1].Id);

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

            Assert.IsNotNull(tableObjectFromDatabase);
            Assert.AreEqual(2, tableObjectFromDatabase.Properties.Count);
            Assert.AreEqual(firstPropertyName, tableObjectFromDatabase.Properties[0].Name);
            Assert.AreEqual(firstPropertyValue, tableObjectFromDatabase.Properties[0].Value);
            Assert.AreEqual(secondPropertyName, tableObjectFromDatabase.Properties[1].Name);
            Assert.AreEqual(secondPropertyValue, tableObjectFromDatabase.Properties[1].Value);
        }
Esempio n. 26
0
        public static async Task AddPlayingSoundAsync(Guid uuid, List <string> soundIds, int current, int repetitions, bool randomly, double volume)
        {
            var properties = new List <Property>
            {
                new Property {
                    Name = FileManager.PlayingSoundTableSoundIdsPropertyName, Value = string.Join(",", soundIds)
                },
                new Property {
                    Name = FileManager.PlayingSoundTableCurrentPropertyName, Value = current.ToString()
                },
                new Property {
                    Name = FileManager.PlayingSoundTableRepetitionsPropertyName, Value = repetitions.ToString()
                },
                new Property {
                    Name = FileManager.PlayingSoundTableRandomlyPropertyName, Value = randomly.ToString()
                },
                new Property {
                    Name = FileManager.PlayingSoundTableVolumePropertyName, Value = volume.ToString()
                }
            };

            await TableObject.CreateAsync(uuid, FileManager.PlayingSoundTableId, properties);
        }
Esempio n. 27
0
        public async Task SetFileShouldCopyTheFileAndSaveTheExtInTheDatabase()
        {
            // Arrange
            int      tableId = 3;
            Guid     uuid    = Guid.NewGuid();
            FileInfo oldFile = new FileInfo(Path.Combine(Utils.GetProjectDirectory(), "Assets", "image.jpg"));
            FileInfo newFile = new FileInfo(Path.Combine(Utils.GetProjectDirectory(), "Assets", "icon.ico"));

            var tableObject = await TableObject.CreateAsync(uuid, tableId, oldFile);

            // Act
            await tableObject.SetFileAsync(newFile);

            // Assert
            Assert.AreNotEqual(oldFile, tableObject.File);
            Assert.AreEqual(newFile.Length, tableObject.File.Length);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(uuid);

            Assert.NotNull(tableObject2);
            Assert.AreEqual(newFile.Length, tableObject2.File.Length);
            Assert.AreEqual(tableObject2.Properties.Find(prop => prop.Name == "ext").Value, newFile.Extension.Replace(".", ""));
        }
Esempio n. 28
0
        public async Task SetPropertyValueShouldCreateANewPropertyAndSaveItInTheDatabase()
        {
            // Arrange
            int    tableId       = 4;
            string propertyName  = "page1";
            string propertyValue = "Hello World";
            var    tableObject   = await TableObject.CreateAsync(tableId);

            // Act
            await tableObject.SetPropertyValueAsync(propertyName, propertyValue);

            // Assert
            Assert.AreEqual(tableObject.Properties.Count, 1);
            Assert.AreEqual(tableObject.Properties[0].Name, propertyName);
            Assert.AreEqual(tableObject.Properties[0].Value, propertyValue);

            var tableObject2 = await Dav.Database.GetTableObjectAsync(tableObject.Uuid);

            Assert.NotNull(tableObject2);
            Assert.AreEqual(tableObject2.Properties.Count, 1);
            Assert.AreEqual(tableObject2.Properties[0].Name, propertyName);
            Assert.AreEqual(tableObject2.Properties[0].Value, propertyValue);
        }
Esempio n. 29
0
        public static async Task SetSoundOrderAsync(Guid categoryUuid, bool favourite, List <Guid> uuids)
        {
            // Check if the order object already exists
            List <TableObject> tableObjects = await GetAllOrdersAsync();

            TableObject tableObject = tableObjects.Find((TableObject obj) => {
                // Check if the object is of type Sound
                if (obj.GetPropertyValue(FileManager.OrderTableTypePropertyName) != FileManager.SoundOrderType)
                {
                    return(false);
                }

                // Check if the object has the right category uuid
                string categoryUuidString = obj.GetPropertyValue(FileManager.OrderTableCategoryPropertyName);
                Guid?cUuid = FileManager.ConvertStringToGuid(categoryUuidString);
                if (!cUuid.HasValue)
                {
                    return(false);
                }

                string favString = obj.GetPropertyValue(FileManager.OrderTableFavouritePropertyName);
                bool.TryParse(favString, out bool fav);

                return(Equals(categoryUuid, cUuid) && favourite == fav);
            });

            if (tableObject == null)
            {
                // Create a new table object
                List <Property> properties = new List <Property>
                {
                    // Set the type property
                    new Property {
                        Name = FileManager.OrderTableTypePropertyName, Value = FileManager.SoundOrderType
                    },
                    // Set the category property
                    new Property {
                        Name = FileManager.OrderTableCategoryPropertyName, Value = categoryUuid.ToString()
                    },
                    // Set the favourite property
                    new Property {
                        Name = FileManager.OrderTableFavouritePropertyName, Value = favourite.ToString()
                    }
                };

                int i = 0;
                foreach (var uuid in uuids)
                {
                    properties.Add(new Property {
                        Name = i.ToString(), Value = uuid.ToString()
                    });
                    i++;
                }

                await TableObject.CreateAsync(Guid.NewGuid(), FileManager.OrderTableId, properties);
            }
            else
            {
                // Update the existing object
                int i = 0;
                Dictionary <string, string> newProperties = new Dictionary <string, string>();
                foreach (var uuid in uuids)
                {
                    newProperties.Add(i.ToString(), uuid.ToString());
                    i++;
                }
                await tableObject.SetPropertyValuesAsync(newProperties);

                bool removeNonExistentSounds = FileManager.itemViewHolder.User == null || !FileManager.itemViewHolder.User.IsLoggedIn ||
                                               (FileManager.itemViewHolder.User.IsLoggedIn && FileManager.syncFinished);

                if (removeNonExistentSounds)
                {
                    // Remove the properties that are outside of the uuids range
                    List <string> removedProperties = new List <string>();
                    foreach (var property in tableObject.Properties)
                    {
                        if (int.TryParse(property.Name, out int propertyIndex) && propertyIndex >= uuids.Count)
                        {
                            removedProperties.Add(property.Name);
                        }
                    }

                    for (int j = 0; j < removedProperties.Count; j++)
                    {
                        await tableObject.RemovePropertyAsync(removedProperties[j]);
                    }
                }
            }
        }
Esempio n. 30
0
 public static async Task AddImageFileAsync(Guid uuid, StorageFile imageFile)
 {
     await TableObject.CreateAsync(uuid, FileManager.ImageFileTableId, new FileInfo(imageFile.Path));
 }