コード例 #1
0
        public async Task GetSurveys_Always_ReturnsOk()
        {
            var mockRepository = Substitute.For <ISurveyRepository>();

            mockRepository.GetSurveysAsync().Returns(RandomEntitiesGenerator.PredefinedSurveys);

            var controller = new SurveyController(mockRepository);

            var response = await controller.GetSurveysAsync();

            response.Should().NotBeNull();
            response.Result.Should().BeOfType <OkObjectResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var ok = response.Result as OkObjectResult;

            ok.Value.Should().BeAssignableTo <IEnumerable <Survey> >();
            ok.Value.Should().BeEquivalentTo(RandomEntitiesGenerator.PredefinedSurveys, opt => opt.IgnoringCyclicReferences());

            await mockRepository.Received().GetSurveysAsync();
        }