public void DefaultConstructor() { // Act ValueProviderCollection collection = new ValueProviderCollection(); // Assert Assert.AreEqual(0, collection.Count); }
public void ShouldBindAnEnumValue() { var collection = new ValueProviderCollection(); var nameValueCollection = new NameValueCollection { {"someVariable", EnumFixture.Value2.Name} }; collection.Add(new FormCollection(nameValueCollection)); var modelMetadata = new ModelMetadata(new EmptyModelMetadataProvider(), null, null, typeof(EnumFixture), "someProperty"); var bindingContext = new ModelBindingContext { ModelMetadata = modelMetadata, ValueProvider = collection, ModelName = "someVariable" }; var binderDictionary = new ModelBinderDictionary(); var binder = new EnumModelBinder(binderDictionary); var retrieved = binder.BindModel(null, bindingContext); Assert.IsInstanceOfType(retrieved, typeof(EnumFixture)); var @enum = retrieved as EnumFixture; Assert.AreEqual(EnumFixture.Value2, @enum); }
public void DefaultConstructor() { // Act ValueProviderCollection collection = new ValueProviderCollection(); // Assert Assert.Empty(collection); }
public void AddNullValueProviderThrows() { // Arrange ValueProviderCollection collection = new ValueProviderCollection(); // Act & Assert Assert.ThrowsArgumentNull( delegate { collection.Add(null); }, "item"); }
public void AddNullValueProviderThrows() { // Arrange ValueProviderCollection collection = new ValueProviderCollection(); // Act & Assert ExceptionHelper.ExpectArgumentNullException( delegate { collection.Add(null); }, "item"); }
public void SetNullValueProviderThrows() { // Arrange ValueProviderCollection collection = new ValueProviderCollection(); collection.Add(new Mock<IValueProvider>().Object); // Act & Assert Assert.ThrowsArgumentNull( delegate { collection[0] = null; }, "item"); }
public void ListWrappingConstructor() { // Arrange List<IValueProvider> list = new List<IValueProvider>() { new Mock<IValueProvider>().Object, new Mock<IValueProvider>().Object }; // Act ValueProviderCollection collection = new ValueProviderCollection(list); // Assert CollectionAssert.AreEqual(list, collection); }
public void SetItem() { // Arrange ValueProviderCollection collection = new ValueProviderCollection(); collection.Add(new Mock<IValueProvider>().Object); IValueProvider newProvider = new Mock<IValueProvider>().Object; // Act collection[0] = newProvider; // Assert Assert.AreEqual(1, collection.Count); Assert.AreEqual(newProvider, collection[0]); }
public void SetItem() { // Arrange ValueProviderCollection collection = new ValueProviderCollection(); collection.Add(new Mock<IValueProvider>().Object); IValueProvider newProvider = new Mock<IValueProvider>().Object; // Act collection[0] = newProvider; // Assert IValueProvider provider = Assert.Single(collection); Assert.Equal(newProvider, provider); }
private static void InitializeController(Controller moduleController, ModuleRequestContext moduleRequestContext) { moduleController.ControllerContext = new ControllerContext(moduleRequestContext, moduleController); var pageControllerContext = moduleRequestContext.PageControllerContext; var valueProvider = new ValueProviderCollection(); valueProvider.Add(new ModuleFormValueProvider(moduleController.ControllerContext)); valueProvider.Add(new ModuleQueryStringValueProvider(moduleController.ControllerContext)); valueProvider.Add(new RouteDataValueProvider(moduleController.ControllerContext)); if (Kooboo.CMS.Sites.View.Page_Context.Current.PageRequestContext != null) { valueProvider.Add(new NameValueCollectionValueProvider(Kooboo.CMS.Sites.View.Page_Context.Current.PageRequestContext.AllQueryString, System.Globalization.CultureInfo.InvariantCulture)); } valueProvider.Add(pageControllerContext.Controller.ValueProvider); moduleController.ValueProvider = valueProvider; moduleController.TempDataProvider = new ModuleSessionStateTempDataProvider(); moduleController.Url = new UrlHelper(moduleController.ControllerContext.RequestContext, moduleRequestContext.ModuleContext.RouteTable); }
public void ContainsPrefix() { // Arrange string prefix = "somePrefix"; Mock<IValueProvider> mockProvider1 = new Mock<IValueProvider>(); mockProvider1.Setup(p => p.ContainsPrefix(prefix)).Returns(false); Mock<IValueProvider> mockProvider2 = new Mock<IValueProvider>(); mockProvider2.Setup(p => p.ContainsPrefix(prefix)).Returns(true); Mock<IValueProvider> mockProvider3 = new Mock<IValueProvider>(); mockProvider3.Setup(p => p.ContainsPrefix(prefix)).Returns(false); ValueProviderCollection collection = new ValueProviderCollection() { mockProvider1.Object, mockProvider2.Object, mockProvider3.Object }; // Act bool retVal = collection.ContainsPrefix(prefix); // Assert Assert.IsTrue(retVal); }
public void GetValue() { // Arrange string key = "someKey"; Mock<IValueProvider> mockProvider1 = new Mock<IValueProvider>(); mockProvider1.Setup(p => p.GetValue(key)).Returns((ValueProviderResult)null); Mock<IValueProvider> mockProvider2 = new Mock<IValueProvider>(); mockProvider2.Setup(p => p.GetValue(key)).Returns(new ValueProviderResult("2", "2", null)); Mock<IValueProvider> mockProvider3 = new Mock<IValueProvider>(); mockProvider3.Setup(p => p.GetValue(key)).Returns(new ValueProviderResult("3", "3", null)); ValueProviderCollection collection = new ValueProviderCollection() { mockProvider1.Object, mockProvider2.Object, mockProvider3.Object }; // Act ValueProviderResult result = collection.GetValue(key); // Assert Assert.IsNotNull(result); Assert.AreEqual(2, result.ConvertTo(typeof(int))); }
public void GetValueFromProvider_EnumeratedProvider_NotFound_DoNotReturnNull() { // Arrange IDictionary<string, string> expectedResult = new Dictionary<string, string>() { { "random", "random.hello" } }; Mock<IEnumerableValueProvider> mockProvider = new Mock<IEnumerableValueProvider>(); mockProvider.Setup(o => o.GetKeysFromPrefix("notfound")).Returns(expectedResult); ValueProviderCollection providerCollection = new ValueProviderCollection(new List<IValueProvider>() { mockProvider.Object }); // Act IDictionary<string, string> actualResult = providerCollection.GetKeysFromPrefix("prefix"); // Assert Assert.NotNull(actualResult); Assert.Empty(actualResult); }
private HiveId ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext) { var modelBinder = new HiveIdModelBinder(); var httpContextFactory = new FakeHttpContextFactory("~/Rebel/Editors/ContentEditor/Edit/1", routeData); var fakeFrameworkContext = new FakeFrameworkContext(); var hive = FakeHiveCmsManager.New(fakeFrameworkContext); var appContext = new FakeRebelApplicationContext(hive); var resolverContext = new MockedMapResolverContext(fakeFrameworkContext, hive, new MockedPropertyEditorFactory(appContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(fakeFrameworkContext) })); var rebelApplicationContext = new FakeRebelApplicationContext(hive); controllerContext = new ControllerContext( httpContextFactory.RequestContext, new ContentEditorController(new FakeBackOfficeRequestContext(rebelApplicationContext))); //put both the form and route values in the value provider var routeDataValueProvider = new RouteDataValueProvider(controllerContext); var values = new ValueProviderCollection(new List<IValueProvider>() { form, routeDataValueProvider }); bindingContext = GetBindingContext(new HiveId(1), values); //do the binding! var model = modelBinder.BindModel(controllerContext, bindingContext); //assert! Assert.That(model, Is.InstanceOf<HiveId>(), "Model isn't a HiveId"); var boundModel = (HiveId)model; return boundModel; }