コード例 #1
0
        public void GetAllAsync_Has_Route_Attribute()
        {
            // Arrange
            var mockMediator        = new Mock <IMediator>();
            var mockMapper          = new Mock <IMapper>();
            var mockResponseFactory = new Mock <IResponseFactory>();
            var mockApiSettings     = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut = new DestinationsController(mockMediator.Object, mockMapper.Object, mockResponseFactory.Object, mockApiSettings.Object);

            // Act
            var attributes = sut.GetAttributesOn(x => x.GetAllDestinationsAsync(
                                                     It.IsAny <PagingOptions>(),
                                                     It.IsAny <SortOptions>(),
                                                     It.IsAny <SearchOptions>(),
                                                     It.IsAny <CancellationToken>())).OfType <RouteAttribute>().SingleOrDefault();

            // Assert
            attributes.Should().NotBeNull();
            attributes.Name.Should().Be("GetAllDestinationsAsync");
        }
コード例 #2
0
        public void GetAllAsync_Has_ProducesResponse_Atttribute_With_Correct_Return_Type()
        {
            // Arrange
            var mockMediator        = new Mock <IMediator>();
            var mockMapper          = new Mock <IMapper>();
            var mockResponseFactory = new Mock <IResponseFactory>();
            var mockApiSettings     = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut           = new DestinationsController(mockMediator.Object, mockMapper.Object, mockResponseFactory.Object, mockApiSettings.Object);
            var expectedTyped = typeof(IEnumerable <DestinationPreviewDto>);

            // Act
            var attributes = sut.GetAttributesOn(x => x.GetAllDestinationsAsync(
                                                     It.IsAny <PagingOptions>(),
                                                     It.IsAny <SortOptions>(),
                                                     It.IsAny <SearchOptions>(),
                                                     It.IsAny <CancellationToken>())).OfType <ProducesResponseTypeAttribute>();

            // Assert
            attributes.Should().NotBeNull();
            attributes.Count().Should().BeGreaterThan(0);
            attributes.Select(x => x.Type == expectedTyped).Should().NotBeNull();
        }