Exemple #1
0
        public void TryValidateModel_TestAgainstModelSuccess()
        {
            TestWidget      model            = new TestWidget();
            Type            modelType        = model.GetType();
            WFModelMetaData metadata         = new WFModelMetaData();
            WFModelMetaData metadataExpected = new WFModelMetaData();
            bool            actual;

            model.Email          = "*****@*****.**";
            model.MaxLengthName  = "goodname";
            model.RequiredName   = "reqname"; //Required
            model.Sprockets      = 6;         //Good sprocket count
            model.Price          = 0.99d;     //Good price
            model.NoErrorMessage = "reqmsg";  //Required - no error message defined

            actual = WFUtilities.TryValidateModel(model, "", new WFObjectValueProvider(model, ""), metadata, new WFTypeRuleProvider(modelType));

            //No Errors
            Assert.AreEqual(metadata.Errors.Count, 0);

            //Properties are not collected when an error does not exist
            //The reason is because there is no page to collect them for
            Assert.AreEqual(metadata.Properties.Count, 0);

            Assert.AreEqual(actual, true);
        }
Exemple #2
0
        public void TryValidateModel_TestAJAXLikeValidation()
        {
            TestWidget                  model            = new TestWidget();
            Type                        modelType        = model.GetType();
            List <string>               errors           = null;
            WFModelMetaData             metadata         = new WFModelMetaData();
            WFModelMetaData             metadataExpected = new WFModelMetaData();
            bool                        actual;
            Dictionary <string, string> values = new Dictionary <string, string>();

            values.Add("model_RequiredName", "reqname");
            values.Add("model_MaxLengthName", "toolongofaname");
            values.Add("model_Sprockets", "4");    //bad sprocket value
            values.Add("model_Email", "bademail"); //bad email
            values.Add("model_Price", "999");      //bad price
            // NoErrorMessage property is NOT added and should NOT be present

            actual = WFUtilities.TryValidateModel(model, "model_", new WFDictionaryValueProvider(values), metadata, new WFTypeRuleProvider(modelType));
            errors = metadata.Errors;
            Assert.AreEqual(errors.Count, 4);

            Assert.AreEqual(errors[0], "Max length 10 characters");
            Assert.AreEqual(errors[1], "Invalid number of sprockets.");
            Assert.AreEqual(errors[2], "Widget must have valid e-mail");
            //Generated error message on custom annotation
            Assert.AreEqual(errors[3], "Invalid price");

            Assert.AreEqual(actual, false);
        }
Exemple #3
0
        public void GridInGrid_RespectsMargins()
        {
            var size = new Vector2(10, 20);

            var target = new TestWidget()
            {
            };
            var child = new TestWidget()
            {
                Size = new Vector2(2, 2)
            };

            target.AddChild(child);
            target.Prepare(null);

            // ####################### Left/Top
            target.UpdateFormatting(size);
            Assert.AreEqual(0, child.Offset.X);
            Assert.AreEqual(0, child.Offset.Y);

            // Setting left/top margins should change the offset as expected
            child.Margin = new VarmintWidget.WidgetMargin()
            {
                Left = 1, Top = 2
            };
            target.UpdateFormatting(size);
            Assert.AreEqual(1, child.Offset.X);
            Assert.AreEqual(2, child.Offset.Y);
        }
        public void DisposeDeregistersPropertyChangedEventFromSource()
        {
            var source = new TestWidget();
            var obj    = new BindINotifyPropertyChanged(source, nameof(source.TestBool));

            obj.Dispose();

            Assert.IsTrue(source.PropertyChangedEventRemoved);
        }
