public async void AddUserWithAgreement()
        {
            var userName   = GenerateRandomUserName();
            var signedDate = RemoveMilliseconds(DateTime.Now);
            var profile    = new S4UserProfile()
            {
                FirstName    = "Dilbert",
                LastName     = "Dewberry",
                EmailAddress = $"{userName}@ufl.edu",
                Agency       = new Agency()
                {
                    AgencyId = 1150200
                }                                            // UF PD
            };
            var userAgreement = new UserAgreement()
            {
                AgreementName  = "User Agreement",
                SignedDate     = signedDate,
                ExpirationDate = signedDate.AddYears(1)
            };

            profile.Agreements.Add(userAgreement);
            await CreateBasicUser(userName, "secret", profile);

            var user = await _userManager.FindByNameAsync(userName);

            Assert.NotEmpty(user.Profile.Agreements);
            userAgreement = user.Profile.Agreements[0];
            Assert.Equal("User Agreement", userAgreement.AgreementName);
            Assert.Equal(signedDate, userAgreement.SignedDate);
            Assert.Equal(signedDate.AddYears(1), userAgreement.ExpirationDate);
        }
        public async void UpdateAgency()
        {
            var userName = GenerateRandomUserName();
            var profile  = new S4UserProfile()
            {
                FirstName    = "Dilbert",
                LastName     = "Dewberry",
                EmailAddress = $"{userName}@ufl.edu",
                Agency       = new Agency()
                {
                    AgencyId = 1150200
                }                                            // UF PD
            };

            await CreateBasicUser(userName, "secret", profile);

            var user = await _userManager.FindByNameAsync(userName);

            user.Profile.Agency = new Agency()
            {
                AgencyId = 1340200
            };                                                         // FSU PD
            await _userManager.UpdateAsync(user);

            user = await _userManager.FindByNameAsync(userName);

            Assert.Equal("Florida State University Police Department", user.Profile.Agency.AgencyName);
        }
        public async void UnsetVendorCompany()
        {
            var userName = GenerateRandomUserName();
            var profile  = new S4UserProfile()
            {
                FirstName    = "Dilbert",
                LastName     = "Dewberry",
                EmailAddress = $"{userName}@ufl.edu",
                Agency       = new Agency()
                {
                    AgencyId = 1150200
                },                                            // UF PD
                VendorCompany = new Vendor {
                    VendorId = 69
                }                                            // UF
            };

            await CreateBasicUser(userName, "secret", profile);

            var user = await _userManager.FindByNameAsync(userName);

            user.Profile.VendorCompany = null;
            await _userManager.UpdateAsync(user);

            user = await _userManager.FindByNameAsync(userName);

            Assert.Null(user.Profile.VendorCompany);
        }
        public async void UpdateVendorCompany()
        {
            var userName = GenerateRandomUserName();
            var profile  = new S4UserProfile()
            {
                FirstName    = "Dilbert",
                LastName     = "Dewberry",
                EmailAddress = $"{userName}@ufl.edu",
                Agency       = new Agency()
                {
                    AgencyId = 1150200
                },                                            // UF PD
                VendorCompany = new Vendor {
                    VendorId = 69
                }                                            // UF
            };

            await CreateBasicUser(userName, "secret", profile);

            var user = await _userManager.FindByNameAsync(userName);

            user.Profile.VendorCompany = new Vendor {
                VendorId = 73
            };                                                         // USF
            await _userManager.UpdateAsync(user);

            user = await _userManager.FindByNameAsync(userName);

            Assert.Equal("University of South Florida", user.Profile.VendorCompany.VendorName);
        }
        public async void UpdateBasicProfile()
        {
            var userName  = GenerateRandomUserName();
            var startDate = RemoveMilliseconds(DateTime.Now);
            var profile   = new S4UserProfile()
            {
                FirstName             = "Dilbert",
                LastName              = "Dewberry",
                AccountExpirationDate = startDate.AddYears(1),
                AccountStartDate      = startDate,
                EmailAddress          = $"{userName}@ufl.edu",
                SuffixName            = "Jr.",
                ForcePasswordChange   = true,
                TimeLimitedAccount    = true,
                CrashReportAccess     = CrashReportAccess.After60Days,
                Agency = new Agency()
                {
                    AgencyId = 1150200
                }                                            // UF PD
            };

            await CreateBasicUser(userName, "secret", profile);

            var user = await _userManager.FindByNameAsync(userName);

            user.Profile.FirstName = "Dogbert";
            user.Profile.LastName  = "Doolittle";
            var newStartDate = startDate.AddDays(5);

            user.Profile.AccountStartDate      = newStartDate;
            user.Profile.AccountExpirationDate = newStartDate.AddYears(1);
            user.Profile.EmailAddress          = "*****@*****.**";
            user.Profile.SuffixName            = "Sr.";
            user.Profile.ForcePasswordChange   = false;
            user.Profile.TimeLimitedAccount    = false;
            user.Profile.CrashReportAccess     = CrashReportAccess.NoAccess;
            await _userManager.SetEmailAsync(user, user.Profile.EmailAddress);

            user = await _userManager.FindByNameAsync(userName);

            Assert.NotNull(user.Profile);
            Assert.Equal("Dogbert", user.Profile.FirstName);
            Assert.Equal("Doolittle", user.Profile.LastName);
            Assert.Equal(newStartDate.AddYears(1), user.Profile.AccountExpirationDate);
            Assert.Equal(newStartDate, user.Profile.AccountStartDate);
            Assert.Equal("*****@*****.**", user.Profile.EmailAddress);
            Assert.Equal("Sr.", user.Profile.SuffixName);
            Assert.False(user.Profile.ForcePasswordChange);
            Assert.False(user.Profile.TimeLimitedAccount);
            Assert.Equal(CrashReportAccess.NoAccess, user.Profile.CrashReportAccess);
        }
        private async Task <S4IdentityUser <S4UserProfile> > CreateBasicUser(
            string userName,
            string password,
            S4UserProfile profile)
        {
            var user = new S4IdentityUser <S4UserProfile>(userName);

            user.Profile = profile;
            await _userManager.CreateAsync(user, password);

            await _userManager.SetEmailAsync(user, profile.EmailAddress);

            return(user);
        }
        public async void UpdateCounties()
        {
            var userName = GenerateRandomUserName();
            var profile  = new S4UserProfile()
            {
                FirstName    = "Dilbert",
                LastName     = "Dewberry",
                EmailAddress = $"{userName}@ufl.edu",
                Agency       = new Agency()
                {
                    AgencyId = 1150200
                }                                            // UF PD
            };

            profile.ViewableCounties.Add(new UserCounty()
            {
                CountyCode = 14, // Marion
                CanEdit    = false
            });
            await CreateBasicUser(userName, "secret", profile);

            var user = await _userManager.FindByNameAsync(userName);

            user.Profile.ViewableCounties.Add(new UserCounty()
            {
                CountyCode = 11, // Alachua
                CanEdit    = true
            });
            await _userManager.UpdateAsync(user);

            user = await _userManager.FindByNameAsync(userName);

            Assert.Equal(2, user.Profile.ViewableCounties.Count);
            Assert.Equal(1, user.Profile.EditableCounties.Count);
            var alachua = user.Profile.ViewableCounties.First(c => c.CountyName == "Alachua");
            var marion  = user.Profile.ViewableCounties.First(c => c.CountyName == "Marion");

            Assert.Equal(true, alachua.CanEdit);
            Assert.Equal(false, marion.CanEdit);
            Assert.True(user.Profile.EditableCounties.Any(c => c.CountyName == "Alachua"));
        }