Exemplo n.º 1
0
        public async Task TestPostEditEditSuccessTrue()
        {
            // Arrange
            var mockService = new Mock <IListingService>();

            mockService
            .Setup(x => x.UpdateListingAsync(It.IsAny <ListingInputModel>()))
            .ReturnsAsync(true)
            .Verifiable();

            var controller = new ListingController(mockService.Object);

            controller.TempData =
                new TempDataDictionary(
                    new DefaultHttpContext(),
                    Mock.Of <ITempDataProvider>());

            // Act
            var result =
                await controller.Edit(
                    1,
                    new ListingInputModel { Id = 1, Description = "test" });

            // Assert
            var redirectResult =
                Assert.IsAssignableFrom <RedirectToActionResult>(result);

            Assert.Equal("Home", redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);

            mockService.Verify(x => x.UpdateListingAsync(It.IsAny <ListingInputModel>()),
                               Times.Once);
        }
Exemplo n.º 2
0
 public void setupForEachTest()
 {
     service = new Mock <IEntityService <ProductListing> >();
     service.Setup(s => s.GetAll(1, 10)).Returns(It.IsAny <IEnumerable <ProductListing> >());
     //Arrange
     instance = new ListingController(service.Object);
 }
        public async Task GetListingWithBookingDetail_ExpectListingWithNoBookingSlot()
        {
            // Arrange
            _listingServiceMock.Setup(x => x.GetListingDetail(1)).ReturnsAsync(() => _sampleListing);

            _imageStorageMock.Setup(
                x => x.TransformImageUrls(It.IsAny <List <Image> >(), ImageType.Listing, It.IsAny <IDevice>())).Returns(
                () => new List <Image>
            {
                new Image {
                    Url = "image1NewUrl"
                }
            });

            _bookingServiceMock.Setup(x => x.GetBookingSlotsByListingId(1)).ReturnsAsync(() => null);

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

            // Action
            var result = await controller.GetListingWithBookingDetail(1);

            // Assert
            result.Should().NotBeNull();
            result.Id.Should().Be(1);
            result.Header.Should().Be(_sampleListing.Header);
            result.Description.Should().Be(_sampleListing.Description);
            result.ImageList.Count.Should().Be(_sampleListing.ImageList.Count);
            result.ImageList.FirstOrDefault().Url = "image1NewUrl";
            result.BookingSlots.Count.Should().Be(0);
        }
Exemplo n.º 4
0
        public async Task TestPostEditEditSuccessFalse()
        {
            // Arrange
            var mockService = new Mock <IListingService>();

            mockService
            .Setup(x => x.UpdateListingAsync(It.IsAny <ListingInputModel>()))
            .ReturnsAsync(false)
            .Verifiable();

            var controller = new ListingController(mockService.Object);

            controller.TempData = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>());

            // Act
            var result = await controller.Edit(1, new ListingInputModel { Id = 1, Description = "test" });

            // Assert
            var viewResult  = Assert.IsAssignableFrom <ViewResult>(result);
            var modelResult = Assert.IsAssignableFrom <ListingInputModel>(viewResult.Model);

            Assert.Equal("test", modelResult.Description);
            Assert.NotNull(controller.TempData["EditError"]);
            Assert.Equal("There was a problem updating the information. Please ensure the data entered is valid, and try again.",
                         controller.TempData["EditError"]);

            mockService.Verify(x => x.UpdateListingAsync(It.IsAny <ListingInputModel>()),
                               Times.Once);
        }
Exemplo n.º 5
0
        public void Setup()
        {
            var dataContext = new DataContext(_dbContextOptions);

            _listingService    = new ListingService(dataContext);
            _listingController = new ListingController(_listingService);
        }
        public async Task GetFeatureListings_ExpectOneListing()
        {
            _listingServiceMock.Setup(x => x.GetFeatureListings()).ReturnsAsync(() => new List <ListingView>
            {
                new ListingView
                {
                    Id          = 1,
                    Header      = "This is header",
                    Description = "This is description",
                    SuburbName  = "Name",
                    PostCode    = 2000,
                    OwnerName   = "Boss"
                }
            });
            var controller = new ListingController(_listingServiceMock.Object, _mapperMock, _appSettingMock.Object,
                                                   _loggerMock.Object,
                                                   _authorizationServiceMock.Object, _imageServiceMock.Object, _bookingServiceMock.Object, _deviceMock.Object,
                                                   _imageStorageMock.Object);

            // Act
            var result = (await controller.GetFeatureListings()).ToList();

            // Assert
            result.Count.Should().Be(1);
            var firstListing = result.FirstOrDefault();

            firstListing.Should().NotBeNull();
            firstListing.Id.Should().Be(1);
            firstListing.Header.Should().Be("This is header ...");
            firstListing.Description.Should().Be("This is description");
            firstListing.Location.Should().Be("Name (2000)");
            firstListing.PrimaryOwner.Should().Be("Boss");
        }
        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");
        }
