private InputSpecification GetInputSpecification_CheesePrice()
 {
     try
     {
         InputSpecification priceInputSpecification = new InputSpecification();
         priceInputSpecification.Add("Cheddar_Price",
                                     new Number(label: "Cheddar price index", order: 0, min: 0.0, max: 15.0));
         priceInputSpecification.Add("Gamle_Ole_Price",
                                     new Number(label: "Gamle Ole price index", order: 1, min: 0.0, max: 15.0));
         priceInputSpecification.Add("Vasterbotten_Price",
                                     new Number(label: "Vasterbotten price index", order: 2, min: 0.0, max: 15.0));
         priceInputSpecification.Add("Edamer_Price",
                                     new Number(label: "Edamer price index", order: 3, min: 0.0, max: 15.0));
         priceInputSpecification.Add("Maasdamer_Price",
                                     new Number(label: "Maasmer price index", order: 4, min: 0.0, max: 15.0));
         priceInputSpecification.Add("Gouda_Price",
                                     new Number(label: "Gouda price index", order: 5, min: 0.0, max: 15.0));
         return(priceInputSpecification);
     }
     catch (Exception ex)
     {
         var exNew = new ErrorMessageEventArg()
         {
             Exception      = ex,
             SourceFunction = "GetInputSpecification_CheesePrice",
             Message        = "Could not create input specification for cheese price!"
         };
         CExcelModule_ErrorRaised(this, exNew);
         return(new InputSpecification());
     }
 }
