Exemplo n.º 1
0
        public async Task LocateFromPath_JustRoot()
        {
            var rootGroup = new Group("ABPaint".ToCharArray());
            await ABSRegistry.AddItemToRootAsync(rootGroup);

            Assert.AreEqual(rootGroup, await ABSRegistry.LocateFromPathAsync("/ABPaint"));
        }
Exemplo n.º 2
0
        public async Task SplitPath_Nothing_EmptyPath()
        {
            var expected = new List <List <char> >();

            CollectionAssert.AreEqual(expected, await ABSRegistry.SplitPathAsync(""));
            CollectionAssert.AreEqual(expected, await ABSRegistry.SplitPathAsync(new char[0]));
        }
Exemplo n.º 3
0
        public async Task GetItems_MultipleParts()
        {
            var inner = new Group("Inner".ToCharArray())
            {
                InnerItems = new List <Item>()
                {
                    new Group("Final1".ToCharArray()),
                    new Group("Final2".ToCharArray()),
                }
            };

            var rootArr = new Group[]
            {
                new Group("Test1".ToCharArray())
                {
                    InnerItems = new List <Item>()
                    {
                        inner
                    }
                },
                new Group("Test2".ToCharArray()),
                new Group("Test3".ToCharArray())
            };

            for (int i = 0; i < rootArr.Length; i++)
            {
                await ABSRegistry.AddItemToRootAsync(rootArr[i]);
            }

            CollectionAssert.AreEqual(inner.InnerItems, await ABSRegistry.GetItemsAsync("Test1/Inner"));
            CollectionAssert.AreEqual(inner.InnerItems, await ABSRegistry.GetItemsAsync("/Test1/Inner"));
        }
Exemplo n.º 4
0
        public async Task Delete_ItemWithInnerItems()
        {
            var rootArr = new Group[]
            {
                new Group("Test1".ToCharArray())
                {
                    InnerItems = new List <Item>()
                    {
                        new Group("Inner".ToCharArray())
                    }
                },
                new Group("Test2".ToCharArray()),
                new Group("Test3".ToCharArray())
            };

            for (int i = 0; i < rootArr.Length; i++)
            {
                await ABSRegistry.AddItemToRootAsync(rootArr[i]);
            }

            // Delete the item.
            await ABSRegistry.DeleteAsync("Test1");

            // It shouldn't exist anymore.
            Assert.IsFalse(await ABSRegistry.ExistsAsync("Test1"));
            Assert.IsFalse(await ABSRegistry.ExistsAsync("Test1/Inner"));
        }
Exemplo n.º 5
0
        public BaseViewModel()
        {
            var allProperties = typeof(T).GetProperties();

            PropertyChanged += (s, e) => UpdateRegistry(e.PropertyName);

            for (int i = 0; i < allProperties.Length; i++)
            {
                var attribute = allProperties[i].GetCustomAttribute <RegistrySyncAttribute>();
                if (attribute != null)
                {
                    var regItem = ABSRegistry.GetItem(attribute.RegistryPath);
                    if (regItem is RegGroup)
                    {
                        ABSLog.ThrowError("Cannot registry sync to a group.");
                    }

                    var syncInfo = new RegistrySyncInfo(allProperties[i], regItem, attribute.BooleanGroupPos);
                    _registrySyncProperties.Add(allProperties[i].Name, syncInfo);
                    AddEventHandlerToItem(syncInfo, regItem);

                    UpdateProperty(syncInfo);
                }
            }
        }
Exemplo n.º 6
0
        public unsafe void GetSegment_Invalid()
        {
            char *ch = stackalloc char[4];

            Assert.IsFalse(ABSRegistry.GetSegment("$AG:", ch, out _, out _));
            Assert.IsFalse(ABSRegistry.GetSegment("XYZ:", ch, out _, out _));
            Assert.IsFalse(ABSRegistry.GetSegment("abc", ch, out _, out _));
        }
Exemplo n.º 7
0
        public async Task SplitPath_RootOnly_EmptyPath()
        {
            var expected = new List <List <char> >();

            CollectionAssert.AreEqual(expected, await ABSRegistry.SplitPathAsync("/"));
            CollectionAssert.AreEqual(expected, await ABSRegistry.SplitPathAsync(new char[] { '/' }));
            CollectionAssert.AreEqual(expected, await ABSRegistry.SplitPathAsync("\\"));
            CollectionAssert.AreEqual(expected, await ABSRegistry.SplitPathAsync(new char[] { '\\' }));
        }
Exemplo n.º 8
0
        public async Task CreateGroup_AddToRoot()
        {
            var groupName = "Test";

            // Add the group.
            await ABSRegistry.CreateGroupAsync(groupName);

            // Make sure that group exists.
            CollectionAssert.AreEqual(groupName.ToCharArray(), ABSRegistry.RegistryItems[0].Name);
        }
