Inheritance: ListingRequest
Beispiel #1
0
        public async Task DoesNotSaveExistingListingIfFieldsAreDeemedInvalid()
        {
            var existingListing = new ListingFixture().Build();
            var editRequest     = new EditListingRequest
            {
                Address        = existingListing + "edit",
                AskingPrice    = existingListing.AskingPrice + 10m,
                Description    = existingListing.Description + "edit",
                Expired        = true,
                NumberBedrooms = existingListing.NumberBedrooms + 1,
                PostCode       = existingListing.PostCode + "edit"
            };

            var mockContext = new Mock <IPortalDbContext>();

            mockContext.Setup(m => m.Attach(existingListing)).Verifiable();

            var mockValidatorThatAlwaysFails = new Mock <IListingValidatorHelper>();

            mockValidatorThatAlwaysFails.Setup(v => v.HasValidFields(It.IsAny <Listing>())).Returns(false).Verifiable();

            var coordinator = new EditListingCoordinator(mockContext.Object, mockValidatorThatAlwaysFails.Object);
            var result      = await coordinator.Edit(existingListing.Id, existingListing, editRequest);

            mockValidatorThatAlwaysFails.VerifyAll();
            mockContext.VerifyAll();
            mockContext.Verify(m => m.SaveChanges(), Times.Never);
            Assert.Null(result);
        }
Beispiel #2
0
        public async Task AppliesEditsAndSavesExistingListing()
        {
            var existingListing = new ListingFixture().Build();
            var editRequest     = new EditListingRequest
            {
                Address        = existingListing + "edit",
                AskingPrice    = existingListing.AskingPrice + 10m,
                Description    = existingListing.Description + "edit",
                Expired        = true,
                NumberBedrooms = existingListing.NumberBedrooms + 1,
                PostCode       = existingListing.PostCode + "edit"
            };

            var mockContext = new Mock <IPortalDbContext>();

            mockContext.Setup(m => m.Attach(existingListing)).Verifiable();
            mockContext.Setup(m => m.SaveChanges()).Verifiable();

            var mockValidator = new Mock <IListingValidatorHelper>();

            mockValidator.Setup(v => v.HasValidFields(It.IsAny <Listing>())).Returns(true).Verifiable();

            var coordinator = new EditListingCoordinator(mockContext.Object, mockValidator.Object);
            var result      = await coordinator.Edit(existingListing.Id, existingListing, editRequest);

            mockContext.VerifyAll();
            mockValidator.VerifyAll();
            Assert.Equal(editRequest.Address, existingListing.Address);
            Assert.Equal(editRequest.AskingPrice, existingListing.AskingPrice);
            Assert.Equal(editRequest.Description, existingListing.Description);
            Assert.Equal(editRequest.Expired, existingListing.Expired);
            Assert.Equal(editRequest.NumberBedrooms, existingListing.NumberBedrooms);
            Assert.Equal(editRequest.PostCode, existingListing.PostCode);
        }
Beispiel #3
0
 public static void Update(this Listing listing, EditListingRequest request)
 {
     listing.Address        = request.Address;
     listing.AskingPrice    = request.AskingPrice;
     listing.Description    = request.Description;
     listing.Expired        = request.Expired;
     listing.NumberBedrooms = request.NumberBedrooms;
     listing.PostCode       = request.PostCode;
 }
Beispiel #4
0
        public async Task <IActionResult> EditListing(Guid listingId, EditListingRequest editListingRequest)
        {
            var existingListing = await _findListingCoordinator.Find(listingId);

            if (existingListing == null)
            {
                return(NotFound());
            }

            var result = await _editListingCoordinator.Edit(listingId, existingListing, editListingRequest);

            if (result == null)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Beispiel #5
0
        public async Task <IActionResult> AddNewListing(EditListingRequest newListingRequest)
        {
            if (newListingRequest == null)
            {
                return(BadRequest());
            }

            var newListing = await _createListingCoordinator.Create(newListingRequest);

            if (newListing == null)
            {
                return(BadRequest());
            }

            var response = MapListingResponse(newListing);

            return(Ok(response));
        }
        public async Task <Listing> Create(EditListingRequest newListing)
        {
            if (newListing == null)
            {
                throw new ArgumentNullException(nameof(newListing));
            }

            var listing = new Listing();

            listing.Update(newListing);

            if (!_validationHelper.HasValidFields(listing))
            {
                return(null);
            }

            await _dbContext.Add(listing);

            await _dbContext.SaveChanges();

            return(listing);
        }
        public async Task <Listing> Edit(Guid listingId, Listing existingListing, EditListingRequest editRequest)
        {
            if (existingListing == null)
            {
                throw new ArgumentNullException(nameof(existingListing));
            }
            if (editRequest == null)
            {
                throw new ArgumentNullException(nameof(editRequest));
            }

            _dbContext.Attach(existingListing);
            existingListing.Update(editRequest);

            if (!_validationHelper.HasValidFields(existingListing))
            {
                return(null);
            }

            await _dbContext.SaveChanges();

            return(existingListing);
        }
 /// <summary>
 /// <para>Edit an auction or classified that you have created.
 /// </para><para>
 /// You will need to resubmit the complete sell form as used when you created the listing but with the fields you wish to edit modified.
 /// Request format will error if fields are locked and cannot be edited.
 /// </para>
 /// REQUIRES AUTHENTICATION.
 /// </summary>
 /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param>
 /// <returns>XDocument: ListingResponse</returns>
 public XDocument EditListedItem(EditListingRequest request)
 {
     var query = String.Format(Constants.Culture, "{0}/{1}{2}", Constants.SELLING, Constants.EDIT, Constants.XML);
     return _connection.Post(request, query);
 }
Beispiel #9
0
        /// <summary>
        /// <para>Edit an auction or classified that you have created.
        /// </para><para>
        /// You will need to resubmit the complete sell form as used when you created the listing but with the fields you wish to edit modified.
        /// Request format will error if fields are locked and cannot be edited.
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument: ListingResponse</returns>
        public XDocument EditListedItem(EditListingRequest request)
        {
            if (_selling == null)
            {
                _selling = new SellingMethods(_connection);
            }

            return _selling.EditListedItem(request);
        }
        /// <summary>
        /// <para>Edit an auction or classified that you have created.
        /// </para><para>
        /// You will need to resubmit the complete sell form as used when you created the listing but with the fields you wish to edit modified.
        /// Request format will error if fields are locked and cannot be edited.
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="request">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <returns>XDocument: ListingResponse</returns>
        public XDocument EditListedItem(EditListingRequest request)
        {
            var query = String.Format(Constants.Culture, "{0}/{1}{2}", Constants.SELLING, Constants.EDIT, Constants.XML);

            return(_connection.Post(request, query));
        }