Пример #1
0
        public async Task TestAddGroup()
        {
            var currentPath  = Path.Combine(Path.GetTempPath(), "SavedDatabase.kdbx");
            var originalFile = await _fileProxy.OpenBinaryFile(Path.Combine(Directory.GetCurrentDirectory(), "Data", "TestDatabase.kdbx"));

            var currentFile = await _fileProxy.OpenBinaryFile(currentPath);

            var newGroup = new GroupEntity {
                Name = "New Group Test"
            };
            await _database.Open(originalFile, _credentials);

            await _database.AddGroup(_database.RootGroupId, newGroup.Id);

            var result = await _database.SaveDatabase(currentFile);

            await _fileProxy.WriteBinaryContentsToFile(currentPath, result);

            _database.CloseDatabase();

            await _database.Open(currentFile, _credentials);

            var rootGroup = _database.GetGroup(_database.RootGroupId);

            Assert.That(newGroup.Id, Is.Not.Empty);
            Assert.That(rootGroup.SubGroups.Count, Is.EqualTo(7));
            Assert.That(rootGroup.SubGroups.Last().Name, Is.EqualTo("New Group Test"));
        }
Пример #2
0
            public async Task Handle(DeleteGroupCommand message)
            {
                if (!_database.IsOpen)
                {
                    throw new DatabaseClosedException();
                }

                var isRecycleBin = message.GroupId.Equals(_database.RecycleBinId);

                if (_database.IsRecycleBinEnabled && (string.IsNullOrEmpty(_database.RecycleBinId) || _database.RecycleBinId.Equals(Constants.EmptyId)))
                {
                    _database.CreateGroup(_database.RootGroupId, message.RecycleBinName, true);
                }

                if (!_database.IsRecycleBinEnabled || message.ParentGroupId.Equals(_database.RecycleBinId) || isRecycleBin)
                {
                    _database.DeleteEntity(message.GroupId);
                }
                else
                {
                    await _database.AddGroup(_database.RecycleBinId, message.GroupId);
                }

                await _database.RemoveGroup(message.ParentGroupId, message.GroupId);

                if (isRecycleBin)
                {
                    _database.RecycleBinId = Constants.EmptyId;
                }
            }
Пример #3
0
            public async Task Handle(AddGroupCommand message)
            {
                if (!_database.IsOpen)
                {
                    throw new DatabaseClosedException();
                }

                await _database.AddGroup(message.ParentGroupId, message.GroupId);
            }