Exemple #2
0
        static public void Test()
        {
            try
            {
                //Input Spec
                InputSpecification iSpec = new InputSpecification();
                iSpec.Add("age", new Number(label: "Age", min: 0, unit: "years"));
                List aList = new List("Cheese Types");
                aList.Add("alp", new Text("Alp cheese"));
                aList.Add("brie", new Text("Brie cheese"));
                iSpec.Add("cheese-types", aList);
                SelectModuleResponse mResponse = new SelectModuleResponse(moduleId: "foo-bar_cheese-Module-v1-0",
                                                                          variantId: "503f191e8fcc19729de860ea", caseId: "5d9300d0-1574-4ae5-9d19-4e896b959f1c",
                                                                          kpiId: "cheese-taste-kpi", inputSpecification: iSpec);
                string json = Serialize.ToJsonString(mResponse);

                //Request from dashboard
                string jsonmessage = File.ReadAllText(@"../../../EcodistrictMessagingTests/TestData/Json/ModuleRequest/StartModuleRequest2.txt");
                object obj         = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonmessage);
                jsonmessage = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                Type     expected = typeof(StartModuleRequest);
                IMessage message  = Deserialize <IMessage> .JsonString(jsonmessage);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #3
0
        public void SelectModuleResponseTest()
        {
            try
            {
                // arrange
                InputSpecification iSpec = new InputSpecification();

                iSpec.Add("age", new Number(label: "Age", min: 0, unit: "years"));

                Options opt = new Options();
                opt.Add(new Option(value: "alp-cheese", label: "Alpk\u00e4se"));
                opt.Add(new Option(value: "edam-cheese", label: "Edammer"));
                Option brie = new Option(value: "brie-cheese", label: "Brie");
                opt.Add(brie);
                iSpec.Add("cheese-type", new Select(label: "Cheese type", options: opt, value: brie));

                SelectModuleResponse mResponse = new SelectModuleResponse(moduleId: "foo-bar_cheese-Module-v1-0",
                                                                          variantId: "503f191e8fcc19729de860ea", caseId: "5d9300d0-1574-4ae5-9d19-4e896b959f1c", kpiId: "cheese-taste-kpi", inputSpecification: iSpec);
                var      message = File.ReadAllText(@"../../TestData/Json/ModuleResponse/SelectModuleResponse.txt");
                IMessage obj     = Deserialize <IMessage> .JsonString(message);

                string expected = Serialize.ToJsonString(obj);

                // act
                string actual = Serialize.ToJsonString(mResponse);

                // assert
                Assert.AreEqual(expected, actual, false, "\nNot Json-serialized correctly:\n\n" + expected + "\n\n" + actual); //TODO is unordered => makes comparisson hard.
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void AtomicSelect()
        {
            try
            {
                // arrange
                InputSpecification inputSpec = new InputSpecification();
                Options            opt       = new Options();
                opt.Add(new Option(value: "alp-cheese", label: "Alpku00e4se"));
                opt.Add(new Option(value: "edam-cheese", label: "Edammer"));
                Option brie = new Option(value: "brie-cheese", label: "Brie");
                opt.Add(brie);
                inputSpec.Add("cheese-type", new Select(label: "Cheese type", options: opt, value: brie));  //TODO value = brie-cheese makes room for error in dashboard, shuld be connected to the options.
                string expected = "{" +
                                  "\"cheese-type\":{" +
                                  "\"options\":[" +
                                  "{\"label\":\"Alpku00e4se\",\"value\":\"alp-cheese\"}" + "," +
                                  "{\"label\":\"Edammer\",\"value\":\"edam-cheese\"}" + "," +
                                  "{\"label\":\"Brie\",\"value\":\"brie-cheese\"}" +
                                  "]" + "," +
                                  "\"value\":\"brie-cheese\",\"label\":\"Cheese type\",\"type\":\"select\"" +
                                  "}" +
                                  "}";

                // act
                string actual = Serialize.ToJsonString(inputSpec);

                // assert
                Assert.AreEqual(expected, actual, false, "\nSelect not Json-seralized correctly:\n\n" + expected + "\n\n" + actual);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemple #5
0
        public void StartModuleResponseReconstructionTest()
        {
            try
            {
                // arrange
                InputSpecification inputSpec = new InputSpecification();
                List aList = new List(label: "aList");
                aList.Add(key: "o1", item: new Number(label: "o1 label", value: 1));
                aList.Add(key: "o2", item: new Number(label: "o2 label", value: 2));
                aList.Add(key: "o3", item: new Number(label: "o3 label", value: 3));
                inputSpec.Add("list", aList);
                SelectModuleResponse mResponse = new SelectModuleResponse("", "", "", "", inputSpec);
                string expected = Serialize.ToJsonString(mResponse);

                // act
                SelectModuleResponse mResponseR = Deserialize <SelectModuleResponse> .JsonString(expected);

                string actual = Serialize.ToJsonString(mResponseR);

                // assert
                Assert.AreEqual(expected, actual, false, "\nSelectModuleResponse not Json-seralized correctly:\n\n" + expected + "\n\n" + actual);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public FormDataValidationResult Validate()
        {
            var result = new FormDataValidationResult();


            if (Title.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Title is required");
            }
            if (Description.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Description is required");
            }
            if (Constraints.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Constraints is required");
            }
            if (InputSpecification.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("InputSpecification is required");
            }
            if (OutputSpecification.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("OutputSpecification is required");
            }
            if (SampleInput.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("SampleInput is required");
            }
            if (SampleOutput.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("SampleOutput is required");
            }
            if (Notes.IsNullOrWhiteSpace())
            {
                result.AddErrorMessage("Notes is required");
            }
            if (TimeLimit == 0 || TimeLimit > 20)
            {
                result.AddErrorMessage("TimeLimit is invalid");
            }
            if (MemoryLimit == 0 || MemoryLimit > 512)
            {
                result.AddErrorMessage("MemoryLimit is invalid");
            }
            if (string.IsNullOrEmpty(TestCaseInput))
            {
                result.AddErrorMessage("TestCaseInput is required");
            }
            if (string.IsNullOrEmpty(TestCaseOutput))
            {
                result.AddErrorMessage("TestCaseOutput is required");
            }

            return(result);
        }
        /// <summary>
        /// Convert the <see cref="InputSpecification"/> to a json formated string.
        /// </summary>
        /// <remarks>
        /// Used in testing purposes, the <see cref="InputSpecification"/> is newer sent to the dashboard on its own.
        /// Its always sent as a part of <see cref="SelectModuleResponse"/>.
        /// </remarks>
        /// <param name="obj">The message object.</param>
        /// <param name="indented">If the string should be indented (visual only, does not affect the dashboard interpretation of the message).</param>
        /// <returns>Json string</returns>
        public static string ToJsonString(InputSpecification obj, bool indented = false)
        {
            if (indented)
            {
                settings.Formatting = Newtonsoft.Json.Formatting.Indented;
            }
            else
            {
                settings.Formatting = Newtonsoft.Json.Formatting.None;
            }

            return(Newtonsoft.Json.JsonConvert.SerializeObject(obj, obj.GetType(), settings));
        }
Exemple #8
0
        static void Main(string[] args)
        {
            try
            {
                GetModulesRequestExemple();
                SelectModuleRequestExemple();
                StartModuleRequestExemple();
                GetModulesResponseExemple();
                SelectModuleResponseExemple();
                StartModuleResponseExemple();


                InputSpecification iSpec = new InputSpecification();

                iSpec.Add("age", new Number(label: "Age", min: 0, unit: "years"));

                Options opt = new Options();
                opt.Add(new Option(value: "alp-cheese", label: "Alpk\u00e4se"));
                opt.Add(new Option(value: "edam-cheese", label: "Edammer"));
                Option brie = new Option(value: "brie-cheese", label: "Brie");
                opt.Add(brie);
                iSpec.Add("cheese-type", new Select(label: "Cheese type", options: opt, value: brie));

                SelectModuleResponse mResponse = new SelectModuleResponse(moduleId: "foo-bar_cheese-Module-v1-0",
                                                                          variantId: "503f191e8fcc19729de860ea", caseId: "5d9300d0-1574-4ae5-9d19-4e896b959f1c",
                                                                          kpiId: "cheese-taste-kpi", inputSpecification: iSpec);
                var      message = File.ReadAllText(@"../../../EcodistrictMessagingTests/TestData/Json/ModuleResponse/SelectModuleResponse.txt");
                IMessage obj     = Deserialize <SelectModuleResponse> .JsonString(message);

                string expected = Serialize.ToJsonString(obj);

                // act
                string actual = Serialize.ToJsonString(mResponse);

                //StartModuleResponseReconstructionTest();

                // arrange
                //string jsonmessage = File.ReadAllText(@"../../../EcodistrictMessagingTests/TestData/Json/ModuleRequest/StartModuleRequest3.txt");

                //// act
                //IMessage message = Deserialize.JsonString(jsonmessage);
                //Type actual = message.GetType();


                StartModuleRequestComplex();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #9
0
        static void StartModuleResponseReconstructionTest()
        {
            // arrange
            InputSpecification inputSpec = new InputSpecification();
            List aList = new List(label: "aList");

            aList.Add(key: "o1", item: new Number(label: "o1 label", value: 1));
            aList.Add(key: "o2", item: new Number(label: "o2 label", value: 2));
            aList.Add(key: "o3", item: new Number(label: "o3 label", value: 3));
            inputSpec.Add("list", aList);
            SelectModuleResponse mResponse = new SelectModuleResponse("", "", "", "", inputSpec);
            string expected = Serialize.ToJsonString(mResponse);

            // act
            SelectModuleResponse mResponseR = Deserialize <SelectModuleResponse> .JsonString(expected);

            string actual = Serialize.ToJsonString(mResponseR);
        }
Exemple #10
0
        static void InputSpecificationTest()
        {
            try
            {
                InputSpecification inputSpec = new InputSpecification();
                inputSpec.Add("name", new Text(label: "Parent name"));
                inputSpec.Add("age", new Number(label: "Parent age"));
                List aList = new List("Children");
                aList.Add("name", new Text(label: "Child name"));
                aList.Add("age", new Number(label: "Child age"));
                inputSpec.Add("child", aList);

                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.Formatting = Newtonsoft.Json.Formatting.Indented;
                Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(inputSpec, typeof(InputSpecification), settings));
                Console.WriteLine("");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void AtomicText()
        {
            try
            {
                // arrange
                InputSpecification inputSpec = new InputSpecification();
                inputSpec.Add("text", new Text(label: "A Label"));
                string expected = "{" +
                                  "\"text\":{\"label\":\"A Label\",\"type\":\"text\"}" +
                                  "}";

                // act
                string actual = Serialize.ToJsonString(inputSpec);

                // assert
                Assert.AreEqual(expected, actual, false, "\nText not Json-seralized correctly:\n\n" + expected + "\n\n" + actual);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemple #12
0
        static void InputSpecificationExample()
        {
            //Create a input specification demanding 2 values from the user of the dashboard.
            InputSpecification iSpec = new InputSpecification();

            //A user specified age
            Number numberAge = new Number(
                label: "Age",
                min: 0,
                unit: "years");

            Options opt = new Options();

            opt.Add(new Option(value: "alp-cheese", label: "Alpk\u00e4se")); //Note the web-friendly string
            opt.Add(new Option(value: "edam-cheese", label: "Edammer"));
            Option brie = new Option(value: "brie-cheese", label: "Brie");

            opt.Add(brie);

            //And one of the above options of cheese-types.
            //(The preselected value, "brie-cheese", is optional)
            Select selectCheseType = new Select(
                label: "Cheese type",
                options: opt,
                value: brie);

            //Add these components to the input specification.
            //(Note the choosed keys, its the keys that will be attached to the
            //data when the dashboard returns with the user specified data in
            //a StartModuleRequest.)
            iSpec.Add(
                key: "age",
                value: numberAge);

            iSpec.Add(
                key: "cheese-type",
                value: selectCheseType);
        }
        public void AtomicNumber()
        {
            try
            {
                // arrange
                InputSpecification inputSpec = new InputSpecification();
                inputSpec.Add("number", new Number(label: "A label"));
                var    message  = File.ReadAllText(@"../../TestData/Json/InputSpecification/AtomicNumber.txt");
                object obj      = JsonConvert.DeserializeObject(message);
                string expected = JsonConvert.SerializeObject(obj);

                // act
                string actual = Serialize.ToJsonString(inputSpec);
                //string actual = Newtonsoft.Json.JsonConvert.SerializeObject(inputSpec);

                // assert
                Assert.AreEqual(expected, actual, false, "\nNumber not Json-seralized correctly:\n\n" + expected + "\n\n" + actual);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void ISpecToJSON_E1()
        {
            try
            {
                // arrange
                InputSpecification inputSpec = new InputSpecification();
                inputSpec.Add("name", new Text(label: "Name"));
                inputSpec.Add("shoe-size", new Number(label: "Shoe size"));
                string expected = "{" +
                                  "\"name\":{\"label\":\"Name\",\"type\":\"text\"}" + "," +
                                  "\"shoe-size\":{\"label\":\"Shoe size\",\"type\":\"number\"}" +
                                  "}";
                // act
                string actual = Serialize.ToJsonString(inputSpec);

                // assert
                Assert.AreEqual(expected, actual, false, "\nInputSpecification not Json-seralized correctly:\n\n" + expected + "\n\n" + actual);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Exemple #15
0
        static void SelectModuleResponseExemple()
        {
            //This module's id
            string moduleId = "foo-bar_cheese-Module-v1-0";

            //The dashboard message recieved (as a json-string)
            string message = "{" +
                             "\"type\": \"request\"," +
                             "\"method\": \"selectModule\"," +
                             "\"moduleId\": \"foo-bar_cheese-Module-v1-0\"," +
                             "\"variantId\": \"503f191e8fcc19729de860ea\"," +
                             "\"kpiId\": \"cheese-taste-kpi\"" +
                             "}";
            //Message reconstructed into a .Net object.
            SelectModuleRequest recievedMessage = Deserialize <SelectModuleRequest> .JsonString(message);

            //Is this message meant for me?
            if (recievedMessage.moduleId == moduleId)
            {
                //For the selected kpi, create a input specification describing what data
                //the module need in order to calculate the selected kpi.
                InputSpecification iSpec = new InputSpecification();
                if (recievedMessage.kpiId == "cheese-taste-kpi")
                {
                    //In this case the module needs 2 things.

                    //A user specified age
                    Number numberAge = new Number(
                        label: "Age",
                        min: 0,
                        unit: "years");

                    Options opt = new Options();
                    opt.Add(new Option(value: "alp-cheese", label: "Alpk\u00e4se")); //Note the web-friendly string
                    opt.Add(new Option(value: "edam-cheese", label: "Edammer"));
                    Option brie = new Option(value: "brie-cheese", label: "Brie");
                    opt.Add(brie);

                    //And one of the above options of cheese-types.
                    //(The preselected value, "brie-cheese", is optional)
                    Select selectCheseType = new Select(
                        label: "Cheese type",
                        options: opt,
                        value: brie);

                    //Add these components to the input specification.
                    //(Note the choosed keys, its the keys that will be attached to the
                    //data when the dashboard returns with the user specified data in
                    //a StartModuleRequest.)
                    iSpec.Add(
                        key: "age",
                        value: numberAge);

                    iSpec.Add(
                        key: "cheese-type",
                        value: selectCheseType);
                }
                else
                {
                    //...
                }

                //Create the IMessage response.
                SelectModuleResponse mResponse = new SelectModuleResponse(
                    moduleId: recievedMessage.moduleId,
                    variantId: recievedMessage.variantId,
                    caseId: recievedMessage.caseId,
                    kpiId: recievedMessage.kpiId,
                    inputSpecification: iSpec);

                //json-string that can be interpreted by the dashboard
                //In this case indented in order to be easier to read (won't effect the dashboard).
                string messageResponse = Serialize.ToJsonString(mResponse, true);

                //Write the message to the console
                Console.WriteLine(messageResponse);

                //Output:
                //{
                //  "kpiId": "cheese-taste-kpi",
                //  "variantId": "503f191e8fcc19729de860ea",
                //  "inputSpecification": {
                //    "age": {
                //      "unit": "years",
                //      "min": 0,
                //      "label": "Age",
                //      "type": "number"
                //    },
                //    "cheese-type": {
                //      "options": [
                //        {
                //          "value": "alp-cheese",
                //          "label": "Alpk\u00e4se"
                //        },
                //        {
                //          "value": "edam-cheese",
                //          "label": "Edammer"
                //        },
                //        {
                //          "value": "brie-cheese",
                //          "label": "Brie"
                //        }
                //      ],
                //      "value": "brie-cheese",
                //      "label": "Cheese type",
                //      "type": "select"
                //    }
                //  },
                //  "moduleId": "foo-bar_cheese-Module-v1-0",
                //  "method": "selectModule",
                //  "type": "response"
                //}
            }

            Console.WriteLine("");
        }