public void Add_MissingOPropertyNamePassed_ReturnsBadRequest() { // Arrange var theItem = new Domain.Entities.Property { PropertyNumber = 105, Area = 100, LandlordId = 1, PropertyID = 5, Address = "Address5", PropertyStatus = Domain.Enums.Status.North }; MoqSetupAdd(theItem); var createdDto = mapper.Map <PropertyDto>(theItem); // Act //See how the ValidateViewModel extension method in the Helper class is useful here _controller.ValidateViewModel(theItem); //I have used the above useful extension method to simulate validation instead of adding customly like below //_controller.ModelState.AddModelError("PropertyName", "Required"); var badResponse = _controller.Post(1, createdDto); // Assert Assert.IsType <BadRequestObjectResult>(badResponse); }
public async Task <bool> Handle(InsertPropertyCommand request, CancellationToken cancellationToken) { var newProperty = new Domain.Entities.Property { Id = request.Id, Address1 = request.Address1, Address2 = request.Address2, City = request.City, State = request.State, ZipCode = request.Zip, ZipPlus4 = request.ZipPlus4, YearBuilt = request.YearBuilt, ListPrice = request.ListPrice, MonthlyRent = request.MonthlyRent }; await _context.Properties.AddAsync(newProperty); return(await _context.SaveChangesAsync(cancellationToken) > 0); }
public async Task <int> Handle(CreatePropertyCommand request, CancellationToken cancellationToken) { var propertyObj = request.PropertyDto; Domain.Entities.Property property = new Domain.Entities.Property { PropertyType = propertyObj.PropertyType, AddressPremises = propertyObj.AddressPremises, AddressLine1 = propertyObj.AddressLine1, AddressLine2 = propertyObj.AddressLine2, City = propertyObj.City, PinCode = propertyObj.PinCode, LateFeeDay = propertyObj.LateFeeDay, TdsInterestRate = propertyObj.TdsInterestRate, StateID = propertyObj.StateID, GstTaxCode = propertyObj.GstTaxCode, TDSTaxCode = propertyObj.TDSTaxCode }; _context.Property.Add(property); await _context.SaveChangesAsync(cancellationToken); return(property.PropertyID); }
private void MoqSetupAdd(Domain.Entities.Property testItem) { _mockRepo.Setup(x => x.Add(It.Is <Domain.Entities.Property>(y => y == testItem))) .Callback <Domain.Entities.Property>(s => MockData.Current.Properties.Add(s)); }