Exemplo n.º 8
0
        public async Task TestGetEditIdValid()
        {
            // Arrange
            var inputModel = new ListingInputModel
            {
                Id          = 666,
                Description = "test"
            };

            var mockService = new Mock <IListingService>();

            mockService
            .Setup(x => x.GetListingInputModelByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(inputModel)
            .Verifiable();

            var controller = new ListingController(mockService.Object);

            // Act
            var result = await controller.Edit(1);

            // Assert
            var viewResult  = Assert.IsAssignableFrom <ViewResult>(result);
            var modelResult = Assert.IsAssignableFrom <ListingInputModel>(viewResult.Model);

            Assert.Equal("test", modelResult.Description);
            mockService.Verify(x => x.GetListingInputModelByIdAsync(It.IsAny <int>()), Times.Once);
        }
Exemplo n.º 9
0
 public ListingControllerTests()
 {
     _amazonListingSyncManager           = A.Fake <IAmazonListingSyncManager>();
     _amazonListingService               = A.Fake <IAmazonListingService>();
     _amazonAppSettings                  = A.Fake <AmazonAppSettings>();
     _prepareForSyncAmazonListingService = A.Fake <IPrepareForSyncAmazonListingService>();
     _listingController                  = new ListingController(_amazonListingSyncManager, _amazonListingService,
                                                                 _amazonAppSettings, _prepareForSyncAmazonListingService);
 }
Exemplo n.º 10
0
 public ListingControllerTests()
 {
     _amazonListingSyncManager = A.Fake<IAmazonListingSyncManager>();
     _amazonListingService = A.Fake<IAmazonListingService>();
     _amazonAppSettings = A.Fake<AmazonAppSettings>();
     _prepareForSyncAmazonListingService = A.Fake<IPrepareForSyncAmazonListingService>();
     _listingController = new ListingController(_amazonListingSyncManager, _amazonListingService,
     _amazonAppSettings, _prepareForSyncAmazonListingService);
 }
Exemplo n.º 11
0
        public void TestCreateGet()
        {
            // Arrange
            var controller = new ListingController(null);

            // Act
            var result = controller.Create();

            // Assert
            Assert.IsAssignableFrom <ViewResult>(result);
        }
Exemplo n.º 12
0
        public async Task TestPostEditIdUnequalToInputModelId()
        {
            // Arrange
            var controller = new ListingController(null);

            // Act
            var result = await controller.Edit(1, new ListingInputModel { Id = 2 });

            // Assert
            Assert.IsAssignableFrom <NotFoundResult>(result);
        }
Exemplo n.º 13
0
        public async Task TestPostEditInputModelNull()
        {
            // Arrange
            var controller = new ListingController(null);

            // Act
            var result = await controller.Edit(1, null);

            // Assert
            Assert.IsAssignableFrom <BadRequestResult>(result);
        }
Exemplo n.º 14
0
        public async Task TestGetEditIdNull()
        {
            // Arrange
            var controller = new ListingController(null);

            // Act
            var result = await controller.Edit(null);

            // Assert
            Assert.IsAssignableFrom <NotFoundResult>(result);
        }
Exemplo n.º 15
0
 private void GetDataAccordingToCurrentSortState()
 {
     // Are the items shown grouped or just in item order
     if (SortOrderHandler.CurrentOrder == ItemSort.SortState.Grouped)
     {
         WrappedView.Adapter = new GroupItemAdapter(Context, ListingController.GetGroupsAndItems());
     }
     else
     {
         WrappedView.Adapter = new ItemAdapter(Context, ListingController.GetItems(SortOrderHandler.CurrentOrder == ItemSort.SortState.Alphabetic));
     }
 }
        public async Task DeactivateListing_ExpectValidationException()
        {
            // Arrange
            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 <ValidationException>(async() => await controller.DeactivateListing(-1));

            ex.Message.Should().Be("id");
        }
        public async Task UpdateListing_ExpectArgumentNullException()
        {
            // Arrange
            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 <ArgumentNullException>(async() => await controller.UpdateListing(0, null));

            ex.Message.Should().Be("Value cannot be null.\r\nParameter name: listing");
        }
        public async Task GetListingWithBookingDetail_ExpectException()
        {
            _listingServiceMock.Setup(x => x.GetListingDetail(It.IsAny <int>())).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.GetListingWithBookingDetail(10000000));

            ex.Message.Should().Be("Can't find listing\r\nParameter name: id");
        }
        public void Index_LoadingPageWithTag()
        {
            var controller = new ListingController(queryService.Object, null);
            var viewResult = controller.Index(tag: "Tag1");

            Assert.IsNotNull(viewResult);
            Assert.IsInstanceOfType(viewResult, typeof(ViewResult));

            var model = ((ViewResult)viewResult).Model as ListingViewModel;

            Assert.IsFalse(string.IsNullOrEmpty(model.Tag));
            Assert.IsTrue(model.Questions.Count == 1);
        }
        public void Export_DownloadQnA()
        {
            IExportService <QnAMakerSetting> exportService = new ExportServiceImpl <QnAMakerSetting>();
            var controller = new ListingController(queryService.Object, exportService);
            var result     = controller.ExportQnAMaker(string.Empty, AppDomain.CurrentDomain.BaseDirectory);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));

            var fileResult = result as FileResult;

            Assert.IsTrue(fileResult.ContentType == "application/text");
        }
