Пример #1
0
        public async Task ItemsAuthenticationLeft_TestAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked);
            var dataBase       = await dataBaseFilter.GetDataBaseAsync(app);

            var authentications = await dataBase.GetAuthenticationInfosAsync();

            var authenticationIDs = authentications.Select(item => item.ID).ToArray();
            var authentication    = await this.TestContext.LoginRandomAsync(item => authenticationIDs.Contains(item.ID) == false);

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

            await dataBase.EnterAsync(authentication);

            await dataBaseContext.AddItemsAuthenticationLeftEventHandlerAsync(DataBaseContext_ItemsAuthenticationLeft);

            await dataBase.LeaveAsync(authentication);

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

            await dataBase.EnterAsync(authentication);

            await dataBaseContext.RemoveItemsAuthenticationLeftEventHandlerAsync(DataBaseContext_ItemsAuthenticationLeft);

            await dataBase.LeaveAsync(authentication);

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

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

                actualDataBase = dataBase;
                actualUserID   = e.InvokeID;
            }
        }