コード例 #1
0
        public async Task Throw_MagicExeption_IfNullValue_AppUserOccurs()
        {
            var options = TestUtils.GetOptions(nameof(Throw_CorrectMagicExeption_IfNullValue_AppUserOccurs));

            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 result = await Assert.ThrowsExceptionAsync <MagicException>
                                 (async() => await sut.GetUserByUsernameAsync("13333"));
            }
        }
コード例 #2
0
        public async Task Throw_CorrectMagicExeption_IfNullValue_UserNamePassed()
        {
            var options = TestUtils.GetOptions(nameof(Throw_CorrectMagicExeption_IfNullValue_UserNamePassed));

            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 result = await Assert.ThrowsExceptionAsync <MagicException>
                                 (async() => await sut.GetUserByUsernameAsync(null));

                Assert.AreEqual("UserName cannot be null!", result.Message);
            }
        }
コード例 #3
0
        public async Task Return_AppUserWithSameUsername_IfThereIsOne()
        {
            var options = TestUtils.GetOptions(nameof(Return_AppUserWithSameUsername_IfThereIsOne));

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

            using (var arrangeContext = new CMContext(options))
            {
                //1
                arrangeContext.Users.Add(new AppUser {
                    Id = "1", UserName = "******"
                });

                //2
                arrangeContext.Users.Add(new AppUser {
                    Id = "2", UserName = "******"
                });

                //3
                arrangeContext.Users.Add(new AppUser {
                    Id = "3", UserName = "******", Email = "*****@*****.**"
                });

                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new AppUserServices(assertContext, userManagerMocked.Object);

                var result = await sut.GetUserByUsernameAsync("user3");

                Assert.AreEqual("user3", result.UserName);
                Assert.AreEqual("3", result.Id);
                Assert.AreEqual("*****@*****.**", result.Email);
                Assert.IsInstanceOfType(result, typeof(AppUser));
            }
        }