Exemplo n.º 9
0
        public async Task AddItemAt_AddToRoot()
        {
            var groupName = "Test".ToCharArray();

            // Add the item.
            await ABSRegistry.AddItemAtAsync("", new Group(groupName));

            // Make sure that group exists.
            CollectionAssert.AreEqual(groupName, ABSRegistry.RegistryItems[0].Name);
        }
Exemplo n.º 10
0
        public async Task LocateInGroup_ValidPath()
        {
            var group = new Group("ABPaint".ToCharArray());

            group.InnerItems = new List <Item>()
            {
                new Group("Another".ToCharArray())
            };

            CollectionAssert.AreEqual((await ABSRegistry.LocateInGroupAsync("Another", group)).Name, "Another".ToCharArray());
        }
Exemplo n.º 11
0
        public async Task LocateInGroup_InvalidPath()
        {
            var group = new Group("ABPaint".ToCharArray())
            {
                InnerItems = new List <Item>()
                {
                    new Group("Another".ToCharArray())
                }
            };

            Assert.AreEqual(await ABSRegistry.LocateInGroupAsync("Another2", group), null);
        }
Exemplo n.º 12
0
        public async Task Exists_InRoot_DoesExist()
        {
            // Set up the registry.
            await ABSRegistry.AddItemToRootAsync(new Group("Test1".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test2".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test3".ToCharArray()));

            Assert.IsTrue(await ABSRegistry.ExistsAsync("Test1"));
            Assert.IsTrue(await ABSRegistry.ExistsAsync("/Test1"));
        }
Exemplo n.º 13
0
        public unsafe void GetSegment_Alias_Valid()
        {
            var newSegment = new RegSegment();

            ABSRegistry.SegmentAliases.Add("abc", newSegment);
            char *ch = stackalloc char[4];

            Assert.IsTrue(ABSRegistry.GetSegment("$abc:", ch, out int pos, out RegSegment segment));

            Assert.AreEqual(newSegment, segment);
            Assert.AreEqual(5, pos);
        }
Exemplo n.º 14
0
        public async Task LocateFromPath_MultipleParts()
        {
            var secondGroup = new Group("Another".ToCharArray());
            var rootGroup   = new Group("ABPaint".ToCharArray())
            {
                InnerItems = new List <Item>()
                {
                    secondGroup
                }
            };
            await ABSRegistry.AddItemToRootAsync(rootGroup);

            CollectionAssert.AreEqual(secondGroup.Name, (await ABSRegistry.LocateFromPathAsync("/ABPaint/Another")).Name);
        }
Exemplo n.º 15
0
        public async Task SplitPath_GroupInRoot()
        {
            var expected = new List <List <char> >()
            {
                new List <char>()
                {
                    'A', 'B', 'P', 'a', 'i', 'n', 't'
                }
            };

            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("ABPaint")));
            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("/ABPaint")));
            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("\\ABPaint")));
        }
