public async Task AddImage_OperationSuccess()
        {
            // Arrange
            _listingServiceMock.Setup(x => x.GetListingDetail(1)).ReturnsAsync(_sampleListing);
            _authorizationServiceMock.Setup(
                x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
            .ReturnsAsync(AuthorizationResult.Success);

            _imageServiceMock.Setup(x => x.InsertListingImage(1, It.IsAny <IFormFile>()))
            .ReturnsAsync(new Image {
                Url = "imageUrl"
            });

            var controller = new ListingController(_listingServiceMock.Object, _mapperMock, _appSettingMock.Object,
                                                   _loggerMock.Object,
                                                   _authorizationServiceMock.Object, _imageServiceMock.Object, _bookingServiceMock.Object, _deviceMock.Object,
                                                   _imageStorageMock.Object);

            // Action
            var records = await controller.AddImage(1, new List <IFormFile> {
                new FormFile(null, 10, 10, "name", "fileName")
            });

            // Assert
            records.Should().NotBeNull();
            records.Count().Should().Be(1);
            records.FirstOrDefault().Url.Should().Be("imageUrl");
        }
        public async Task AddImage_ExpectUnauthorizedException()
        {
            // Arrange
            _listingServiceMock.Setup(x => x.GetListingDetail(1)).ReturnsAsync(_sampleListing);
            _authorizationServiceMock.Setup(
                x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
            .ReturnsAsync(AuthorizationResult.Failed);

            var controller = new ListingController(_listingServiceMock.Object, _mapperMock, _appSettingMock.Object,
                                                   _loggerMock.Object,
                                                   _authorizationServiceMock.Object, _imageServiceMock.Object, _bookingServiceMock.Object, _deviceMock.Object,
                                                   _imageStorageMock.Object);

            // Assert
            var ex = await Assert.ThrowsAsync <UnauthorizedAccessException>(async() => await controller.AddImage(1, new List <IFormFile>()));

            ex.Message.Should().Be("Attempted to perform an unauthorized operation.");
        }
        public async Task AddImage_ExpectArgumentOutOfRangeException()
        {
            // Arrange
            _listingServiceMock.Setup(x => x.GetListingDetail(0)).ReturnsAsync(() => null);

            var controller = new ListingController(_listingServiceMock.Object, _mapperMock, _appSettingMock.Object,
                                                   _loggerMock.Object,
                                                   _authorizationServiceMock.Object, _imageServiceMock.Object, _bookingServiceMock.Object, _deviceMock.Object,
                                                   _imageStorageMock.Object);

            // Assert
            var ex = await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await controller.AddImage(0, new List <IFormFile>()));

            ex.Message.Should().Be("Can't find listing\r\nParameter name: listingId");
        }