public void GetAdminById_ThrowsException_InvalidId()
        {
            adminsService = new AdminsService(adminRepositoryMock.Object, carRepositoryMock.Object,
                                              ownerRepositoryMock.Object, ruleRepositoryMock.Object);

            var invalidAdminId = "invalid";

            Assert.ThrowsException <Exception>(() =>
            {
                adminsService.GetAdminById(invalidAdminId);
            });
        }
        public void GetAdminById_Returns_AdminExists()
        {
            var existingAdminId = Guid.NewGuid();

            var admin = new Admin
            {
                Id        = existingAdminId,
                UserId    = Guid.NewGuid(),
                FirstName = "firstName",
                LastName  = "lastName"
            };

            adminRepositoryMock.Setup(adminRepositoryMock => adminRepositoryMock.GetAdminByUserId(existingAdminId)).Returns(admin);

            adminsService = new AdminsService(adminRepositoryMock.Object, carRepositoryMock.Object,
                                              ownerRepositoryMock.Object, ruleRepositoryMock.Object);

            var searchedAdmin = adminsService.GetAdminById(existingAdminId.ToString());

            Assert.IsNotNull(searchedAdmin);
        }
        public void GetAdminById_ThrowsEntityNotFound_AdminDoesntExist()
        {
            var nonExistingAdmin = Guid.NewGuid().ToString();
            var existingAdmin    = Guid.NewGuid();

            var admin = new Admin {
                Id        = existingAdmin,
                FirstName = "firstName",
                LastName  = "lastName",
                Email     = "*****@*****.**"
            };

            adminRepositoryMock.Setup(adminRepositoryMock => adminRepositoryMock.GetAdminByUserId(existingAdmin)).Returns(admin);

            adminsService = new AdminsService(adminRepositoryMock.Object, carRepositoryMock.Object,
                                              ownerRepositoryMock.Object, ruleRepositoryMock.Object);

            Assert.ThrowsException <EntityNotFoundException>(() =>
            {
                adminsService.GetAdminById(nonExistingAdmin);
            });
        }
示例#4
0
        public async Task <IActionResult> EditAccount()
        {
            var userId = _userManager.GetUserId(User);

            var user_identity = await _userManager.FindByIdAsync(userId);

            var user_email = await _userManager.GetEmailAsync(user_identity);

            var user_username = await _userManager.GetUserNameAsync(user_identity);

            var admin = adminsService.GetAdminById(userId);

            AdminEditAccountViewModel adminEditAccountViewModel = new AdminEditAccountViewModel
            {
                UserId    = userId,
                FirstName = admin.FirstName,
                LastName  = admin.LastName,
                Email     = user_email,
                Username  = user_username
            };

            return(View(adminEditAccountViewModel));
        }