コード例 #1
0
        public async void DeleteUserProfile_UserNotAdmin()
        {
            var users = new List <UserProfile>()
            {
                new UserProfile {
                    Id = "6315DEBD-4EFB-47D9-80B4-B3C42DB72059"
                },
                new UserProfile {
                    Id = "FCB70CC5-D9E3-4396-B38E-1F9BB4DB2381"
                }
            };
            var prevCount    = users.Count;
            var store        = new Mock <IUserRoleStore <UserProfile> >();
            var userToDelete = users.Last();

            store.Setup(s => s.FindByIdAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(userToDelete);
            store.Setup(s => s.GetRolesAsync(It.IsAny <UserProfile>(), It.IsAny <CancellationToken>())).ReturnsAsync(new List <string>()
            {
                "user"
            });
            store.Setup(s => s.DeleteAsync(It.IsAny <UserProfile>(), It.IsAny <CancellationToken>())).ReturnsAsync(IdentityResult.Success).Callback(() => users.Remove(userToDelete));
            var userManager           = new UserManager <UserProfile>(store.Object, null, null, null, null, null, null, null, null);
            var administrationService = new AdministrationService(null, userManager);

            await administrationService.DeleteUserProfile("");

            Assert.NotEqual(prevCount, users.Count);
            Assert.DoesNotContain(userToDelete, users);
        }
コード例 #2
0
        public async void DeleteUserProfile_UserAdmin()
        {
            var users = new List <UserProfile>()
            {
                new UserProfile {
                    Id = "D3EF52BC-58FD-42EE-97E0-D110A0A9707A"
                },
                new UserProfile {
                    Id = "4F3743D9-214D-4CC4-BA71-204F34D17EAC"
                }
            };
            var prevCount    = users.Count;
            var store        = new Mock <IUserRoleStore <UserProfile> >();
            var userToDelete = users.Last();

            store.Setup(s => s.FindByIdAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(userToDelete);
            store.Setup(s => s.GetRolesAsync(It.IsAny <UserProfile>(), It.IsAny <CancellationToken>())).ReturnsAsync(new List <string>()
            {
                "admin"
            });
            store.Setup(s => s.DeleteAsync(It.IsAny <UserProfile>(), It.IsAny <CancellationToken>())).ReturnsAsync(IdentityResult.Success).Callback(() => users.Remove(userToDelete));
            var userManager           = new UserManager <UserProfile>(store.Object, null, null, null, null, null, null, null, null);
            var administrationService = new AdministrationService(null, userManager);

            await administrationService.DeleteUserProfile("");

            Assert.Equal(prevCount, users.Count);
            Assert.Contains(userToDelete, users);
        }
コード例 #3
0
        public async void DeleteUserProfile_UserNotFound()
        {
            var store = new Mock <IUserRoleStore <UserProfile> >();

            store.Setup(s => s.FindByIdAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(() => null);
            store.Setup(s => s.GetRolesAsync(null, It.IsAny <CancellationToken>())).ThrowsAsync(new ArgumentNullException());
            store.Setup(s => s.DeleteAsync(null, It.IsAny <CancellationToken>())).ThrowsAsync(new ArgumentNullException());
            var userManager           = new UserManager <UserProfile>(store.Object, null, null, null, null, null, null, null, null);
            var administrationService = new AdministrationService(null, userManager);

            await Assert.ThrowsAsync(new ArgumentNullException().GetType(), () => administrationService.DeleteUserProfile(""));
        }