Esempio n. 1
0
        public async Task Get_Should_Return_Ok_Result_When_Valid()
        {
            var mockInterest = new List <InterestDTO>()
            {
                new InterestDTO()
                {
                    Id = 1, InterestDescription = "test", InterestName = "test"
                },
                new InterestDTO()
                {
                    Id = 2, InterestDescription = "test", InterestName = "test"
                }
            } as IReadOnlyList <InterestDTO>;
            var mockInterestsService = new Mock <IInterestService>();

            mockInterestsService.Setup(x => x.GetInterests()).ReturnsAsync(Result.Ok(mockInterest));

            var controller = new InterestController(mockInterestsService.Object);
            var result     = await controller.GetAll();

            var contentResult = result as OkObjectResult;

            contentResult.StatusCode.Should().Be(200);
            contentResult.Value.Should().BeAssignableTo <IReadOnlyList <InterestDTO> >();
            var actualValue = contentResult.Value as IReadOnlyList <InterestDTO>;

            actualValue.Should().BeEquivalentTo(mockInterest);
        }
Esempio n. 2
0
        public async Task Get_Should_Return_Failure_Result_When_No_Content_Is_Available()
        {
            var mockInterestsService = new Mock <IInterestService>();

            mockInterestsService.Setup(x => x.GetInterests()).ReturnsAsync(Result.Fail <IReadOnlyList <InterestDTO> >(InterestRepository.No_Interests_Found));

            var controller = new InterestController(mockInterestsService.Object);
            var result     = await controller.GetAll();

            var contentResult = result as BadRequestObjectResult;

            contentResult.StatusCode.Should().Be(400);
            contentResult.Value.Should().Be(InterestRepository.No_Interests_Found);
        }