Ejemplo n.º 1
0
        public void TestBuildInput_NoIdentifier_Compression()
        {
            ICompressor compressor = new GZipCompressor();
            Image       img        = _createTestImage();
            JobInput    i          = new JobInput(img);

            i.Compressor = compressor;
            JobBuilderProcess p       = new JobBuilderProcess();
            XElement          element = p.BuildInput(i);

            Assert.AreEqual("input", element.Name);
            Assert.IsNull(element.Attribute("identifier"));

            Assert.IsNotNull(element.Attribute("compressor"));
            Assert.AreEqual("gzip", element.Attribute("compressor").Value.ToLower());

            XNode child = element.FirstNode;

            Assert.IsTrue(child.NodeType == System.Xml.XmlNodeType.CDATA);

            XCData data          = (XCData)child;
            string providedImage = data.Value;
            string expectedImage = System.Text.Encoding.Default.GetString(CompressionAssistant.Compress(img, compressor));

            Assert.AreEqual(expectedImage, providedImage);
        }
Ejemplo n.º 2
0
        public void TestBuildInput_Identifier_NoCompression()
        {
            object   identifier = "Test";
            Image    img        = _createTestImage();
            JobInput i          = new JobInput(img);

            i.Identifier = identifier;
            JobBuilderProcess p       = new JobBuilderProcess();
            XElement          element = p.BuildInput(i);

            Assert.AreEqual("input", element.Name);

            Assert.IsNotNull(element.Attribute("identifier"));
            Assert.AreEqual(identifier, element.Attribute("identifier").Value);

            XNode child = element.FirstNode;

            Assert.IsTrue(child.NodeType == System.Xml.XmlNodeType.CDATA);

            XCData data          = (XCData)child;
            string providedImage = data.Value;
            string expectedImage = System.Text.Encoding.Default.GetString(CompressionAssistant.ImageToBytes(img));

            Assert.AreEqual(expectedImage, providedImage);
        }
Ejemplo n.º 3
0
        public void TestBuild_NullDefinition()
        {
            JobBuilderProcess builder = new JobBuilderProcess();
            XElement          xml     = builder.Build(null);

            Assert.IsNotNull(xml);
            Assert.AreEqual("algorithm", xml.Name);
        }
Ejemplo n.º 4
0
        public void TestBuild_NoProperties()
        {
            string              algorithmName = "Test";
            JobBuilderProcess   builder       = new JobBuilderProcess();
            AlgorithmDefinition d             = new AlgorithmDefinition(algorithmName, null);
            XElement            xml           = builder.Build(d);

            Assert.AreEqual("algorithm", xml.Name);
            Assert.IsNotNull(xml.Attribute("name"));
            Assert.AreEqual(algorithmName, xml.Attribute("name").Value);
            Assert.IsFalse(xml.Descendants("properties").Any());
        }
Ejemplo n.º 5
0
        public void TestBuild_OneAlgorithm_NoInputs()
        {
            IBuilderProcess     builder = new JobBuilderProcess();
            XmlBuilder          b       = new XmlBuilder(builder);
            AlgorithmDefinition d       = new AlgorithmDefinition("test",
                                                                  new[] { new Property("TestProperty", typeof(double))
                                                                          {
                                                                              Value = 1d
                                                                          } });

            b.Algorithms.Add(d);
            b.Build();
            var algorithms = b.Xml.Descendants("algorithm");

            Assert.AreEqual(1, algorithms.Count());
            Assert.AreEqual(1, algorithms.Descendants("property").Count());
        }
Ejemplo n.º 6
0
        public void TestBuild_OneProperty()
        {
            string            algorithmName = "Test";
            JobBuilderProcess builder       = new JobBuilderProcess();
            Property          p             = new Property("Value", typeof(double));

            p.Value = 1d;
            AlgorithmDefinition d   = new AlgorithmDefinition(algorithmName, new [] { p });
            XElement            xml = builder.Build(d);

            Debug.WriteLine(xml);

            Assert.AreEqual("algorithm", xml.Name);
            Assert.IsNotNull(xml.Attribute("name"));
            Assert.AreEqual(algorithmName, xml.Attribute("name").Value);
            Assert.IsTrue(xml.Descendants("properties").Any());

            XElement props = xml.Descendants("properties").First();

            Assert.AreEqual(1, props.Descendants("property").Count());

            XElement prop = xml.Descendants("property").First();

            Assert.AreEqual("property", prop.Name);

            XAttribute name = prop.Attribute("name");

            Assert.IsNotNull(name);
            Assert.AreEqual("Value", name.Value);

            XAttribute type = prop.Attribute("type");

            Assert.IsNotNull(type);
            Assert.AreEqual(typeof(double), Type.GetType(type.Value));

            XElement value = prop.Descendants("value").FirstOrDefault();

            Assert.IsNotNull(value);
            Assert.AreEqual("1", value.Value);
        }