Пример #1
0
        public async Task ItemsLockChanged_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedComment = RandomUtility.NextString();
            var actualValue     = dataBase.LockInfo.IsNotLocked;
            var actualComment   = string.Empty;

            await dataBaseContext.AddItemsLockChangedEventHandlerAsync(DataBaseContext_ItemsLockChanged);

            await dataBase.LockAsync(authentication, expectedComment);

            Assert.IsFalse(actualValue);
            Assert.AreEqual(expectedComment, actualComment);

            await dataBaseContext.RemoveItemsLockChangedEventHandlerAsync(DataBaseContext_ItemsLockChanged);

            await dataBase.UnlockAsync(authentication);

            Assert.IsFalse(actualValue);
            Assert.AreEqual(expectedComment, actualComment);

            void DataBaseContext_ItemsLockChanged(object sender, ItemsEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single();

                actualValue   = dataBase.LockInfo.IsNotLocked;
                actualComment = dataBase.LockInfo.Comment;
            }
        }
Пример #2
0
        public async Task Unloaded_TestAsync()
        {
            var authenitcation = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedDataBase = dataBase;
            var actualDataBase   = null as IDataBase;
            await dataBase.AddUnloadedEventHandlerAsync(DataBase_Unloaded);

            await dataBase.UnloadAsync(authenitcation);

            Assert.AreEqual(expectedDataBase, actualDataBase);
            await dataBase.LoadAsync(authenitcation);

            await dataBase.RemoveUnloadedEventHandlerAsync(DataBase_Unloaded);

            actualDataBase = null;
            await dataBase.UnloadAsync(authenitcation);

            Assert.IsNull(actualDataBase);

            void DataBase_Unloaded(object sender, EventArgs e)
            {
                if (sender is IDataBase dataBase)
                {
                    actualDataBase = dataBase;
                }
            }
        }
        public async Task EnterAsync_Arg0_Null_FailTestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.EnterAsync(null);
        }
Пример #4
0
        public async Task TaskCompleted_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var actualID = Guid.Empty;

            await dataBaseContext.AddTaskCompletedEventHandlerAsync(DataBaseContext_TaskCompleted);

            var taskID1 = await(dataBase.LoadAsync(authentication) as Task <Guid>);

            Assert.AreEqual(taskID1, actualID);

            await dataBaseContext.RemoveTaskCompletedEventHandlerAsync(DataBaseContext_TaskCompleted);

            var taskID2 = await(dataBase.UnloadAsync(authentication) as Task <Guid>);

            Assert.AreEqual(taskID1, actualID);
            Assert.AreNotEqual(Guid.Empty, taskID2);

            void DataBaseContext_TaskCompleted(object sender, TaskCompletedEventArgs e)
            {
                if (e.InvokeID == authentication.ID)
                {
                    actualID = e.TaskIDs.Single();
                }
            }
        }
Пример #5
0
        public async Task DataBaseInfoChanged_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var typeCategoryCollection = dataBase.GetService(typeof(ITypeCategoryCollection)) as ITypeCategoryCollection;
            var expectedDataBase       = dataBase;
            var actualDataBase         = null as IDataBase;
            await dataBase.AddDataBaseInfoChangedEventHandlerAsync(DataBase_DataBaseInfoChanged);

            var typeCategory = await typeCategoryCollection.GetRandomTypeCategoryAsync();

            await typeCategory.AddRandomCategoryAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            await dataBase.RemoveDataBaseInfoChangedEventHandlerAsync(DataBase_DataBaseInfoChanged);

            actualDataBase = null;
            await typeCategory.AddRandomCategoryAsync(authentication);

            Assert.IsNull(actualDataBase);

            void DataBase_DataBaseInfoChanged(object sender, EventArgs e)
            {
                if (object.Equals(sender, dataBase) == true)
                {
                    actualDataBase = sender as IDataBase;
                }
            }
        }
Пример #6
0
        public async Task LockChanged_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedDataBase = dataBase;
            var actualDataBase   = null as IDataBase;
            var comment          = RandomUtility.NextString();
            await dataBase.AddLockChangedEventHandlerAsync(DataBase_LockChanged);

            await dataBase.LockAsync(authentication, comment);

            await dataBase.UnlockAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            await dataBase.RemoveLockChangedEventHandlerAsync(DataBase_LockChanged);

            actualDataBase = null;
            await dataBase.LockAsync(authentication, comment);

            Assert.IsNull(actualDataBase);

            void DataBase_LockChanged(object sender, EventArgs e)
            {
                if (object.Equals(sender, dataBase) == true)
                {
                    actualDataBase = sender as IDataBase;
                }
            }
        }
Пример #7
0
        public async Task SetPublicAsync_Arg0_Expired_FailTestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Private | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.SetPublicAsync(expiredAuthentication);
        }
