public BusinessesControllerTests() { var list = new List <Business> { new Business { Id = 1, Name = "test 1", CountryId = 2 }, new Business { Id = 2, Name = "test 2", CountryId = 1 } }.AsQueryable(); var mockContext = Substitute.For <TtContext>(); var businessRepository = Substitute.For <Repository <Business> >(mockContext); var countryRepository = Substitute.For <Repository <Country> >(mockContext); _service = Substitute.For <BusinessService>(businessRepository, countryRepository); _service.GetList().Returns(list); _service.GetItem(Arg.Any <int>()).Returns(new Business { Id = 1, Name = "test 1", CountryId = 1 }); _service.Create(Arg.Any <Business>()); _service.Update(Arg.Any <int>(), Arg.Any <Business>()); _service.Delete(Arg.Any <int>()); var mockLogger = Substitute.For <ILoggerFactory>(); _controller = new BusinessesController(_service, mockLogger); }
///////////////////////////////////////// // method to create business to register ///////////////////////////////////////// public async Task <IActionResult> Register(BusinessForRegisterDto business) { // AMIT helpME still need to check later if business already exists Business newB = new Business(); Console.WriteLine(business.BHome); foreach (var field in business.GetType().GetProperties()) { PropertyInfo pi = newB.GetType().GetProperty(field.Name); if (pi != null) { //skipping if field does not exists if (field.Name.Equals("BOwner")) { newB.BOwner[0] = business.BOwner[0]; } else { pi.SetValue(newB, field.GetValue(business)); } } } /////////////////////////////////////////////////////////////////// //send business to service /////////////////////////////////////////////////////////////////// await _businessService.Create(newB); Appointment app = new Appointment(); app.BName = newB.BName; await _businessService.setAppointment(app); return(Ok(newB)); }
public IActionResult DoCreate(string testament, string book, int chapter, int verse, string text) { ViewBag.Message = "Verse Could Not Be Added. SadFace"; if (service.Create(testament, book, chapter, verse, text)) { ViewBag.Message = "Verse Added"; } return(View("Index")); }
public void Register() { AddressValidator addressValidator = new AddressValidator(); var repositoryMock = new Mock <IBusinessRepository>(); var accountManagerMock = new Mock <IAccountManager <Business> >(); accountManagerMock.Setup(x => x.CreateUser(business, password, repositoryMock.Object)); repositoryMock.Setup(x => x.CheckIfExist(business.Email, business.CompanyName)).Returns(false); IBusinessService businessService = new BusinessService(repositoryMock.Object, null, accountManagerMock.Object, addressValidator); Assert.Throws <ValidationException>(() => businessService.Create(business, password)); business.Address = address; businessService.Create(business, password); accountManagerMock.Verify(x => x.CreateUser(business, password, repositoryMock.Object), Times.Once); }
public ActionResult <Business> Create(Business business) { _businessService.Create(business); return(CreatedAtRoute("GetBook", new { id = business.Id.ToString() }, business)); }