public static Mock <IRoleRepository> WithValidFindByName(this Mock <IRoleRepository> repository)
 {
     repository.Setup(x => x.FindByName(It.IsAny <string>()))
     .ReturnsAsync(new List <Role>()
     {
         RoleTestUtils.GenerateValidRole()
     });
     return(repository);
 }
        public async Task GetAsyncTest_ValidRole_Fails()
        {
            //arrange
            var role = RoleTestUtils.GenerateValidRole();

            _sut = new RoleRepository(_access.Object, _rAccess.Object, _mapper.Object);

            //act
            await _sut.GetAsync(Int32.Parse(role.Id));
        }
        public async Task FindRoleNameAsyncTest_ValidRole_HappyPath()
        {
            //arrange
            _mapper.WithMap(RoleMapTestUtils.GenerateValidRoleMap());

            _sut = new RoleRepository(_access.Object, _rAccess.Object, _mapper.Object);

            //act
            await _sut.FindRoleName(RoleTestUtils.GenerateValidRole().Id);
        }
Esempio n. 4
0
        public async Task FindMemberRoleByRoleId_TCI85_HappyPath()
        {
            //arrange
            int roleId = Int32.Parse(RoleTestUtils.GenerateValidRole().Id);

            //act
            var result = await _sut.FindMemberRoleByRoleId(roleId);

            //assert
            Assert.IsNotNull(result);
        }
Esempio n. 5
0
        public async Task FindMemberRoleByName_TCI87_HappyPath()
        {
            //arrange
            var roleName = RoleTestUtils.GenerateValidRole().Name;

            //act
            var result = await _sut.FindMemberRoleByName(roleName);

            //assert
            Assert.IsNotNull(result);
        }
Esempio n. 6
0
        public async Task GetMemberInRoleCount_TCI90_HappyPath()
        {
            //arrange
            var roleName = RoleTestUtils.GenerateValidRole().Name;

            //act
            var result = await _sut.GetMemberInRoleCount(roleName);

            //assert
            Assert.IsNotNull(result);
        }
Esempio n. 7
0
        public async Task GetMemberInRoleCountTest_ValidRoleName_HappyPath()
        {
            //arrange
            _sut = new MemberRepository(_access.Object, _mapper.Object);
            var role = RoleTestUtils.GenerateValidRole();

            //act
            await _sut.GetMemberInRoleCount(role.Name);

            //assert
            _access.Verify(x => x.GetMemberInRoleCount(It.IsAny <string>()), Times.Once);
        }
Esempio n. 8
0
        public async Task FindModelsWithRoleName_ValidRoleName_HappyPath()
        {
            //arrange
            _sut = new MemberRepository(_access.Object, _mapper.Object);
            var role = RoleTestUtils.GenerateValidRole();

            //act
            await _sut.FindModelsWithRoleName(role.Name);

            //assert
            _access.Verify(x => x.FindMemberModelsByRoleName(It.IsAny <string>()), Times.Once);
        }
        public async Task RemoveFromRoleAsync_NullMember_HappyPath()
        {
            //arrange
            _repositoryMock.RemoveFromRoleAsync();
            var role = RoleTestUtils.GenerateValidRole();

            //act
            await _facade.RemoveFromRoleAsync(null, role.Name);

            //assert
            _repositoryMock.Verify(x => x.RemoveFromRole(It.IsAny <Member>(), It.IsAny <string>()), Times.Never);
        }
        public async Task UpdateAsyncTest_ValidRole_HappyPath()
        {
            //arrange
            _mapper.WithMap(RoleMapTestUtils.GenerateValidRoleMap());

            _sut = new RoleRepository(_access.Object, _rAccess.Object, _mapper.Object);

            //act
            await _sut.UpdateAsync(RoleTestUtils.GenerateValidRole());

            //assert
            _rAccess.Verify(x => x.UpdateOneAsync(It.IsAny <IMap>()), Times.Once());
        }
        public async Task FindByNameAsyncTest_ValidName_HappyPath()
        {
            //arrange
            _mapper.WithMap(RoleMapTestUtils.GenerateValidRoleMap());

            _sut = new RoleRepository(_access.Object, _rAccess.Object, _mapper.Object);

            //act
            await _sut.FindByName(RoleTestUtils.GenerateValidRole().Name);

            //assert
            _access.Verify(x => x.FindMemberRoleByName(It.IsAny <string>()), Times.Once());
        }