Пример #8
0
        public async Task AuthenticationLeft_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync();

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedID = authentication.ID;
            var actualID   = string.Empty;
            await dataBase.EnterAsync(authentication);

            await dataBase.AddAuthenticationLeftEventHandlerAsync(DataBase_AuthenticationLeft);

            await dataBase.LeaveAsync(authentication);

            await dataBase.EnterAsync(authentication);

            Assert.AreEqual(expectedID, actualID);

            await dataBase.RemoveAuthenticationLeftEventHandlerAsync(DataBase_AuthenticationLeft);

            actualID = string.Empty;
            await dataBase.LeaveAsync(authentication);

            Assert.AreEqual(string.Empty, actualID);

            void DataBase_AuthenticationLeft(object sender, AuthenticationEventArgs e)
            {
                if (object.Equals(sender, dataBase) == true)
                {
                    actualID = e.AuthenticationInfo.ID;
                }
            }
        }
        public async Task EnterAsync_Expired_FailTestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.EnterAsync(expiredAuthentication);
        }
Пример #10
0
        public async Task ItemsRenamed_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var oldDataBaseName      = dataBase.Name;
            var expectedDataBaseName = RandomUtility.NextName();
            var actualDataBaseName   = string.Empty;
            await dataBaseContext.AddItemsRenamedEventHandlerAsync(DataBaseContext_ItemsRenamed);

            await dataBase.RenameAsync(authentication, expectedDataBaseName);

            Assert.AreEqual(expectedDataBaseName, actualDataBaseName);

            await dataBaseContext.RemoveItemsRenamedEventHandlerAsync(DataBaseContext_ItemsRenamed);

            await dataBase.RenameAsync(authentication, oldDataBaseName);

            Assert.AreEqual(expectedDataBaseName, actualDataBaseName);

            void DataBaseContext_ItemsRenamed(object sender, ItemsRenamedEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single() as IDataBase;

                actualDataBaseName = dataBase.Name;
            }
        }
Пример #11
0
        public async Task ItemsStateChanged_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedDataBaseState = DataBaseState.Loaded;
            var actualDataBaseState   = dataBase.DataBaseState;

            await dataBaseContext.AddItemsStateChangedEventHandlerAsync(DataBaseContext_ItemsStateChanged);

            await dataBase.LoadAsync(authentication);

            Assert.AreEqual(expectedDataBaseState, actualDataBaseState);

            await dataBaseContext.RemoveItemsStateChangedEventHandlerAsync(DataBaseContext_ItemsStateChanged);

            await dataBase.UnloadAsync(authentication);

            Assert.AreEqual(expectedDataBaseState, actualDataBaseState);

            void DataBaseContext_ItemsStateChanged(object sender, ItemsEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single();

                actualDataBaseState = dataBase.DataBaseState;
            }
        }
Пример #12
0
        public async Task ItemsAccessChanged_TestAsync()
        {
            var authenticaiton = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var actualValue = dataBase.AccessInfo.IsPublic;

            await dataBaseContext.AddItemsAccessChangedEventHandlerAsync(DataBaseContext_ItemsAccessChanged);

            await dataBase.SetPrivateAsync(authenticaiton);

            Assert.IsFalse(actualValue);

            await dataBaseContext.RemoveItemsAccessChangedEventHandlerAsync(DataBaseContext_ItemsAccessChanged);

            await dataBase.SetPublicAsync(authenticaiton);

            Assert.IsFalse(actualValue);

            void DataBaseContext_ItemsAccessChanged(object sender, ItemsEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single() as IDataBase;

                actualValue = dataBase.AccessInfo.IsPublic;
            }
        }
Пример #13
0
        public async Task ItemsAuthenticationEntered_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync();

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.NotLocked | DataBaseFlags.Public);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedDataBase = dataBase;
            var expectedUserID   = authentication.ID;
            var actualDataBase   = null as IDataBase;
            var actualUserID     = string.Empty;

            await dataBaseContext.AddItemsAuthenticationEnteredEventHandlerAsync(DataBaseContext_ItemsAuthenticationEntered);

            await dataBase.EnterAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);
            Assert.AreEqual(expectedUserID, actualUserID);
            await dataBase.LeaveAsync(authentication);

            await dataBaseContext.RemoveItemsAuthenticationEnteredEventHandlerAsync(DataBaseContext_ItemsAuthenticationEntered);

            await dataBase.EnterAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);
            Assert.AreEqual(expectedUserID, actualUserID);

            void DataBaseContext_ItemsAuthenticationEntered(object sender, ItemsEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single();

                actualDataBase = dataBase;
                actualUserID   = e.InvokeID;
            }
        }
Пример #14
0
        public async Task ItemsReset_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.NotLocked | DataBaseFlags.Public);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedDataBase = dataBase;
            var actualDataBase   = null as IDataBase;
            await dataBaseContext.AddItemsResetEventHandlerAsync(DataBaseContext_ItemsReset);

            var transaction1 = await dataBase.BeginTransactionAsync(authentication);

            await transaction1.RollbackAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            await dataBaseContext.RemoveItemsResetEventHandlerAsync(DataBaseContext_ItemsReset);

            var transaction2 = await dataBase.BeginTransactionAsync(authentication);

            await transaction2.RollbackAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            void DataBaseContext_ItemsReset(object sender, ItemsEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single() as IDataBase;

                actualDataBase = dataBase;
            }
        }