Exemple #5
0
        public void StretchParamter_WorksWithGridlikeItems()
        {
            var container = new TestWidget()
            {
                Size = new Vector2(10, 20)
            };
            var grid = new VarmintWidgetGrid()
            {
                Size = new Vector2(1, 1)
            };

            container.AddChild(grid);

            // starting out with no stretch
            container.Prepare(null);
            Assert.AreEqual(new Vector2(1, 1), grid.Size);

            // Horizontal only
            grid.Stretch = new VarmintWidget.StretchParameter("1");
            container.UpdateChildFormatting();
            Assert.AreEqual(new Vector2(10, 1), grid.Size);
            Assert.AreEqual(new Vector2(0, 0), grid.Offset);

            // Vertical only
            grid.Stretch = new VarmintWidget.StretchParameter(",1");
            container.UpdateChildFormatting();
            Assert.AreEqual(new Vector2(1, 20), grid.Size);
            Assert.AreEqual(new Vector2(0, 0), grid.Offset);

            // With Margins
            grid.Margin  = new VarmintWidget.WidgetMargin("2,2");
            grid.Stretch = new VarmintWidget.StretchParameter();
            container.UpdateChildFormatting();
            Assert.AreEqual(new Vector2(1, 1), grid.Size);
            Assert.AreEqual(new Vector2(2, 2), grid.Offset);
            grid.Stretch = new VarmintWidget.StretchParameter("1,1");;
            container.UpdateChildFormatting();
            Assert.AreEqual(new Vector2(8, 18), grid.Size);
            Assert.AreEqual(new Vector2(2, 2), grid.Offset);

            // Two children, both should stretch to the same dimensions
            var grid2 = new VarmintWidgetGrid()
            {
                Size = new Vector2(2, 2)
            };

            grid2.Stretch = new VarmintWidget.StretchParameter("1,1");;
            container.AddChild(grid2);
            container.UpdateChildFormatting();
            Assert.AreEqual(new Vector2(8, 18), grid.Size);
            Assert.AreEqual(new Vector2(2, 2), grid.Offset);
            Assert.AreEqual(new Vector2(10, 20), grid2.Size);
            Assert.AreEqual(new Vector2(0, 0), grid2.Offset);
        }
        public void DisposeDeregistersPropertyChangedEventFromTarget()
        {
            var source = new TestWidget();
            var target = new TestViewModel();
            var obj    = new BindINotifyPropertyChanged(source, nameof(source.TestBool));

            obj.Bind(target, nameof(target.TestBool));

            obj.Dispose();

            Assert.IsTrue(target.PropertyChangedEventRemoved);
        }
Exemple #7
0
        public void ForeGroundColorPropertyWorks()
        {
            var target = new TestWidget();

            // Default color is black
            Assert.AreEqual(Color.Black, target.ForegroundColor);

            // If not specified, color is inherited
            var parent = new TestWidget();

            parent.ForegroundColor = Color.Green;
            parent.AddChild(target);
            Assert.AreEqual(Color.Green, parent.ForegroundColor);
            Assert.AreEqual(Color.Green, target.ForegroundColor);
            target.ForegroundColor = Color.Yellow;
            Assert.AreEqual(Color.Green, parent.ForegroundColor);
            Assert.AreEqual(Color.Yellow, target.ForegroundColor);
        }
        public void TestSubscriptionEventSerializationCycle()
        {
            // fake an event from graphql aspnet
            // that would be recieved by the publisher
            var widget = new TestWidget()
            {
                Id          = 5,
                Name        = "Widget5Name",
                Description = "Widget5Description"
            };

            var evt = new SubscriptionEvent()
            {
                Id             = Guid.NewGuid().ToString(),
                EventName      = "testEvent",
                DataTypeName   = typeof(TestWidget).AssemblyQualifiedName,
                Data           = widget,
                SchemaTypeName = typeof(GraphSchema).AssemblyQualifiedName,
            };

            var options = new JsonSerializerOptions();

            options.PropertyNameCaseInsensitive = true;
            options.WriteIndented = true;
            options.Converters.Add(new SubscriptionEventConverter());

            // serialize then deserialize the object
            var serailizedData = JsonSerializer.Serialize(evt, typeof(SubscriptionEvent), options);
            var deserialized   = JsonSerializer.Deserialize <SubscriptionEvent>(serailizedData, options);

            // test all properties were translated correctly
            Assert.IsNotNull(deserialized);
            Assert.AreEqual(evt.Id, deserialized.Id);
            Assert.AreEqual(evt.EventName, deserialized.EventName);
            Assert.AreEqual(evt.SchemaTypeName, deserialized.SchemaTypeName);
            Assert.AreEqual(evt.DataTypeName, deserialized.DataTypeName);

            var converted = deserialized.Data as TestWidget;

            Assert.IsNotNull(converted);
            Assert.AreEqual(converted.Id, widget.Id);
            Assert.AreEqual(converted.Name, widget.Name);
            Assert.AreEqual(converted.Description, widget.Description);
        }
