コード例 #1
0
        public async void TestAdminLoginValidModelStateButNotAnExistingUser()
        {
            MockStoreContexts mocks = new MockStoreContexts();

            mocks.UserManager.Setup(x => x.CreateAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);
            mocks.UserManager.Setup(x => x.FindByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(mocks.User);
            mocks.UserManager.Setup(x => x.IsInRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(true);
            mocks.UserManager.Setup(x => x.AddToRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);

            mocks.SignInManager.Setup(x => x.PasswordSignInAsync(
                                          It.IsAny <string>(), It.IsAny <string>(),
                                          It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Failed);

            await mocks.UserManager.Object.CreateAsync(mocks.User, "Abcdefg1!");

            await mocks.UserManager.Object.AddToRoleAsync(mocks.User, ApplicationRoles.Admin);

            AdminLoginModel alm = new AdminLoginModel(mocks.UserManager.Object,
                                                      mocks.SignInManager.Object,
                                                      mocks.Configuration.Object)
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            MockValidation.CheckValidation(alm);
            var result = alm.OnPost().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #2
0
        public void TestPasswordAndConfirmPasswordDoMatchButInvalidModel()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Password        = "******",
                ConfirmPassword = "******"
            };

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #3
0
        public async void TestDetailsPageOnPostInvalidModel()
        {
            using (var context = new UserDbContext(MockRSVPUserDb.TestRSVPDbContextOptions()))
            {
                DetailsModel dm = new DetailsModel(context);

                //Checking DB is actually empty
                var result = await context.Users.ToListAsync();

                Assert.Empty(result);

                MockValidation.CheckValidation(dm);
                var page = await dm.OnPost();

                Assert.IsType <PageResult>(page);
            }
        }
コード例 #4
0
        public void ContactModelOnPostInvalidModelState()
        {
            var EmailSender = new MockEmailSender();

            ContactModel contact = new ContactModel(EmailSender)
            {
                FirstName         = "Test Name",
                Phone             = 1234567890,
                Reason            = EmailMessages.ContactType.Donate,
                AdditionalRemarks = "Additional Remarks"
            };

            //Check validity of the model
            MockValidation.CheckValidation(contact);
            var result = contact.OnPost().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #5
0
        public void TestPasswordMatchingAndValidModelStateButNoUserIsFound()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Name            = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            mocks.UserManager.Setup(x => x.FindByNameAsync(It.IsAny <string>()))
            .ReturnsAsync((ApplicationUser)null);

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #6
0
        public void ContactModelOnPostValidModelState()
        {
            var EmailSender = new MockEmailSender();

            ContactModel contact = new ContactModel(EmailSender)
            {
                FirstName         = "Test Name",
                Email             = "*****@*****.**",
                Phone             = 1234567890,
                Reason            = EmailMessages.ContactType.Donate,
                AdditionalRemarks = "Additional Remarks"
            };

            //Check validity of the model
            MockValidation.CheckValidation(contact);
            var result = contact.OnPost().Result;
            RedirectToPageResult check = (RedirectToPageResult)result;

            Assert.Equal("/", check.PageName);
        }
コード例 #7
0
        public async void TestAddUserPageTryingToAddUserWithInvalidModelState()
        {
            using (var context = new UserDbContext(MockRSVPUserDb.TestRSVPDbContextOptions()))
            {
                Add_UserModel aum = new Add_UserModel(context)
                {
                    Name        = "Test User",
                    PhoneNumber = "0123456789"
                };

                //Checking DB is actually empty
                var result = await context.Users.ToListAsync();

                Assert.Empty(result);

                //Checking Validation of the Model
                MockValidation.CheckValidation(aum);
                var page = aum.OnPost().Result;
                Assert.IsType <PageResult>(page);
            }
        }
コード例 #8
0
        public async void TestSignUpPageWithInvalidModelState()
        {
            using (var context = new UserDbContext(MockRSVPUserDb.TestRSVPDbContextOptions()))
            {
                MockEmailSender EmailSender = new MockEmailSender();
                SignupModel     sum         = new SignupModel(context, EmailSender)
                {
                    Name      = "Test Name",
                    Email     = "fake@email",
                    IsVeteran = true
                };

                //Checking DB is actually empty
                var result = await context.Users.ToListAsync();

                Assert.Empty(result);

                MockValidation.CheckValidation(sum);
                var page = sum.OnPost().Result;
                Assert.IsType <PageResult>(page);
            }
        }
コード例 #9
0
        public void TestPasswordMatchingAndValidModelStateAndUserButFailedToUpdate()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Name            = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            mocks.UserManager.Setup(x => x.FindByNameAsync(It.IsAny <string>()))
            .ReturnsAsync(new ApplicationUser {
                PasswordHash = "abcdefg"
            });
            mocks.UserManager.Setup(x => x.UpdateAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(IdentityResult.Failed());

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #10
0
        public async void TestAddUserPageAddingAUserWithValidModelState()
        {
            using (var context = new UserDbContext(MockRSVPUserDb.TestRSVPDbContextOptions()))
            {
                Add_UserModel aum = new Add_UserModel(context)
                {
                    Agree                = true,
                    Name                 = "Test User",
                    Email                = "*****@*****.**",
                    PhoneNumber          = "0123456789",
                    IsVeteran            = true,
                    PreferredTime        = false,
                    IsWashingtonResident = true,
                    ChooseMaritalStatus  = MaritalStatus.SingleAndNeverDivorced,
                    SpouseName           = "N/A",
                    HasChildren          = false,
                    IsCurrentlyPregnant  = false,
                    MinorChildName       = "N/A",
                    ContRemBeneficiary   = WhoToInheritEstate.OtherPerson,
                    PersonToInherit      = WhoToInheritEstate.OtherPerson,
                    PersonalRep          = WhoToInheritEstate.OtherPerson,
                };

                //Checking DB is actually empty
                var result = await context.Users.ToListAsync();

                Assert.Empty(result);

                MockValidation.CheckValidation(aum);
                var page = await aum.OnPost();

                RedirectToPageResult check = (RedirectToPageResult)page;
                result = await context.Users.ToListAsync();

                Assert.Single(result);
                Assert.Equal("/Dashboard", check.PageName);
            }
        }
コード例 #11
0
        public async void TestAdminLoginValidStateAndAdminUsesDefaultPassword()
        {
            MockStoreContexts mocks = new MockStoreContexts();

            mocks.UserManager.Setup(x => x.CreateAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);
            mocks.UserManager.Setup(x => x.FindByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(mocks.User);
            mocks.UserManager.Setup(x => x.IsInRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(true);
            mocks.UserManager.Setup(x => x.AddToRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);

            mocks.SignInManager.Setup(x => x.PasswordSignInAsync(
                                          It.IsAny <string>(), It.IsAny <string>(),
                                          It.IsAny <bool>(), It.IsAny <bool>()))
            .ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success);

            mocks.Configuration.Setup(x => x[It.IsAny <string>()])
            .Returns("Test2!");
            await mocks.UserManager.Object.CreateAsync(mocks.User, "Test2!");

            await mocks.UserManager.Object.AddToRoleAsync(mocks.User, ApplicationRoles.Admin);

            AdminLoginModel alm = new AdminLoginModel(mocks.UserManager.Object,
                                                      mocks.SignInManager.Object,
                                                      mocks.Configuration.Object)
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            MockValidation.CheckValidation(alm);
            var result = alm.OnPost().Result;
            RedirectToPageResult check = (RedirectToPageResult)result;

            Assert.Equal("/Change_Password", check.PageName);
        }
コード例 #12
0
        public void TestPasswordMatchingAndValidModelStateAndUserAndUpdates()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Name            = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            mocks.UserManager.Setup(x => x.FindByNameAsync(It.IsAny <string>()))
            .ReturnsAsync(new ApplicationUser {
                PasswordHash = "abcdefg"
            });
            mocks.UserManager.Setup(x => x.UpdateAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(IdentityResult.Success);

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;
            RedirectToPageResult check = (RedirectToPageResult)result;

            Assert.Equal("/Dashboard", check.PageName);
        }
コード例 #13
0
        public async void TestDetailsPageOnPostValidModelAndCheckedOut()
        {
            using (var context = new UserDbContext(MockRSVPUserDb.TestRSVPDbContextOptions()))
            {
                DetailsModel dm   = new DetailsModel(context);
                RSVPUser     user = new RSVPUser
                {
                    Name                 = "Test User",
                    Email                = "fake@email",
                    PhoneNumber          = "0123456789",
                    IsVeteran            = true,
                    IsWashingtonResident = true,
                    PreferredTime        = false,
                    ChooseMaritalStatus  = MaritalStatus.FirstMarriage,
                    SpouseName           = "N/A",
                    HasChildren          = false,
                    IsCurrentlyPregnant  = false,
                    MinorChildName       = "n/a",
                    ContRemBeneficiary   = WhoToInheritEstate.OtherPerson,
                    PersonToInherit      = WhoToInheritEstate.OtherPerson,
                    PersonalRep          = WhoToInheritEstate.OtherPerson,
                    CheckedIn            = false
                };

                //Checking DB is actually empty
                var result = await context.Users.ToListAsync();

                Assert.Empty(result);

                await context.Users.AddAsync(user);

                await context.SaveChangesAsync();

                result = await context.Users.ToListAsync();

                dm.ID                   = result[0].ID;
                dm.Name                 = result[0].Name;
                dm.Phone                = result[0].PhoneNumber;
                dm.Email                = result[0].Email;
                dm.IsVeteran            = result[0].IsVeteran;
                dm.PreferredTime        = result[0].PreferredTime;
                dm.IsWashingtonResident = result[0].IsWashingtonResident;
                dm.ChooseMaritalStatus  = result[0].ChooseMaritalStatus;
                dm.SpouseName           = result[0].SpouseName;
                dm.HasChildren          = result[0].HasChildren;
                dm.IsCurrentlyPregnant  = result[0].IsCurrentlyPregnant;
                dm.MinorChildName       = result[0].MinorChildName;
                dm.ContRemBeneficiary   = result[0].ContRemBeneficiary;
                dm.PersonToInherit      = result[0].PersonToInherit;
                dm.PersonalRep          = result[0].PersonalRep;
                dm.CheckedIn            = result[0].CheckedIn;

                MockValidation.CheckValidation(dm);
                var page = await dm.OnPost();

                result = await context.Users.ToListAsync();

                Assert.True(result[0].CheckedIn);
                Assert.IsType <PageResult>(page);
            }
        }