コード例 #1
0
        public async Task UsersKicked_TestAsync()
        {
            var cremaHost      = app.GetService(typeof(ICremaHost)) as ICremaHost;
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var authentication1 = await this.TestContext.LoginRandomAsync();

            var authentication2 = await this.TestContext.LoginRandomAsync();

            var user1 = await userCollection.GetUserAsync(authentication1.ID);

            var user2 = await userCollection.GetUserAsync(authentication2.ID);

            var actualUserID    = string.Empty;
            var actualMessage   = string.Empty;
            var expectedMessage = RandomUtility.NextString();
            await userCollection.AddUsersKickedEventHandlerAsync(UserCollection_UsersKicked);

            await user1.KickAsync(authentication, expectedMessage);

            Assert.AreEqual(user1.ID, actualUserID);
            Assert.AreEqual(expectedMessage, actualMessage);
            await userCollection.RemoveUsersKickedEventHandlerAsync(UserCollection_UsersKicked);

            await user2.KickAsync(authentication, RandomUtility.NextString());

            Assert.AreEqual(user1.ID, actualUserID);
            Assert.AreEqual(expectedMessage, actualMessage);
            Assert.AreNotEqual(user2.ID, actualUserID);

            void UserCollection_UsersKicked(object sender, ItemsEventArgs <IUser> e)
            {
                var user = e.Items.Single();

                actualUserID  = user.ID;
                actualMessage = (e.MetaData as string[]).Single();
            }
        }