Пример #1
0
        private GuestListResponse CreateGuestListSuccessResponse(IEnumerable <Guest> guests)
        {
            var guestDtos = Mapper.Map <IEnumerable <GuestDto> >(guests);
            var guestList = new GuestListDto
            {
                Guests = guestDtos
            };

            return(new GuestListResponse(
                       BaseApiResponse <GuestListDto> .CreateSuccessResponse("Guests list successfully retrieved.", guestList))
            {
                Count = guestDtos.ToList().Count
            });
        }
Пример #2
0
        public async Task Index_ReturnsOkObjectResult_WithListOfGuests_ForGivenAgeParam()
        {
            // Arrange
            int ageParam    = 3;
            var mockLogger  = new Mock <ILogger <GuestsController> >();
            var mockService = new Mock <IGuestService>();
            var mockGuests  = new List <GuestDto>(new GuestDto[]
            {
                new GuestDto(),
                new GuestDto(),
                new GuestDto()
            });
            var mockItem = new GuestListDto
            {
                Guests = mockGuests
            };
            var mockResponse = new GuestListResponse(
                BaseApiResponse <GuestListDto> .CreateSuccessResponse("test message", mockItem))
            {
                Count = mockGuests.Count
            };

            mockService.Setup(svc => svc.GetGuestsByAgeAsync(ageParam)).ReturnsAsync(mockResponse);
            var controller = new GuestsController(mockLogger.Object, mockService.Object);

            // Act
            var result = await controller.Index(ageParam);

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            var okObjectResult = (OkObjectResult)result;

            okObjectResult.Value.Should().NotBeNull();
            okObjectResult.Value.Should().BeOfType <GuestListResponse>();

            var response = (GuestListResponse)okObjectResult.Value;

            response.Status.Should().Be(ResponseStatus.Success);
            response.Result.Should().BeTrue();
            response.Item.Guests.Should().NotBeNull();
            response.Item.Guests.Should().NotBeEmpty();
            response.Item.Guests.Should().HaveCount(3);
            response.Count.Should().Be(3);
        }