示例#1
0
        public void Backend_IdentityBackend_CreateNewStudent_Valid_User_Should_Pass()
        {
            //arrange
            var testUsername       = "******";
            var expectedClaimCount = 2;
            var testStudent        = new StudentModel
            {
                Name = testUsername,
                Id   = testUsername
            };

            var dummyUser = new ApplicationUser()
            {
                UserName = testUsername, Email = testUsername + "@seattleu.edu", Id = testUsername
            };

            var claimIdentity1 = new IdentityUserClaim()
            {
                ClaimType  = _5051.Models.UserRoleEnum.StudentUser.ToString(),
                ClaimValue = "True",
            };
            var claimIdentity2 = new IdentityUserClaim()
            {
                ClaimType  = "StudentID",
                ClaimValue = testStudent.Id,
            };

            dummyUser.Claims.Add(claimIdentity1);
            dummyUser.Claims.Add(claimIdentity2);

            var userStore       = new Mock <IUserStore <ApplicationUser> >();
            var createDummyUser = userStore
                                  .Setup(x => x.CreateAsync(dummyUser))
                                  .Returns(Task.FromResult(IdentityResult.Success));
            var passwordManager = userStore.As <IUserPasswordStore <ApplicationUser> >()
                                  .Setup(x => x.FindByIdAsync(testUsername))
                                  .ReturnsAsync(dummyUser);
            var claimsManager = userStore.As <IUserClaimStore <ApplicationUser> >();

            var userManager = new ApplicationUserManager(userStore.Object);

            var backend = new IdentityDataSourceMock(userManager, null);

            //act
            var result = backend.CreateNewStudent(testStudent);

            //assert
            Assert.AreEqual(testUsername, result.UserName, TestContext.TestName);
            Assert.AreEqual(expectedClaimCount, result.Claims.Count, TestContext.TestName);
        }
示例#2
0
        public void Backend_IdentityBackend_CreateNewStudent_Result_Failed_Should_Return_Null()
        {
            //arrange
            var testUsername = "******";
            var testStudent  = new StudentModel
            {
                Name = "",
                Id   = testUsername
            };


            var dummyUser = new ApplicationUser()
            {
                UserName = testUsername, Email = testUsername + "@seattleu.edu", Id = testUsername
            };

            var userStore       = new Mock <IUserStore <ApplicationUser> >();
            var createDummyUser = userStore
                                  .Setup(x => x.CreateAsync(dummyUser))
                                  .Returns(Task.FromResult(IdentityResult.Success));
            var passwordManager = userStore.As <IUserPasswordStore <ApplicationUser> >()
                                  .Setup(x => x.FindByIdAsync(testUsername))
                                  .ReturnsAsync(dummyUser);
            var claimsManager = userStore.As <IUserClaimStore <ApplicationUser> >();

            var userManager = new ApplicationUserManager(userStore.Object);

            var backend = new IdentityDataSourceMock(userManager, null);


            //act
            //pass in a bad password, causes create failure
            var result = backend.CreateNewStudent(testStudent);

            //assert
            Assert.IsNull(result, TestContext.TestName);
        }