public bool DuplicateEquals(IResturant other) { var resturantName = ResturantName ?? ""; var resturantDesc = ResturantDescription ?? ""; var address = ResturantAddress ?? new FormalAddress() { AddressApartmentNumber = null, AddressBuildingNumber = null, AddressCityName = null, AddressStreetName = null, AddressCountryName = null, AddressPostcode = null, AddressStateName = null, AddressSuburbName = null }; var otherName = other.ResturantName ?? ""; var otherDesc = other.ResturantDescription ?? ""; var otherAddress = other.ResturantAddress ?? new FormalAddress() { AddressApartmentNumber = null, AddressBuildingNumber = null, AddressCityName = null, AddressStreetName = null, AddressCountryName = null, AddressPostcode = null, AddressStateName = null, AddressSuburbName = null }; return(resturantName.Equals(otherName) && address.Equals(otherAddress) && resturantDesc.Equals(otherDesc)); }
public void SearchForResturant() { bool result = false; IResturant resturantModel = null; try { int size = _random.Next(0, 30); string desiredName = GenerateResturantName(size); resturantModel = SetupAddedResturant(desiredName); var searchResults = _resturantController.SearchResturant(resturantModel.ResturantName); result = CheckSearchResultsList(resturantModel.ResturantName, searchResults); using (var dbContext = new ResturantReviewDBContext()) { dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } catch (Exception) { using (var dbContext = new ResturantReviewDBContext()) { dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } Assert.True(result); }
public void UpdateResturantDetails() { bool result = false; IResturant resturantModel = null; try { IResturant updatedResturant = null; resturantModel = SetupAddedResturant(); int size = _random.Next(0, 30); string name = GenerateResturantName(size); resturantModel.ResturantName = name; _resturantController.UpdateResturantDetails(JsonConvert.SerializeObject(resturantModel)); using (var dbContext = new ResturantReviewDBContext()) { updatedResturant = dbContext.Resturants.Where(x => x.ResturantName.Equals(name)).FirstOrDefault(); result = updatedResturant != null; dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } catch (Exception) { using (var dbContext = new ResturantReviewDBContext()) { dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } Assert.True(result); }
public bool Equals(IResturant other) { return(ResturantId == other.ResturantId && ResturantName.Equals(other.ResturantName) && ResturantAddress.Equals(other.ResturantAddress) && ResturantStarRating == other.ResturantStarRating && ResturantOwnerName.Equals(other.ResturantOwnerName) && ResturantDescription.Equals(other.ResturantDescription) && ResturantType == other.ResturantType && DateAdded.Equals(other.DateAdded)); }
public void OnGet() { logger.LogError("executing Get method for list"); Message = Config["message"]; Resturants = IResturant.SearchByName(searchedTerm); }
public void AddResturant() { bool result = false; IResturant resturantModel = null; try { var resturant = new Mock <IResturant>(); var address = new FormalAddress(); resturant.SetupAllProperties(); resturant.SetupProperty(x => x.ResturantAddress, address); resturantModel = resturant.Object; var addressModel = resturant.Object.ResturantAddress; _resturantController.AddResturant(resturantModel.ResturantName, addressModel.AddressApartmentNumber, addressModel.AddressBuildingNumber, addressModel.AddressStreetName, addressModel.AddressSuburbName, addressModel.AddressCityName, addressModel.AddressStateName, addressModel.AddressCountryName, addressModel.AddressPostcode, resturantModel.ResturantOwnerName, resturantModel.ResturantDescription, (int)resturantModel.ResturantType, null); Resturant dbResturantModel; using (var dbContext = new ResturantReviewDBContext()) { dbResturantModel = dbContext.Resturants.Where(x => x.DuplicateEquals(resturantModel)).FirstOrDefault(); result = dbResturantModel != null; dbContext.Resturants.Remove(dbResturantModel); dbContext.SaveChanges(); // Ensures test object is removed if (!result && resturantModel != null) { dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } } catch (Exception) { using (var dbContext = new ResturantReviewDBContext()) { dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } Assert.True(result); }
// Adds a test resturant to the database private IResturant SetupAddedResturant(string desiredName = "") { IResturant resturant = new Resturant(); var address = new FormalAddress(); IResturant resturantModel = null; resturant.ResturantAddress = address; if (!string.IsNullOrEmpty(desiredName)) { resturant.ResturantName = desiredName; } using (var dbContext = new ResturantReviewDBContext()) { dbContext.Resturants.Add(Resturant.ConvertToEntity(resturant)); dbContext.SaveChanges(); resturantModel = dbContext.Resturants.Where(x => x.ResturantName.Equals(resturant.ResturantName)).FirstOrDefault(); } return(resturantModel); }
public void DeleteResturant() { bool result = false; IResturant resturantModel = null; try { Resturant deletedResturant = null; resturantModel = SetupAddedResturant("testModel"); using (var _dbContext = new ResturantReviewDBContext()) { _resturantController.DeleteResturant(resturantModel.ResturantId); deletedResturant = _dbContext.Resturants.Where(x => x.ResturantName.Equals("testModel")).FirstOrDefault(); result = deletedResturant == null; if (!result) { _dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); _dbContext.SaveChanges(); } } } catch (Exception) { try { using (var dbContext = new ResturantReviewDBContext()) { dbContext.Resturants.Remove(Resturant.ConvertToEntity(resturantModel)); dbContext.SaveChanges(); } } catch (DbUpdateConcurrencyException) { } } Assert.True(result); }
public bool UpdateResturantDetails([FromRoute] dynamic resturantJson) { IResturant resturant = null; try { resturant = JsonConvert.DeserializeObject <Resturant>(resturantJson); using (var _dbContext = new ResturantReviewDBContext()) { if (resturant != null) { _dbContext.Resturants.Update(Resturant.ConvertToEntity(resturant)); _dbContext.SaveChanges(); } } return(true); } catch (Exception e) { _logger.LogError(e.Message); return(false); } }
public static Resturant ConvertToEntity(IResturant resturant) { if (resturant != null) { Resturant newResturant = new Resturant() { ResturantId = resturant.ResturantId, ResturantName = resturant.ResturantName, ResturantAddress = resturant.ResturantAddress, ResturantDescription = resturant.ResturantDescription, ResturantImage = resturant.ResturantImage, ResturantOwnerName = resturant.ResturantOwnerName, ResturantReviews = resturant.ResturantReviews, ResturantStarRating = resturant.ResturantStarRating, ResturantType = resturant.ResturantType }; return(newResturant); } else { return(null); } }
public DetailsModel(IResturant resturants) { this.resturants = resturants; }
public HomeController(IResturant resturant, IGreeter greeter) { _resturant = resturant; _greetre = greeter; }
public ListModel(IConfiguration config, IResturant resturants) { Config = config; this.resturants = resturants; }
public EditModel(IResturant resturant, IHtmlHelper htmlHelper) { this.resturant = resturant; this.htmlHelper = htmlHelper; }
public EditModel(IResturant resturantData) { _resturantData = resturantData; }