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); }
public void Should_Return_Current_Principal() { var accessor = new Mock <IHttpContextAccessor>(); var contextMock = new HttpContextMoq(); var fakePrincipal = new GenericPrincipal(new GenericIdentity("TEST"), null); contextMock.MockContext.Setup(r => r.User).Returns(() => fakePrincipal); accessor.Setup(r => r.GetCurrent()).Returns(() => contextMock.MockContext.Object); var provider = new DefaultWebPrincipalProvider(accessor.Object); var principal = provider.GetCurrentPrincipal(); Assert.AreEqual(principal, fakePrincipal); }
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); }