Esempio n. 12
0
        public async Task RemoveFromRole_NullMember_Fails()
        {
            //arrange
            var role = RoleTestUtils.GenerateValidRole();

            _sut = new MemberRepository(_access.Object, _mapper.Object);

            //act
            await _sut.RemoveFromRole(null, role.Name);

            //assert
            _access.Verify(x => x.RemoveMemberRole(It.IsAny <IMemberMap>(), It.IsAny <string>()), Times.Once());
        }
        public async Task IsMemberInRole_NullMember_Fails()
        {
            //arrange
            _repositoryMock.WithSuccessfulIsInRole();
            var role = RoleTestUtils.GenerateValidRole();

            //act
            var result = await _facade.IsInRoleAsync(null, role.Name);

            //assert
            _repositoryMock.Verify(x => x.IsInRole(It.IsAny <Member>(), It.IsAny <string>()), Times.Never);
            Assert.IsNull(result);
        }
        public async Task GetMemberInRoleCount_ValidRole_HappyPath()
        {
            //arrange
            _repositoryMock.WithSuccessfulInRoleCount();
            var role = RoleTestUtils.GenerateValidRole();

            //act
            var result = await _facade.GetMemberInRoleCount(role.Name);

            //assert
            _repositoryMock.Verify(x => x.GetMemberInRoleCount(It.IsAny <string>()), Times.Once);
            Assert.IsNotNull(result);
        }
Esempio n. 15
0
        public async Task UpdateRole_InvalidMember_Fails()
        {
            //arrange
            var member = MemberTestUtils.GenerateInvalidMember();
            var role   = RoleTestUtils.GenerateValidRole();

            _sut = new MemberRepository(_access.Object, _mapper.Object);

            //act
            await _sut.UpdateRole(member, role.Name);

            //assert
            _access.Verify(x => x.AddMemberToRole(It.IsAny <IMemberMap>(), It.IsAny <string>()), Times.Once());
        }
        public async Task FindWithRoleNamePagedModel_InvalidPageSize_Fails()
        {
            //arrange
            var role = RoleTestUtils.GenerateValidRole();

            _repositoryMock.WithSuccesfulFindRoleNamePagedModel(role.Name);

            //act
            var result = await _facade.FindWithRoleNamePagedModel(role.Name, 1, 0);

            //assert
            _repositoryMock.Verify(x => x.FindModelsWithRoleName(It.IsAny <string>()), Times.Never);
            Assert.IsNull(result);
        }
        public async Task FindWithRoleNamePagedModel_ValidRole_HappyPath()
        {
            //arrange
            var role = RoleTestUtils.GenerateValidRole();

            _repositoryMock.WithSuccesfulFindRoleNamePagedModel(role.Name);

            //act
            var result = await _facade.FindWithRoleNamePagedModel(role.Name, 1, 2);

            //assert
            _repositoryMock.Verify(x => x.FindModelsWithRoleName(It.IsAny <string>()), Times.Once);
            Assert.IsNotNull(result);
        }
        public async Task IsMemberInRole_ValidMember_HappyPath()
        {
            //arrange
            _repositoryMock.WithSuccessfulIsInRole();
            var member = MemberTestUtils.GenerateValidMember();
            var role   = RoleTestUtils.GenerateValidRole();

            //act
            var result = await _facade.IsInRoleAsync(member, role.Name);

            //assert
            _repositoryMock.Verify(x => x.IsInRole(It.IsAny <Member>(), It.IsAny <string>()), Times.Once);
            Assert.IsNotNull(result);
        }
        public async Task DeleteByIdAsyncTest_ValidRole_HappyPath()
        {
            //arrange
            _mapper.WithMap(RoleMapTestUtils.GenerateValidRoleMap());

            _sut = new RoleRepository(_access.Object, _rAccess.Object, _mapper.Object);

            var role = RoleTestUtils.GenerateValidRole();

            //act
            await _sut.DeleteAsync(Int32.Parse(role.Id));

            //assert
            _rAccess.Verify(x => x.DeleteOneAsync(It.IsAny <IMap>()), Times.Once());
        }
        public async Task FindByIdAsyncTest_ValidRole_HappyPath()
        {
            //arrange
            _mapper.WithMap(RoleMapTestUtils.GenerateValidRoleMap());

            _sut = new RoleRepository(_access.Object, _rAccess.Object, _mapper.Object);

            var role = RoleTestUtils.GenerateValidRole();

            //act
            var result = await _sut.FindById(Int32.Parse(role.Id));

            //assert
            _access.Verify(x => x.FindMemberRoleByRoleId(It.IsAny <int>()), Times.Once());
            Assert.IsNotNull(result);
        }