public async Task DeleteImage_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.FetchListingImageByUrl(1, "url")).ReturnsAsync(new Image { ImageId = 1, Url = "url" }); _imageServiceMock.Setup(x => x.DeleteImage(1, "url")).ReturnsAsync(1); 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.DeleteImage(1, "url"); // Assert records.Should().Be(1); }
public async Task DeleteImage_WithIncorrectImageUrl_ExpectArgumentOutOfRangeException() { // 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.FetchListingImageByUrl(1, It.IsAny <string>())).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.DeleteImage(1, "url")); ex.Message.Should().Be("Can't find image\r\nParameter name: url"); }
public async Task DeleteImage_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.DeleteImage(1, "url")); ex.Message.Should().Be("Attempted to perform an unauthorized operation."); }
public async Task DeleteImage_WithIncorrectListing_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.DeleteImage(0, "url")); ex.Message.Should().Be("Can't find listing\r\nParameter name: listingId"); }