Exemplo n.º 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 CustomersController(mockMediator.Object, mockMapper.Object, mockResponseFactory.Object, mockApiSettings.Object);

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

            // Assert
            attributes.Should().NotBeNull();
            attributes.Name.Should().Be("GetAllCustomersAsync");
        }
Exemplo n.º 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 CustomersController(mockMediator.Object, mockMapper.Object, mockResponseFactory.Object, mockApiSettings.Object);
            var expectedTyped = typeof(IEnumerable <CustomerPreviewDto>);

            // Act
            var attributes = sut.GetAttributesOn(x => x.GetAllCustomersAsync(
                                                     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();
        }