Exemple #9
0
        public void TryValidateModel_TestAgainstModel()
        {
            TestWidget      model            = new TestWidget();
            Type            modelType        = model.GetType();
            List <string>   errors           = null;
            List <string>   errorsExpected   = new List <string>();
            WFModelMetaData metadata         = new WFModelMetaData();
            WFModelMetaData metadataExpected = new WFModelMetaData();
            bool            expected         = false;
            bool            actual;

            model.Email          = "bademail";
            model.MaxLengthName  = "toolongofaname";
            model.RequiredName   = "";  //Required
            model.Sprockets      = 4;   //Invalid sprocket count
            model.Price          = 999; //Invalid price
            model.NoErrorMessage = "";  //Required - no error message defined

            actual = WFUtilities.TryValidateModel(model, "", new WFObjectValueProvider(model, ""), metadata, new WFTypeRuleProvider(modelType));
            errors = metadata.Errors;

            Assert.AreEqual(errors.Count, 6);
            //Generated error messages on standard annotations
            Assert.AreEqual(errors[0], "Widget name required");
            Assert.AreEqual(errors[1], "Max length 10 characters");
            Assert.AreEqual(errors[2], "Invalid number of sprockets.");
            Assert.AreEqual(errors[3], "Widget must have valid e-mail");
            //Generated error message on custom annotation
            Assert.AreEqual(errors[4], "Invalid price");
            //Auto-generated error message
            Assert.AreEqual(errors[5], "The NoErrorMessage field is required.");

            Assert.AreEqual(metadata.Properties.Count, 6);
            Assert.AreEqual(metadata.Properties[0].PropertyName, "RequiredName");
            Assert.AreEqual(metadata.Properties[1].PropertyName, "MaxLengthName");
            Assert.AreEqual(metadata.Properties[2].PropertyName, "Sprockets");
            Assert.AreEqual(metadata.Properties[3].PropertyName, "Email");
            Assert.AreEqual(metadata.Properties[4].PropertyName, "Price");
            Assert.AreEqual(metadata.Properties[5].PropertyName, "NoErrorMessage");

            Assert.AreEqual(actual, false);
        }
 private void Awake()
 {
     _controller = new ImGuiController();
     widget      = new TestWidget();
 }
Exemple #11
0
        public void GridInGrid_RespectsMargins()
        {
            var target = new TestWidget()
            {
                Size = new Vector2(10, 20)
            };
            var child = new TestWidget()
            {
                Size = new Vector2(2, 2)
            };

            target.HorizontalContentAlignment = HorizontalContentAlignment.Left;
            target.VerticalContentAlignment   = VerticalContentAlignment.Top;
            target.AddChild(child);
            target.Prepare(null);

            // ####################### Left/Top
            target.UpdateChildFormatting();
            Assert.AreEqual(0, child.Offset.X);
            Assert.AreEqual(0, child.Offset.Y);

            // Setting left/top margins should change the offset as expected
            child.Margin = new VarmintWidget.WidgetMargin()
            {
                Left = 1, Top = 2
            };
            target.UpdateChildFormatting();
            Assert.AreEqual(1, child.Offset.X);
            Assert.AreEqual(2, child.Offset.Y);

            // Setting right/bottom should pin the child to the right/bottom
            child.Margin = new VarmintWidget.WidgetMargin()
            {
                Right = 1, Bottom = 2
            };
            target.UpdateChildFormatting();
            Assert.AreEqual(7, child.Offset.X);
            Assert.AreEqual(16, child.Offset.Y);

            // ####################### Center
            target.HorizontalContentAlignment = HorizontalContentAlignment.Center;
            target.VerticalContentAlignment   = VerticalContentAlignment.Center;
            child.Margin = new VarmintWidget.WidgetMargin();
            target.UpdateChildFormatting();
            Assert.AreEqual(4, child.Offset.X);
            Assert.AreEqual(9, child.Offset.Y);

            // Left/Top margin should pad the child
            child.Margin = new VarmintWidget.WidgetMargin()
            {
                Left = 2, Top = 4
            };
            target.UpdateChildFormatting();
            Assert.AreEqual(5, child.Offset.X);
            Assert.AreEqual(11, child.Offset.Y);

            // Right/Bottom margin should pad the child
            child.Margin = new VarmintWidget.WidgetMargin()
            {
                Left = 2, Top = 4, Right = 4, Bottom = 6
            };
            target.UpdateChildFormatting();
            Assert.AreEqual(3, child.Offset.X);
            Assert.AreEqual(8, child.Offset.Y);

            // ####################### Right/Bottom
            target.HorizontalContentAlignment = HorizontalContentAlignment.Right;
            target.VerticalContentAlignment   = VerticalContentAlignment.Bottom;
            child.Margin = new VarmintWidget.WidgetMargin();
            target.UpdateChildFormatting();
            Assert.AreEqual(8, child.Offset.X);
            Assert.AreEqual(18, child.Offset.Y);
        }