Пример #1
0
        public async Task ThrowMagicExeption_IfAppUser_DoesnotExist()
        {
            var options = TestUtils.GetOptions(nameof(ThrowMagicExeption_IfAppUser_DoesnotExist));

            var userStoreMocked   = new Mock <IUserStore <AppUser> >();
            var userManagerMocked =
                new Mock <UserManager <AppUser> >
                    (userStoreMocked.Object, null, null, null, null, null, null, null, null);

            using (var assertContext = new CMContext(options))
            {
                var role = new AppRole {
                    Id = "1", Name = "Administrator", NormalizedName = "ADMINISTRATOR"
                };

                assertContext.Roles.Add(role);
                assertContext.UserRoles.Add(
                    new IdentityUserRole <string>
                {
                    RoleId = "1",
                    UserId = "1"
                });
                await assertContext.SaveChangesAsync();

                var sut = new AppUserServices(assertContext, userManagerMocked.Object);
                var ex  = await Assert.ThrowsExceptionAsync <MagicException>
                              (async() => await sut.GetAdmin());
            }
        }
Пример #2
0
        public async Task ThrowMagicExeption_IfAppRole_DoesnotExist()
        {
            var options = TestUtils.GetOptions(nameof(ThrowMagicExeption_IfAppRole_DoesnotExist));

            var userStoreMocked   = new Mock <IUserStore <AppUser> >();
            var userManagerMocked =
                new Mock <UserManager <AppUser> >
                    (userStoreMocked.Object, null, null, null, null, null, null, null, null);

            using (var assertContext = new CMContext(options))
            {
                var sut = new AppUserServices(assertContext, userManagerMocked.Object);
                var ex  = await Assert.ThrowsExceptionAsync <MagicException>
                              (async() => await sut.GetAdmin());
            }
        }
Пример #3
0
        public async Task Return_AppUser_WithRoleAdministrator_WhenEverythingIsOk()
        {
            var options = TestUtils.GetOptions(nameof(Return_AppUser_WithRoleAdministrator_WhenEverythingIsOk));

            var userStoreMocked   = new Mock <IUserStore <AppUser> >();
            var userManagerMocked =
                new Mock <UserManager <AppUser> >
                    (userStoreMocked.Object, null, null, null, null, null, null, null, null);

            using (var assertContext = new CMContext(options))
            {
                var member = new AppUser {
                    Id = "2", UserName = "******"
                };
                var manager = new AppUser {
                    Id = "1", UserName = "******"
                };
                var admin = new AppUser {
                    Id = "3", UserName = "******"
                };
                assertContext.Users.Add(admin);
                assertContext.Users.Add(member);
                assertContext.Users.Add(manager);
                var role = new AppRole {
                    Id = "1", Name = "Administrator", NormalizedName = "ADMINISTRATOR"
                };

                assertContext.Roles.Add(role);
                assertContext.UserRoles.Add(
                    new IdentityUserRole <string>
                {
                    RoleId = "1",
                    UserId = "3"
                });
                await assertContext.SaveChangesAsync();

                var sut    = new AppUserServices(assertContext, userManagerMocked.Object);
                var result = await sut.GetAdmin();

                Assert.AreEqual("3", result.Id);
                Assert.AreEqual("Admin", result.UserName);
                Assert.IsInstanceOfType(result, typeof(AppUser));
            }
        }
Пример #4
0
        public async Task ThrowCorrectMagicExeption_IfUserRoleConnection_DoesnotExist()
        {
            var options = TestUtils.GetOptions(nameof(ThrowMagicExeption_IfUserRoleConnection_DoesnotExist));

            var userStoreMocked   = new Mock <IUserStore <AppUser> >();
            var userManagerMocked =
                new Mock <UserManager <AppUser> >
                    (userStoreMocked.Object, null, null, null, null, null, null, null, null);

            using (var assertContext = new CMContext(options))
            {
                var role = new AppRole {
                    Name = "Administrator", NormalizedName = "ADMINISTRATOR"
                };
                assertContext.Roles.Add(role);
                await assertContext.SaveChangesAsync();

                var sut = new AppUserServices(assertContext, userManagerMocked.Object);
                var ex  = await Assert.ThrowsExceptionAsync <MagicException>
                              (async() => await sut.GetAdmin());

                Assert.AreEqual("UserRole cannot be null!", ex.Message);
            }
        }