public async Task GetAllPermissions_ShouldReturnNull( [Frozen] Mock <IPermissionRepository> mockRepository, [Frozen] Mock <IMapper> mockMapper, PermissionService sut) { //Arrange mockRepository.Setup(p => p.GetPermissionsAsync()).ReturnsAsync((IEnumerable <Permission>)null); mockMapper.Setup(m => m.Map <DTO.PermissionResponse>(null)).Returns((DTO.PermissionResponse)null); //Act var result = await sut.GetAllAsync(); //Assert Assert.Null(result); mockRepository.Verify(r => r.GetPermissionsAsync(), Times.Once); mockMapper.Verify(m => m.Map <DTO.PermissionResponse>(null), Times.Never); }
public async Task GetPermissions_ShouldReturnValidPermissionDtos( [Frozen] Mock <IPermissionRepository> mockRepository, [Frozen] Mock <IMapper> mockMapper, List <Permission> permissions, List <DTO.PermissionResponse> permissionsDto, PermissionService sut) { //Arrange mockRepository.Setup(p => p.GetPermissionsAsync()).ReturnsAsync(permissions); mockMapper.Setup(m => m.Map <IEnumerable <DTO.PermissionResponse> >(permissions)).Returns(permissionsDto); //Act var result = await sut.GetAllAsync(); //Assert Assert.NotNull(result); Assert.Equal(3, result.Count()); mockRepository.Verify(r => r.GetPermissionsAsync(), Times.Once); mockMapper.Verify(m => m.Map <IEnumerable <DTO.PermissionResponse> >(permissions), Times.Once); }