Exemplo n.º 1
0
        public void Should_Register_Scope_In_The_Context_Container()
        {
            var contextMock         = new HttpContextMoq();
            var htttContextAccessor = new Mock <IHttpContextAccessor>();

            htttContextAccessor
            .Setup(m => m.GetCurrent())
            .Returns(() => contextMock.MockContext.Object);

            var dictionary = new Dictionary <object, object>();

            contextMock.MockContext.Setup(m => m.Items).Returns(dictionary);

            var provider = new PerWebRequestContainerProvider(htttContextAccessor.Object);

            var scope1 = provider.CurrentScope;

            Assert.IsNotNull(scope1);
            Assert.AreEqual(dictionary.Count, 1);
            Assert.AreEqual(((KeyValuePair <object, object>)dictionary.First()).Value, scope1);

            var scope2 = provider.CurrentScope;

            Assert.AreEqual(scope1, scope2);
            Assert.AreEqual(dictionary.Count, 1);
            Assert.AreEqual(((KeyValuePair <object, object>)dictionary.First()).Value, scope2);
        }
Exemplo n.º 2
0
        /// <summary>
        /// When overridden, provides an entry point for custom authorization checks.
        /// </summary>
        /// <param name="httpContext">The HTTP context, which encapsulates all HTTP-specific information about an individual HTTP request.</param>
        /// <returns>
        /// true if the user is authorized; otherwise, false.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">if httpContext is null.</exception>
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            var container = PerWebRequestContainerProvider.GetLifetimeScope(httpContext);

            if (container != null && container.IsRegistered <ISecurityService>())
            {
                var security = container.Resolve <ISecurityService>();
                return(security.IsAuthorized(httpContext.User, Roles));
            }

            return(base.AuthorizeCore(httpContext));
        }
Exemplo n.º 3
0
        public void ShouldResolve_Commands_Successfully()
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType(typeof(CommandTest)).AsSelf();
            ContextScopeProvider.RegisterTypes(containerBuilder);

            var httpContextMoq = new HttpContextMoq();
            var accessor       = new Mock <IHttpContextAccessor>();

            accessor
            .Setup(a => a.GetCurrent())
            .Returns(() => httpContextMoq.HttpContextBase);

            var provider = new PerWebRequestContainerProvider(accessor.Object);
            var resolver = new DefaultCommandResolver(provider);

            var commandContext = new CommandContextTest();
            var command        = resolver.ResolveCommand <CommandTest>(commandContext);

            Assert.IsNotNull(command);
            Assert.AreEqual(command.Context, commandContext);
        }
Exemplo n.º 4
0
 public PageStylesheetProjectionFactory(PerWebRequestContainerProvider containerProvider, IRepository repository)
 {
     this.containerProvider = containerProvider;
     this.repository        = repository;
 }
 public PageStylesheetProjectionFactory(PerWebRequestContainerProvider containerProvider)
 {
     this.containerProvider = containerProvider;
 }
Exemplo n.º 6
0
 public DefaultCommandResolver(PerWebRequestContainerProvider containerProvider)
 {
     this.containerProvider = containerProvider;
 }
Exemplo n.º 7
0
 public DefaultWebControllerFactory(PerWebRequestContainerProvider containerProvider)
 {
     this.containerProvider = containerProvider;
 }
 public PageContentProjectionFactory(PerWebRequestContainerProvider containerProvider, IUnitOfWork unitOfWork)
 {
     this.containerProvider = containerProvider;
     this.unitOfWork        = unitOfWork;
 }
Exemplo n.º 9
0
 public FakePageContentProjectionFactory(PerWebRequestContainerProvider containerProvider, IUnitOfWork unitOfWork)
     : base(containerProvider, unitOfWork)
 {
 }
 public PageJavaScriptProjectionFactory(PerWebRequestContainerProvider containerProvider)
 {
     this.containerProvider = containerProvider;
 }