Exemplo n.º 1
0
        public void AttachFilterEventHandler_AttachToCompatibleHandler(string handlerAssemblyName, string handlerTypeName)
        {
            // Arrange
            var container = Mocks.Create<IContainer>();
            container.Setup(c => c.Resolve<IHtmlBuilder>()).Returns(Mocks.Create<IHtmlBuilder>().Object);

            var response = Mocks.Create<HttpResponseBase>();
            response.Setup(r => r.ContentType).Returns(ContentTypes.Html);
            response.Setup(r => r.Filter).Returns(new MemoryStream());
            response.SetupSet(r => r.Filter = It.IsAny<HttpResponseFilter>());

            var handlerAssembly = Assembly.Load(handlerAssemblyName);
            var handlerType = handlerAssembly.GetType(handlerTypeName);
            var handler = (IHttpHandler)Activator.CreateInstance(handlerType, new RequestContext());

            var context = Mocks.Create<HttpContextBase>();
            context.Setup(c => c.Items.Contains(HttpModule.ContainerKey)).Returns(false);
            context.Setup(c => c.Items.Add(HttpModule.ContainerKey, true));
            context.Setup(c => c.CurrentHandler).Returns(handler);
            context.Setup(c => c.Response).Returns(response.Object);

            var module = new HttpModule(context.Object, container.Object, null, null);

            // Act
            module.AttachFilterEventHandler(null, null);

            // Assert
            Mocks.VerifyAll();
        }
Exemplo n.º 2
0
        public void AttachFilterEventHAndler_AlreadyAttached()
        {
            // Arrange
            var context = Mocks.Create<HttpContextBase>();
            context.Setup(c => c.Items.Contains(HttpModule.ContainerKey)).Returns(true);

            var module = new HttpModule(context.Object, null, null, null);

            // Act
            module.AttachFilterEventHandler(null, null);

            // Assert
            Mocks.VerifyAll();
        }