public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <SomeType> overrider) { overrider.GetBlockBuilderForCollection(x => x.Prop1) .SetMultipleDropDownList <SomeDataProviderForSelectList>(); return(Task.CompletedTask); }
public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <SomeModel> overrider) { overrider.GetBlockBuilder(x => x.Prop1) .SetDropDownList <SomeSelectListDataProvider>(); return(Task.CompletedTask); }
public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <SomeType> overrider) { overrider.GetBlockBuilder(x => x.Name) .SetAutoCompleteFor <SomeDataProvider>(); return(Task.CompletedTask); }
public void TestClassOnComplexArrayProp() { var result = new GenericUserInterfaceModelBuilder <ClassWithComplexArrayProp>(TestsHelper.CreateDefaultBag()).Result; Assert.AreEqual(1, result.Interface.Blocks.Count); var block = result.Interface.Blocks.First(); Assert.AreEqual(nameof(ClassWithComplexArrayProp.Property), block.PropertyName); Assert.AreEqual(UserInterfaceType.GenericInterfaceForArray, block.InterfaceType); var innerInterface = block.InnerGenericInterface; Assert.AreEqual(nameof(ClassWithComplexArrayProp.Property), innerInterface.Prefix); Assert.AreEqual(2, innerInterface.Blocks.Count); var firstBlock = innerInterface.Blocks.First(); Assert.AreEqual(nameof(SomeComplexType.Name), firstBlock.PropertyName); var lastBlock = innerInterface.Blocks.Last(); Assert.AreEqual(nameof(SomeComplexType.Description), lastBlock.PropertyName); }
public void Test() { var builder = new GenericUserInterfaceModelBuilder <SomeType>(TestsHelper.CreateDefaultBag()); var result = builder.Result.Interface; var block0 = result.Blocks[0]; Assert.AreEqual(block0.PropertyName, nameof(SomeType.Property1)); Assert.AreEqual(block0.InterfaceType, UserInterfaceType.TextBox); var block1 = result.Blocks[1]; var innerInterface = block1.InnerGenericInterface; Assert.AreEqual(nameof(SomeType.CreatedOn), innerInterface.Prefix); Assert.AreEqual(UserInterfaceType.GenericInterfaceForClass, block1.InterfaceType); Assert.AreEqual(block1.PropertyName, nameof(SomeType.CreatedOn)); var innerInterfaceBlock1 = innerInterface.Blocks.First(); Assert.AreEqual(innerInterfaceBlock1.PropertyName, nameof(SomeType.CreatedOn.Min)); Assert.AreEqual(UserInterfaceType.DatePicker, innerInterfaceBlock1.InterfaceType); var innerInterfaceBlock2 = innerInterface.Blocks.Last(); Assert.AreEqual(innerInterfaceBlock2.PropertyName, nameof(SomeType.CreatedOn.Max)); Assert.AreEqual(UserInterfaceType.DatePicker, innerInterfaceBlock2.InterfaceType); }
public void TestImplementingMultipleDropDownForToNotEnumerableProperty() { var builder = new GenericUserInterfaceModelBuilder <SomeType>(TestsHelper.CreateDefaultBag()); var ex = Assert.Throws <InvalidOperationException>(() => builder.GetBlockBuilderForCollection(x => x.Prop1)); Assert.AreEqual(ex.Message, ExceptionTexts.DontUseGetBlockBuilderForCollectionOnCollectionsOfChars); }
public void ShiftToEndForTest() { var builder = new GenericUserInterfaceModelBuilder <SomeClass>(TestsHelper.CreateDefaultBag()); builder.ShiftToEndFor(x => x.Property2); Assert.IsTrue(builder.Result.Interface.Blocks.Last().PropertyName == nameof(SomeClass.Property2)); }
public void CheckInterfaceGenerationOnPrimitives(Type type) { var ex = Assert.Throws <InvalidOperationException>(() => { var res = new GenericUserInterfaceModelBuilder(type).Result; }); Assert.AreEqual(ExceptionTexts.NonComplexTypesAreNotSupported, ex.Message); }
public void TestClassWithByteArrayProp() { var result = new GenericUserInterfaceModelBuilder <ClassWithByteProp>(TestsHelper.CreateDefaultBag()).Result; var block = result.Interface.Blocks.First(); Assert.AreEqual(nameof(ClassWithByteProp.Property), block.LabelText); Assert.AreEqual(UserInterfaceType.MultipleDropDownList, block.InterfaceType); Assert.AreEqual(0, block.DropDownData.SelectList.Count); }
public void ShiftToStartForTest() { var builder = new GenericUserInterfaceModelBuilder <SomeClass>(TestsHelper.CreateDefaultBag()); builder.ShiftToStartFor(x => x.Property); var result = builder.Result; Assert.IsTrue(result.Interface.Blocks.First().PropertyName == nameof(SomeClass.Property)); }
public void TestListOfStringPoperty() { var result = new GenericUserInterfaceModelBuilder <SomeClass>(TestsHelper.CreateDefaultBag()).Result; var block = result.Interface.Blocks.First(t => t.PropertyName == nameof(SomeClass.Property2)); Assert.AreEqual(nameof(SomeClass.Property2), block.LabelText); Assert.AreEqual(UserInterfaceType.MultipleDropDownList, block.InterfaceType); Assert.IsTrue(block.DropDownData.SelectList.Count == 0); }
private static async Task <GenerateGenericUserInterfaceModel> GetModelByType(Type type, string modelPrefix, bool useOverridings) { var result = new GenericUserInterfaceModelBuilder(type, modelPrefix).Result; if (!useOverridings) { return(result); } await result.OverrideAsync(ApiMapOverridings.GetOverridings()); return(result); }
public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <SomeTypeToOverride> builder) { builder.GetBlockBuilder(x => x.SomeProperty).SetLabel(LabelText).SetDropDownList(new List <SelectListItemData <string> > { new SelectListItemData <string> { Text = "Text", Selected = true, Value = "SomeValue" } }); return(Task.CompletedTask); }
public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <SomeInnerType> overrider) { overrider.GetBlockBuilder(x => x.Prop1) .SetDropDownList(new List <SelectListItemData <string> > { new SelectListItemData <string> { Selected = true, Text = "Text", Value = "Value" } }); return(Task.CompletedTask); }
public void Test() { var interfaceModel = new GenericUserInterfaceModelBuilder <TypeWithInteger>(TestsHelper.CreateDefaultBag()).Result; var prop1Block = interfaceModel.Interface.Blocks.First(); Assert.AreEqual(UserInterfaceType.NumberBox, prop1Block.InterfaceType); var textBoxData = prop1Block.NumberBoxData; Assert.IsNotNull(textBoxData); Assert.IsTrue(textBoxData.IsInteger); Assert.AreEqual(Tool.JsonConverter.Serialize(int.MinValue), textBoxData.MinValue); Assert.AreEqual(Tool.JsonConverter.Serialize(int.MaxValue), textBoxData.MaxValue); }
/// <summary> /// Получить переопределитель /// </summary> /// <returns></returns> public Overrider GetOverrider() { return(new Overrider { MainOverrideFunction = (bag, model) => { var builder = new GenericUserInterfaceModelBuilder <T>(model, bag); return OverrideInterfaceAsync(bag, builder); }, SetDropDownDatasFunction = (bag, model) => { return ProccessDropDownDatas(bag, model); } }); }
public void ToEnumProperty_ShouldThrowException() { var builder = new GenericUserInterfaceModelBuilder <SomeClass>(TestsHelper.CreateDefaultBag()); var ex = Assert.Throws <InvalidOperationException>(() => builder.GetBlockBuilder(x => x.EnumProp).SetDropDownList(new List <SelectListItemData <SomeEnumType> >() { new SelectListItemData <SomeEnumType> { Selected = true, Value = SomeEnumType.Type1, } })); var expectedMessage = string.Format(ExceptionTexts.CantImplementSetDropListNameToEnumPropertyFormat, nameof(SomeClass.EnumProp)); Assert.AreEqual(expectedMessage, ex.Message); }
public void NullableEnumTest() { var result = new GenericUserInterfaceModelBuilder <Type1WithNullableEnum>(TestsHelper.CreateDefaultBag()).Result; var fProp = result.Interface.Blocks.First(); Assert.AreEqual(Enumerations.UserInterfaceType.DropDownList, fProp.InterfaceType); var selectList = fProp.DropDownData.SelectList; Assert.AreEqual(3, selectList.Count); var fItem = selectList.First(); Assert.IsTrue(fItem.Selected); Assert.IsNull(fItem.Value); }
public void Test() { var builder = new GenericUserInterfaceModelBuilder <SomeClass>(TestsHelper.CreateDefaultBag()); var list = new List <SelectListItemData <bool?> > { new SelectListItemData <bool?> { Selected = true, Text = "Text", } }; builder.GetBlockBuilder(x => x.Sex).SetDropDownList(list); var lastProp = builder.Result.Interface.Blocks.Last(); Assert.IsTrue(lastProp.InterfaceType == UserInterfaceType.DropDownList); TestsHelper.AssertAreEqualViaJson(GenericUserInterfaceModelBuilderMappings.ToSelectListItems(list), lastProp.DropDownData.SelectList); }
public void NullableBoolTest() { var builder = new GenericUserInterfaceModelBuilder <Type1>(TestsHelper.CreateDefaultBag()); var result = builder.Result.Interface; Assert.AreEqual(1, result.Blocks.Count); var block = result.Blocks.First(); Assert.AreEqual(UserInterfaceType.DropDownList, block.InterfaceType); var selectList = block.DropDownData.SelectList; Assert.IsTrue(selectList.Count == 3); var firstSelectItem = selectList.First(); Assert.IsTrue(firstSelectItem.Selected); Assert.IsNull(firstSelectItem.Value); }
public void SetOnEnumerableOfPrimitives_ShouldBeOk() { var propName = nameof(SomeType.Prop4); var defaultValue = ""; var interfaceModel = new GenericUserInterfaceModelBuilder <SomeType>(TestsHelper.CreateDefaultBag()) .GetBlockBuilderForCollection(x => x.Prop4) .SetMultipleDropDownList(new List <SelectListItemData <string> > { new SelectListItemData <string> { Selected = true, Text = "SomeText", Value = defaultValue } }).Result; var block = interfaceModel.Interface.Blocks.First(x => x.PropertyName == propName); Assert.AreEqual(UserInterfaceType.MultipleDropDownList, block.InterfaceType); Assert.AreEqual(1, block.DropDownData.SelectList.Count); }
public void OrdinaryBoolTest() { var builder = new GenericUserInterfaceModelBuilder <Type2>(TestsHelper.CreateDefaultBag()); var result = builder.Result.Interface; Assert.AreEqual(1, result.Blocks.Count); var block = result.Blocks.First(); Assert.AreEqual(UserInterfaceType.DropDownList, block.InterfaceType); var selectList = block.DropDownData.SelectList; //Так как жто не Nullable null быть не должно Assert.IsFalse(selectList.Any(x => x.Value == null)); Assert.IsTrue(selectList.Count == 2); var firstSelectItem = selectList.First(); Assert.IsTrue(firstSelectItem.Selected); Assert.IsFalse(bool.Parse(firstSelectItem.Value)); }
public void Test() { var descr = new GenericUserInterfaceModelBuilder <ModelWithLabel>(TestsHelper.CreateDefaultBag()).Result; Assert.AreEqual(SomeValue, descr.Interface.Blocks.First().LabelText); }
public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <SomeType> overrider) { overrider.GetBlockBuilder(x => x.Prop2).SetTextArea(); return(Task.CompletedTask); }
public override Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <TestClass> overrider) { overrider.GetBlockBuilderForCollection(x => x.Descriptions) .SetMultipleDropDownList(new List <SelectListItemData <string> > { new SelectListItemData <string> { Selected = true, Text = "Описание 1", Value = "Value 1" }, new SelectListItemData <string> { Selected = false, Text = "Описание 2", Value = "Value 2" }, new SelectListItemData <string> { Selected = true, Text = "Описание 3", Value = "Value 3" }, new SelectListItemData <string> { Selected = false, Text = "Описание 4", Value = "Value 4" }, new SelectListItemData <string> { Selected = false, Text = "Описание 5", Value = "Value 5" } }); overrider.GetBlockBuilder(x => x.Name).SetDropDownList(new List <SelectListItemData <string> > { new SelectListItemData <string> { Value = "someValue1", Selected = true, Text = "someText1", }, new SelectListItemData <string> { Value = "someValue2", Selected = false, Text = "someText2" } }); overrider.GetBlockBuilder(x => x.SomeTextArea).SetTextArea(); overrider .GetBlockBuilderForCollection(x => x.AutoCompleteProp1) .SetAutoCompleteFor <TestDataProvider>(); overrider.GetBlockBuilder(x => x.AutoCompleteProp2) .SetAutoCompleteFor <TestDataProvider>(); return(Task.CompletedTask); }
/// <summary> /// /// </summary> /// <param name="bag"></param> /// <param name="overrider"></param> /// <returns></returns> public abstract Task OverrideInterfaceAsync(GenericUserInterfaceBag bag, GenericUserInterfaceModelBuilder <T> overrider);