public void CanReturnServiceIfInitializedAndRegistered() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For <IValidator>().ImplementedBy <Validator>().Named("validator")); ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); IValidator validatorService = SmartServiceLocator <IValidator> .GetService(); Assert.IsNotNull(validatorService); }
public void WillBeInformedIfServiceLocatorNotInitialized() { bool exceptionThrown = false; try { SmartServiceLocator <IValidator> .GetService(); } catch (NullReferenceException e) { exceptionThrown = true; Assert.IsTrue(e.Message.Contains("ServiceLocator has not been initialized")); } Assert.IsTrue(exceptionThrown); }
public void WillBeInformedIfServiceNotRegistered() { bool exceptionThrown = false; IWindsorContainer container = new WindsorContainer(); ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); try { SmartServiceLocator <IValidator> .GetService(); } catch (ActivationException e) { exceptionThrown = true; Assert.IsTrue(e.Message.Contains("IValidator could not be located")); } Assert.IsTrue(exceptionThrown); }
public void Setup() { _builder = new TestControllerBuilder(); _controller = _builder.CreateController <SampleController>(); //Required by .NET4.5+ to invoke actions System.Web.HttpContext.Current = new System.Web.HttpContext(new System.Web.HttpRequest("foo", "http://tempuri.org/foo", ""), new System.Web.HttpResponse(new StringWriter())); ServiceLocatorInitializer.InitWithFakeDBContext(); _dbContext = SmartServiceLocator <IDbContext> .GetService(); _dbContext.Stub(x => x.IsActive).Repeat.Any().Return(true); _dbContext.Stub(x => x.BeginTransaction()).Repeat.Any().WhenCalled(x => _beginTransactionCount++); _dbContext.Stub(x => x.CommitTransaction()).Repeat.Any().WhenCalled(x => _commitTransactionCount++); _dbContext.Stub(x => x.CloseSession()).Repeat.Any().WhenCalled(x => _closeSessionCount++); }
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext) { // load the user and make sure they are valid var userName = httpContext.User.Identity.Name; var membership = new AccountMembershipService(); var result = membership.IsValidUser(userName); if (result) { // load the site id var siteId = httpContext.Request.RequestContext.RouteData.Values["site"]; var personRepository = SmartServiceLocator <IRepositoryWithTypedId <Person, string> > .GetService(); var person = personRepository.Queryable.First(a => a.User.LoweredUserName == userName.ToLower()); //httpContext.Result = new System.Web.Mvc.HttpStatusCodeResult((int)System.Net.HttpStatusCode.Forbidden); return(person.Sites.Any(a => a.Id == (string)siteId)); } return(false); }
public static ICollection <IValidationResult> GetValidationResultsFor(object obj) { var validator = SmartServiceLocator <IValidator> .GetService(); return(validator.ValidationResultsFor(obj)); }
public TransactionScope() { _dbContext = SmartServiceLocator <IDbContext> .GetService(); _dbContext.BeginTransaction(); }