Пример #1
0
        public async void UserServiceGetUserTest()
        {
            //arrange
            var testGroups = _groupListNames.Select(x => new Group {
                Name = x
            });
            var mockTestGroups = testGroups.AsQueryable().BuildMock();

            _mockUserManager.Setup(x => x.GetRolesAsync(_testUser)).Returns(Task.FromResult(_groupListNames));
            _mockRoleManager.Setup(x => x.Roles).Returns(mockTestGroups.Object);

            var userService =
                MockUserService.GetMockUserService(
                    signInManager: MockSignInManager.GetMockSignInManager(userManager: _mockUserManager.Object).Object,
                    userManager: _mockUserManager.Object,
                    roleManager: _mockRoleManager.Object
                    ).Object;

            // act
            var result = await userService.GetUser(_testUser);

            // assert
            result.Groups
            .Should()
            .HaveCount(testGroups.Count());

            result.Groups.Select(x => x.Name).Should().Equal(_groupListNames);

            Assert.Equal(_testUser.UserName, result.Email);
        }
Пример #2
0
        public void UserServiceRegisterDuplicateUserTest()
        {
            // arrange
            // create a registration model with same email as the test user
            var registrationModel = new RegisterModel
            {
                Email    = _testUser.Email,
                Password = _fixture.Create <string>(),
                Groups   = _groupListNames
            };

            _mockUserManager
            .Setup(x => x.FindByEmailAsync(_testUser.Email))
            .Returns(Task.FromResult(_testUser));

            var userService =
                MockUserService.GetMockUserService(
                    signInManager: MockSignInManager.GetMockSignInManager(userManager: _mockUserManager.Object).Object,
                    userManager: _mockUserManager.Object,
                    roleManager: _mockRoleManager.Object
                    ).Object;

            // act
            Func <Task> act = async() =>
                              await userService.RegisterUser(registrationModel, _groupListNames);

            // assert
            act.Should().Throw <DuplicateUserException>();
        }
Пример #3
0
        public async void UserServiceRegisterUserTest()
        {
            // arrange
            var mockedResult = new MockIdentityResult().MockResultSuccession(true);

            var testPassword = _fixture.Create <string>();

            // create a registration model with same email as the test user
            var registrationModel = new RegisterResult
            {
                Result = mockedResult,
                User   = _testUser
            };

            _mockUserManager
            .Setup(x => x.CreateAsync(_testUser, testPassword))
            .Returns(Task.FromResult((IdentityResult)mockedResult));

            var usersList = new List <User> {
                _testUser
            };

            var mockUsers = usersList.AsQueryable().BuildMock();

            _mockUserManager.Setup(x => x.Users).Returns(mockUsers.Object);

            var userService =
                MockUserService.GetMockUserService(
                    signInManager: MockSignInManager.GetMockSignInManager(userManager: _mockUserManager.Object).Object,
                    userManager: _mockUserManager.Object,
                    roleManager: _mockRoleManager.Object
                    ).Object;

            // act
            var result = await userService.RegisterUser(_testUser, testPassword, _groupListNames);

            // assert
            registrationModel.ToExpectedObject().ShouldMatch(result);
        }