public void BuildChannelListener_Adds_HttpMessageEncodingBindingElement_To_Binding_Parameters_Collection() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); MockBindingContext context = MockBindingContext.CreateWithMockTransport(); encoding.BuildChannelListener <IReplyChannel>(context); Assert.IsNotNull(context.BindingParameters.Find <HttpMessageEncodingBindingElement>(), "The HttpMessageEncodingBindingElement should have been added to the collection of binding parameters."); }
public void BuildChannelListener_Returns_Null_If_Inner_BindingElement_Returns_Null() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); MockBindingContext context = MockBindingContext.CreateWithMockTransport(); IChannelListener <IReplyChannel> listener = encoding.BuildChannelListener <IReplyChannel>(context); Assert.IsNull(listener, "HttpMessageEncodingBindingElement.BuildChannelListener should have null since the inner binding element returned null."); }
public void BuildChannelFactory_Throws() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelFactoryNotSupportedByHttpMessageEncodingBindingElement(typeof(HttpMessageEncodingBindingElement).Name), () => { encoding.BuildChannelFactory <IReplyChannel>(MockBindingContext.Create()); }); }
public void BuildChannelFactory_Throws() { HttpMessageHandlerBindingElement bindingElement = new HttpMessageHandlerBindingElement(); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelFactoryNotSupported(typeof(HttpMessageHandlerBindingElement).Name, typeof(IChannelFactory <IReplyChannel>).Name), () => { bindingElement.BuildChannelFactory <IReplyChannel>(MockBindingContext.Create()); }); }
public void BuildChannelFactory_Throws() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelFactory should have thrown.", () => { encoding.BuildChannelFactory <IReplyChannel>(MockBindingContext.Create()); }); }
public void CanBuildChannelListener_Only_Returns_True_For_IReplyChannel() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); Assert.IsTrue(encoding.CanBuildChannelListener <IReplyChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should have returned 'true'."); Assert.IsFalse(encoding.CanBuildChannelListener <IReplySessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IRequestChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IRequestSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IOutputChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IOutputSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IInputChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IInputSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IDuplexChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); Assert.IsFalse(encoding.CanBuildChannelListener <IDuplexSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelListener should always return 'false' for non IReplyChannel shapes."); }
public void CanBuildChannelFactory_Always_Returns_False() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); Assert.IsFalse(encoding.CanBuildChannelFactory <IReplyChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IReplySessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IRequestChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IRequestSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IOutputChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IOutputSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IInputChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IInputSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IDuplexChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); Assert.IsFalse(encoding.CanBuildChannelFactory <IDuplexSessionChannel>(MockBindingContext.Create()), "HttpMessageEncodingBindingElement.CanBuildChannelFactory should always return 'false'."); }
private void DoTest( Action<MockBindingContext> action, Func<MockBindingContext, object> findTargetObjectFunc, MvxBindingDescription expectedDescription) { ClearAll(); MvxBindingSingletonCache.Initialize(); var dataContext = new TestDataContext(); var bindingContext = new Mock<IMvxBindingContext>(); bindingContext.Setup(x => x.RegisterBinding(It.IsAny<object>(), It.IsAny<IMvxUpdateableBinding>())); bindingContext.SetupGet(x => x.DataContext).Returns(dataContext); var callbacksSeen = new List<Callback>(); var binder = new Mock<IMvxBinder>(); binder.Setup( b => b.Bind(It.IsAny<object>(), It.IsAny<object>(), It.IsAny<IEnumerable<MvxBindingDescription>>())) .Callback((object source, object target, IEnumerable<MvxBindingDescription> descriptions) => { if (descriptions.Count() != 1) throw new Exception("Unexpected description count"); callbacksSeen.Add(new Callback { Source = source, Target = target, BindingDescription = descriptions.First() }); }); Ioc.RegisterSingleton(binder.Object); Ioc.RegisterSingleton<IMvxPropertyExpressionParser>(new MvxPropertyExpressionParser()); var converterLookup = new MvxValueConverterRegistry(); converterLookup.AddOrOverwrite("SampleConv", new SampleValueConverter()); Ioc.RegisterSingleton<IMvxValueConverterLookup>(converterLookup); var testTarget = new MockBindingContext { Target = new TestTarget(), BindingContext = bindingContext.Object }; action(testTarget); Assert.AreEqual(1, callbacksSeen.Count); var callback = callbacksSeen[0]; var expectedTarget = findTargetObjectFunc(testTarget); Assert.AreEqual(expectedTarget, callback.Target); Assert.AreEqual(dataContext, callback.Source); var desc = callback.BindingDescription; Assert.IsTrue(expectedDescription.Source is MvxPathSourceStepDescription); var path = desc.Source as MvxPathSourceStepDescription; Assert.IsTrue(desc.Source is MvxPathSourceStepDescription); var expectedPath = expectedDescription.Source as MvxPathSourceStepDescription; Assert.AreEqual(expectedPath.ConverterParameter, path.ConverterParameter); Assert.AreEqual(expectedPath.FallbackValue, path.FallbackValue); Assert.AreEqual(expectedPath.SourcePropertyPath, path.SourcePropertyPath); Assert.AreEqual(expectedDescription.Mode, desc.Mode); Assert.AreEqual(expectedDescription.TargetName, desc.TargetName); if (expectedPath.Converter == null) Assert.IsNull(path.Converter); else Assert.AreEqual(expectedPath.Converter.GetType(), path.Converter.GetType()); }
private void DoTest( Action <MockBindingContext> action, Func <MockBindingContext, object> findTargetObjectFunc, MvxBindingDescription expectedDescription) { ClearAll(); MvxBindingSingletonCache.Initialize(); var dataContext = new TestDataContext(); var bindingContext = new Mock <IMvxBindingContext>(); bindingContext.Setup(x => x.RegisterBinding(It.IsAny <object>(), It.IsAny <IMvxUpdateableBinding>())); bindingContext.SetupGet(x => x.DataContext).Returns(dataContext); var callbacksSeen = new List <Callback>(); var binder = new Mock <IMvxBinder>(); binder.Setup( b => b.Bind(It.IsAny <object>(), It.IsAny <object>(), It.IsAny <IEnumerable <MvxBindingDescription> >())) .Callback((object source, object target, IEnumerable <MvxBindingDescription> descriptions) => { if (descriptions.Count() != 1) { throw new Exception("Unexpected description count"); } callbacksSeen.Add(new Callback { Source = source, Target = target, BindingDescription = descriptions.First() }); }); Ioc.RegisterSingleton(binder.Object); Ioc.RegisterSingleton <IMvxPropertyExpressionParser>(new MvxPropertyExpressionParser()); var converterLookup = new MvxValueConverterRegistry(); converterLookup.AddOrOverwrite("SampleConv", new SampleValueConverter()); Ioc.RegisterSingleton <IMvxValueConverterLookup>(converterLookup); var testTarget = new MockBindingContext { Target = new TestTarget(), BindingContext = bindingContext.Object }; action(testTarget); Assert.AreEqual(1, callbacksSeen.Count); var callback = callbacksSeen[0]; var expectedTarget = findTargetObjectFunc(testTarget); Assert.AreEqual(expectedTarget, callback.Target); Assert.AreEqual(dataContext, callback.Source); var desc = callback.BindingDescription; Assert.IsTrue(expectedDescription.Source is MvxPathSourceStepDescription); var path = desc.Source as MvxPathSourceStepDescription; Assert.IsTrue(desc.Source is MvxPathSourceStepDescription); var expectedPath = expectedDescription.Source as MvxPathSourceStepDescription; Assert.AreEqual(expectedPath.ConverterParameter, path.ConverterParameter); Assert.AreEqual(expectedPath.FallbackValue, path.FallbackValue); Assert.AreEqual(expectedPath.SourcePropertyPath, path.SourcePropertyPath); Assert.AreEqual(expectedDescription.Mode, desc.Mode); Assert.AreEqual(expectedDescription.TargetName, desc.TargetName); if (expectedPath.Converter == null) { Assert.IsNull(path.Converter); } else { Assert.AreEqual(expectedPath.Converter.GetType(), path.Converter.GetType()); } }
public void BuildChannelListener_Throws_For_Non_IReplyChannel() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IReplySessionChannel).Name), () => { encoding.BuildChannelListener <IReplySessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IRequestChannel).Name), () => { encoding.BuildChannelListener <IRequestChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IRequestSessionChannel).Name), () => { encoding.BuildChannelListener <IRequestSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IOutputChannel).Name), () => { encoding.BuildChannelListener <IOutputChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IOutputSessionChannel).Name), () => { encoding.BuildChannelListener <IOutputSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IInputChannel).Name), () => { encoding.BuildChannelListener <IInputChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IInputSessionChannel).Name), () => { encoding.BuildChannelListener <IInputSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IDuplexChannel).Name), () => { encoding.BuildChannelListener <IDuplexChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.ChannelShapeNotSupportedByHttpMessageEncodingBindingElement(typeof(IDuplexSessionChannel).Name), () => { encoding.BuildChannelListener <IDuplexSessionChannel>(MockBindingContext.Create()); }); }
public void BuildChannelListener_Returns_ChannelListener_For_IReplyChannel() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); IChannelListener <IReplyChannel> listener = encoding.BuildChannelListener <IReplyChannel>(MockBindingContext.Create()); Assert.IsNotNull(listener, "HttpMessageEncodingBindingElement.BuildChannelListener should have returned an instance."); Assert.IsInstanceOfType(listener, typeof(HttpMessageEncodingChannelListener), "HttpMessageEncodingBindingElement.BuildChannelListener should have returned an HttpMessageEncodingChannelListener."); }
public void BuildChannelListener_Throws_For_Non_IReplyChannel() { HttpMessageHandlerBindingElement bindingElement = new HttpMessageHandlerBindingElement(); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IReplySessionChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IReplySessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IRequestChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IRequestChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IRequestSessionChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IRequestSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IOutputChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IOutputChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IOutputSessionChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IOutputSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IInputChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IInputChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IInputSessionChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IInputSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IDuplexChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IDuplexChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws <NotSupportedException>( SR.HttpMessageHandlerChannelInvalidChannelShape(typeof(IDuplexSessionChannel).Name, typeof(HttpMessageHandlerBindingElement).Name, typeof(IReplyChannel).Name), () => { bindingElement.BuildChannelListener <IDuplexSessionChannel>(MockBindingContext.Create()); }); }
public void BuildChannelListener_Throws_For_Non_IReplyChannel() { HttpMessageEncodingBindingElement encoding = new HttpMessageEncodingBindingElement(); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IReplySessionChannel.", () => { encoding.BuildChannelListener <IReplySessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IRequestChannel.", () => { encoding.BuildChannelListener <IRequestChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IRequestSessionChannel.", () => { encoding.BuildChannelListener <IRequestSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IOutputChannel.", () => { encoding.BuildChannelListener <IOutputChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IOutputSessionChannel.", () => { encoding.BuildChannelListener <IOutputSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IInputChannel.", () => { encoding.BuildChannelListener <IInputChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IInputSessionChannel.", () => { encoding.BuildChannelListener <IInputSessionChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IDuplexChannel.", () => { encoding.BuildChannelListener <IDuplexChannel>(MockBindingContext.Create()); }); ExceptionAssert.Throws( typeof(NotSupportedException), "HttpMessageEncodingBindingElement.BuildChannelListener should have thrown for IDuplexSessionChannel.", () => { encoding.BuildChannelListener <IDuplexSessionChannel>(MockBindingContext.Create()); }); }