コード例 #1
0
        public async Task <IActionResult> GetList()
        {
            var queryResult = await _mediator.Send(new GetFrameworksQuery());

            var response = new GetFrameworksResponse
            {
                Frameworks = queryResult.Frameworks.Select(framework => (GetFrameworkResponse)framework),
            };

            return(Ok(response));
        }
        public async Task Then_The_Frameworks_Are_Retrieved_From_The_Api_And_Added_To_Cached()
        {
            //Arrange
            var apiResponse = new GetFrameworksResponse
            {
                Frameworks = new List<FrameworkResponseItem>
                {
                    new FrameworkResponseItem
                    {
                        Id = "123",
                        FrameworkName = "test",
                        PathwayName = "test",
                        Title = "test"
                    }
                }
            };
                
            FrameworksView returnData = null;
            _apiClient.Setup(x => x.Get<GetFrameworksResponse>(It.IsAny<GetFrameworksRequest>()))
                .ReturnsAsync(apiResponse);
            _cache.Setup(x => x.Exists("Frameworks")).Returns(false);
            _cache.Setup(x => x.Set("Frameworks", It.IsAny<FrameworksView>())).Callback<string,object>(
                (key, value) =>
                {
                    returnData = value as FrameworksView;
                });

            //Act
            await _service.GetFrameworksAsync();
            
            //Assert
            _apiClient.Verify(x=>x.Get<GetFrameworksResponse>(It.IsAny<GetFrameworksRequest>()),Times.Once);
            returnData.Frameworks.Count.Should().Be(apiResponse.Frameworks.Count);
            returnData.Frameworks.ToList().First().ShouldBeEquivalentTo(apiResponse.Frameworks.First(), options=> options
                .Excluding(c=>c.Title)
                .Excluding(c=>c.ProgrammeType)
            );
        }