Exemplo n.º 21
0
        public async Task TestCreatePostInputModelNull()
        {
            // Arrange
            var controller = new ListingController(null);

            // Act
            var result = await controller.Create(null);

            // Assert
            var redirectResult = Assert.IsAssignableFrom <RedirectToActionResult>(result);

            Assert.Equal("Listing", redirectResult.ControllerName);
            Assert.Equal("Create", redirectResult.ActionName);
        }
Exemplo n.º 22
0
        public EditShould()
        {
            fixture = new SetupFixture();

            env = new Mock <IHostEnvironment>();
            imageUploadWrapper = new Mock <IImageUploadWrapper>();
            env.Setup(m => m.EnvironmentName).Returns("Hosting:UnitTestEnvironment");
            sut = new ListingController(fixture.Logger.Object,
                                        fixture.repositoryWrapper.Object,
                                        fixture.mapper.Object,
                                        env.Object,
                                        imageUploadWrapper.Object);

            address = new Address()
            {
                FirstLine = "TestFirstLine", Number = "23", TownCity = "TestCity", Postcode = "Xf343xs", Id = 1
            };
            address2 = new Address()
            {
                FirstLine = "FirstLine", Number = "33", TownCity = "TestCity", Postcode = "Xf343xs", Id = 1
            };
            fixture.repositoryWrapper
            .Setup(x => x.Listing.GetListingByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(It.IsAny <Listing>);
            fixture.repositoryWrapper.Setup(x => x.Address.GetAllAddressesNotInUseAsync()).ReturnsAsync(new List <Address>()
            {
                address
            });
            fixture.repositoryWrapper.Setup(x => x.Address.GetAddressByIdAsync(It.IsAny <int>())).ReturnsAsync(address2);
            fixture.mapper.Setup(x => x.Map <ListingManagementDTO>(It.IsAny <Listing>())).Returns(new ListingManagementDTO()
            {
                Address = address
            });
            imageUploadWrapper.Setup(x => x.Upload(It.IsAny <IFormFile>(), It.IsAny <IHostEnvironment>()))
            .Returns("imageurl");
            fixture.mapper.Setup(x => x.Map <Listing>(It.IsAny <ListingManagementDTO>())).Returns(new Listing()
            {
                Id = 1
            });


            listingManagementDTO = new ListingManagementDTO()
            {
                Id = 1, Address = new Address()
                {
                    Id = 1
                }, File = new Mock <IFormFile>().Object
            };
        }
        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");
        }