Пример #15
0
        public async Task ItemsUnloaded_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter1 = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase1       = await dataBaseFilter1.GetDataBaseAsync(app);

            var dataBaseFilter2 = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked)
            {
                ExcludedDataBaseNames = new string[] { dataBase1.Name }
            };
            var dataBase2 = await dataBaseFilter2.GetDataBaseAsync(app);

            var expectedDataBase = dataBase1;
            var actualDataBase   = null as IDataBase;
            await dataBaseContext.AddItemsUnloadedEventHandlerAsync(DataBaseContext_ItemsUnloaded);

            await dataBase1.UnloadAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            await dataBaseContext.RemoveItemsUnloadedEventHandlerAsync(DataBaseContext_ItemsUnloaded);

            await dataBase2.UnloadAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            void DataBaseContext_ItemsUnloaded(object sender, ItemsEventArgs <IDataBase> e)
            {
                var dataBase = e.Items.Single() as IDataBase;

                actualDataBase = dataBase;
            }
        }
Пример #16
0
        public async Task TaskCompleted_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var expectedDataBase = dataBase;
            var actualDataBase   = null as IDataBase;
            await dataBase.AddTaskCompletedEventHandlerAsync(DataBase_TaskCompleted);

            await dataBase.SetPrivateAsync(authentication);

            Assert.AreEqual(expectedDataBase, actualDataBase);

            await dataBase.RemoveTaskCompletedEventHandlerAsync(DataBase_TaskCompleted);

            actualDataBase = null;
            await dataBase.SetPublicAsync(authentication);

            Assert.IsNull(actualDataBase);

            void DataBase_TaskCompleted(object sender, EventArgs e)
            {
                if (object.Equals(sender, dataBase) == true)
                {
                    actualDataBase = sender as IDataBase;
                }
            }
        }
Пример #17
0
        public async Task SetPrivateAsync_Private_FailTestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Private | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.SetPrivateAsync(authentication);
        }
Пример #18
0
        public async Task Contains_Dispatcher_FailTestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            dataBase.Contains(authentication);
        }
        public async Task RenameAsync_Expired_FailTestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var dataBaseName = await dataBaseContext.GenerateNewDataBaseNameAsync();

            await dataBase.RenameAsync(expiredAuthentication, dataBaseName);
        }
Пример #20
0
        public async Task GetMetaData_Dispatcher_FailTestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync();

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            dataBase.GetMetaData();
        }
        public async Task RenameAsync_Arg0_Null_FailTestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var dataBaseName = await dataBaseContext.GenerateNewDataBaseNameAsync();

            await dataBase.RenameAsync(null, dataBaseName);
        }
        public async Task LoadAsync_Member_FailTestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Member);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.LoadAsync(authentication);
        }
        public async Task RenameAsync_Arg1_SameName_FailTestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.NotLoaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.RenameAsync(authentication, dataBase.Name);
        }
        public async Task EnterAsync_Guest_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Guest);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.EnterAsync(authentication);
        }
        public async Task BeginTransactionAsync_Admin_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.BeginTransactionAsync(authentication);
        }
        private async Task EnterAsync_Locked_NotLocker_FailTestAsync(Authority authority)
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.Locked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var lockInfo       = dataBase.LockInfo;
            var authentication = await this.TestContext.LoginRandomAsync(authority, item => item.ID != lockInfo.ID);

            await dataBase.EnterAsync(authentication);
        }
        private async Task EnterAsync_Private_AccessTypeNone_FailTestAsync(Authority authority)
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Private | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var accessInfo     = dataBase.AccessInfo;
            var authentication = await this.TestContext.LoginRandomAsync(authority, item => accessInfo.GetAccessType(item.ID) == AccessType.None);

            await dataBase.EnterAsync(authentication);
        }
        public async Task EnterAsync_Locked_Admin_Locker_TestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.Locked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var lockInfo       = dataBase.LockInfo;
            var authentication = await this.TestContext.LoginAsync(lockInfo.ID);

            await dataBase.EnterAsync(authentication);
        }
        public async Task EnterAsync_Private_Admin_Owner_TestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Private | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var accessInfo     = dataBase.AccessInfo;
            var authentication = await this.TestContext.LoginAsync(accessInfo.ID);

            await dataBase.EnterAsync(authentication);
        }
        public async Task GetLogAsync_Expired_FailTestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked)
            {
                Settings = DataBaseSettings.Default
            };
            var dataBase = await dataBaseFilter.GetDataBaseAsync(app);

            await dataBase.GetLogAsync(expiredAuthentication, string.Empty);
        }