Exemplo n.º 16
0
        public async Task AddItemAt_InOtherGroup_NotGroup()
        {
            var groupName = "NewGroup".ToCharArray();

            // Set up the registry.
            await ABSRegistry.AddItemToRootAsync(new Group("Test1".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test2".ToCharArray()));

            // Add the item.
            await ABSRegistry.AddItemAtAsync("Test1", new Group(groupName));

            // Make sure that group exists.
            CollectionAssert.AreEqual(groupName, (ABSRegistry.RegistryItems[0] as Group).InnerItems[0].Name);
        }
Exemplo n.º 17
0
        public async Task Delete_InRoot()
        {
            // Set up the registry.
            await ABSRegistry.AddItemToRootAsync(new Group("Test1".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test2".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test3".ToCharArray()));

            // Delete the item.
            await ABSRegistry.DeleteAsync("Test2");

            // It shouldn't exist anymore.
            Assert.IsFalse(await ABSRegistry.ExistsAsync("Test2"));
        }
Exemplo n.º 18
0
        public async Task CreateGroup_InOtherGroup()
        {
            // Set up the registry.
            await ABSRegistry.AddItemToRootAsync(new Group("Test1".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test2".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test3".ToCharArray()));

            // Add the group.
            await ABSRegistry.CreateGroupAsync("Test1/NewGroup");

            // Make sure that group exists.
            CollectionAssert.AreEqual("NewGroup".ToCharArray(), (ABSRegistry.RegistryItems[0] as Group).InnerItems[0].Name);
        }
Exemplo n.º 19
0
        public async Task GetItems_FromRoot()
        {
            var rootArr = new Group[]
            {
                new Group("Test1".ToCharArray()),
                new Group("Test2".ToCharArray()),
                new Group("Test3".ToCharArray())
            };

            for (int i = 0; i < rootArr.Length; i++)
            {
                await ABSRegistry.AddItemToRootAsync(rootArr[i]);
            }

            CollectionAssert.AreEqual(rootArr, await ABSRegistry.GetItemsAsync("/"));
        }
Exemplo n.º 20
0
        public async Task AddItemToRoot_AlreadyExists()
        {
            var groupName = "Test".ToCharArray();

            // Add the group.
            await ABSRegistry.AddItemToRootAsync(new Group(groupName));


            try
            {
                await ABSRegistry.AddItemToRootAsync(new Group(groupName));

                // An exception should have been thrown, so it shouldn't get here.
                Assert.Fail();
            }
            catch (Exception) { }
        }
Exemplo n.º 21
0
        public async Task AddItemAt_InOtherGroup_AlreadyExists()
        {
            // Set up the registry.
            await ABSRegistry.AddItemToRootAsync(new Group("Test1".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test2".ToCharArray()));

            await ABSRegistry.AddItemToRootAsync(new Group("Test3".ToCharArray()));

            // Add the item.
            await ABSRegistry.AddItemAtAsync("Test1", new Group("NewGroup".ToCharArray()));

            try
            {
                await ABSRegistry.AddItemAtAsync("Test1", new Group("NewGroup".ToCharArray()));

                // An exception should have been thrown.
                Assert.Fail();
            }
            catch (Exception) { }
        }
Exemplo n.º 22
0
        public async Task GetItems_InvalidPath()
        {
            var rootArr = new Group[]
            {
                new Group("Test1".ToCharArray()),
                new Group("Test2".ToCharArray()),
                new Group("Test3".ToCharArray())
            };

            for (int i = 0; i < rootArr.Length; i++)
            {
                await ABSRegistry.AddItemToRootAsync(rootArr[i]);
            }

            try
            {
                // This should throw an exception, meaning the "Assert.Fail" never gets hit.
                await ABSRegistry.GetItemsAsync("Test4");

                Assert.Fail();
            } catch (Exception) { }
        }
Exemplo n.º 23
0
        public async Task SplitPath_MultipleParts()
        {
            var expected = new List <List <char> >()
            {
                new List <char>()
                {
                    'A', 'B', 'P', 'a', 'i', 'n', 't'
                },
                new List <char>()
                {
                    'N', 'e', 'x', 't'
                },
                new List <char>()
                {
                    'A', 'n', 'o', 't', 'h', 'e', 'r'
                }
            };

            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("ABPaint/Next/Another")));
            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("/ABPaint/Next/Another")));
            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("ABPaint\\Next\\Another")));
            Assert.IsTrue(TestArr(expected, await ABSRegistry.SplitPathAsync("\\ABPaint\\Next\\Another")));
        }
Exemplo n.º 24
0
        public async Task Exists_MultipleParts_DoesExist()
        {
            var rootArr = new Group[]
            {
                new Group("Test1".ToCharArray())
                {
                    InnerItems = new List <Item>()
                    {
                        new Group("Inner".ToCharArray())
                    }
                },
                new Group("Test2".ToCharArray()),
                new Group("Test3".ToCharArray())
            };

            for (int i = 0; i < rootArr.Length; i++)
            {
                await ABSRegistry.AddItemToRootAsync(rootArr[i]);
            }

            Assert.IsTrue(await ABSRegistry.ExistsAsync("Test1/Inner"));
            Assert.IsTrue(await ABSRegistry.ExistsAsync("/Test1/Inner"));
        }
Exemplo n.º 25
0
 public async Task Exists_RootItself_DoesExist()
 {
     Assert.IsTrue(await ABSRegistry.ExistsAsync("/"));
 }
Exemplo n.º 26
0
        public async Task LocateInRoot_ValidPath()
        {
            await ABSRegistry.AddItemToRootAsync(new Group("ABPaint".ToCharArray()));

            CollectionAssert.AreEqual((await ABSRegistry.LocateInRootAsync("ABPaint")).Name, "ABPaint".ToCharArray());
        }
Exemplo n.º 27
0
 public async Task Exists_InRoot_DoesNotExist()
 {
     Assert.IsFalse(await ABSRegistry.ExistsAsync("Test1"));
     Assert.IsFalse(await ABSRegistry.ExistsAsync("/Test1"));
 }
Exemplo n.º 28
0
 public void Init() => ABSRegistry.ClearRegistry();
Exemplo n.º 29
0
 public async Task Exists_MultipleParts_DoesNotExist()
 {
     Assert.IsFalse(await ABSRegistry.ExistsAsync("Test1/Another"));
     Assert.IsFalse(await ABSRegistry.ExistsAsync("/Test1/Another"));
 }
Exemplo n.º 30
0
 public async Task LocateInRoot_InvalidPath()
 {
     Assert.AreEqual(await ABSRegistry.LocateInRootAsync("(None)"), null);
 }