Exemplo n.º 24
0
        public DetailsShould()
        {
            fixture = new SetupFixture();
            sut     = new ListingController(fixture.Logger.Object,
                                            fixture.repositoryWrapper.Object,
                                            fixture.mapper.Object);


            fixture.repositoryWrapper.Setup(x => x.Listing.GetAllListingsAsync()).ReturnsAsync(new List <Listing>()
            {
                It.IsAny <Listing>()
            });
            fixture.mapper.Setup(x => x.Map <ListingDetailDTO>(It.IsAny <Listing>())).Returns(new ListingDetailDTO());
            fixture.mapper.Setup(x => x.Map <List <ExtendedListingDTO> >(It.IsAny <List <Listing> >())).Returns(new List <ExtendedListingDTO>());
        }
Exemplo n.º 25
0
        public async Task TestCreatePostModelStateInvalid()
        {
            // Arrange
            var controller = new ListingController(null);

            controller.ModelState.AddModelError("test", "test");

            // Act
            var result = await controller.Create(new ListingInputModel { Description = "test description" });

            // Assert
            var viewResult  = Assert.IsAssignableFrom <ViewResult>(result);
            var modelResult = Assert.IsAssignableFrom <ListingInputModel>(viewResult.Model);

            Assert.Equal("test description", modelResult.Description);
        }
        public async Task DeactivateListing_ExpectUnauthorizedException()
        {
            // Arrange
            _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.DeactivateListing(1));

            ex.Message.Should().Be("Attempted to perform an unauthorized operation.");
        }
Exemplo n.º 27
0
        public IndexShould()
        {
            fixture = new SetupFixture();

            env = new Mock <IHostEnvironment>();
            imageUploadWrapper = new Mock <IImageUploadWrapper>();
            env.Setup(m => m.EnvironmentName).Returns("Hosting:UnitTestEnvironment");
            sut = new ListingController(fixture.Logger.Object,
                                        fixture.repositoryWrapper.Object,
                                        fixture.mapper.Object,
                                        env.Object,
                                        imageUploadWrapper.Object);
            fixture.repositoryWrapper.Setup(x => x.Listing.GetAllListingsAsync()).ReturnsAsync(It.IsAny <List <Listing> >());
            fixture.mapper.Setup(x => x.Map <List <ListingManagementDTO> >(It.IsAny <Listing>())).Returns(new List <ListingManagementDTO>());
            imageUploadWrapper.Setup(x => x.Upload(It.IsAny <IFormFile>(), It.IsAny <IHostEnvironment>()))
            .Returns("imageUrl");
        }
        public async Task DeactivateListing_OperationSuccess()
        {
            // Arrange
            _listingServiceMock.Setup(x => x.DeActivateListing(1)).ReturnsAsync(1);
            _authorizationServiceMock.Setup(
                x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsAny <IEnumerable <IAuthorizationRequirement> >()))
            .ReturnsAsync(AuthorizationResult.Success);

            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.DeactivateListing(1);

            // Assert
            records.Should().Be(1);
        }
Exemplo n.º 29
0
        public async Task TestCreateInputModelValid()
        {
            // Arrange
            var mockService = new Mock <IListingService>();

            mockService
            .Setup(x => x.AddListingAsync(It.IsAny <ListingInputModel>()))
            .Verifiable();

            var controller = new ListingController(mockService.Object);

            // Act
            var result = await controller.Create(new ListingInputModel());

            // Assert
            var redirectResult = Assert.IsAssignableFrom <RedirectToActionResult>(result);

            Assert.Equal("Home", redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);
        }
        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");
        }
Exemplo n.º 31
0
        public async Task TestGetEditInputModelNull()
        {
            // Arrange
            ListingInputModel inputModel = null;

            var mockService = new Mock <IListingService>();

            mockService
            .Setup(x => x.GetListingInputModelByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(inputModel)
            .Verifiable();

            var controller = new ListingController(mockService.Object);

            // Act
            var result = await controller.Edit(1);

            // Assert
            Assert.IsAssignableFrom <NotFoundResult>(result);

            mockService.Verify(x => x.GetListingInputModelByIdAsync(It.IsAny <int>()), Times.Once);
        }