Example #1
0
        /// <summary>
        /// Gets the build.
        /// </summary>
        /// <param name="buildDescriptor">The build descriptor.</param>
        /// <returns></returns>
        public Build GetBuild(BuildDescriptor buildDescriptor)
        {
            Build build = new NullBuild(buildDescriptor);

            if (buildDescriptor != null)
            {
                var key = build.Number + "-" + build.Url;

                if (Cache.ContainsKey(key))
                {
                    build = Cache[key];

                    System.Diagnostics.Debug.WriteLine("Hit: " + key);
                }
                else
                {
                    build = BuildService.GetBuild(buildDescriptor);

                    if (!build.Building) Cache.Add(key, build);

                    System.Diagnostics.Debug.WriteLine("Miss: " + key);
                }
            }

            return build;
        }
        public void TestGetBuildWhenInvalid()
        {
            xmlService
                .Expect(call => call.GetPage(new Uri("http://www.example.com/api/xml/")))
                .Returns(XmlFactory.LoadInvalidXml());

            var descriptor = new BuildDescriptor { Url = new Uri("http://www.example.com/") };

            var build = service.GetBuild(descriptor);

            Assert.AreEqual(typeof(NullBuild), build.GetType());
        }
Example #3
0
        public void TestGetBuildWhenCacheHit()
        {
            var descriptor = new BuildDescriptor { Number = 10, Url = new Uri("http://www.example.com/") };

            buildService.Verify(call => call.GetBuild(descriptor), Times.Never());

            cache.Cache.Add("10-http://www.example.com/", new Build());

            var build = cache.GetBuild(descriptor);

            Assert.IsNotNull(build);
        }
        public void TestGetBuild()
        {
            xmlService
                .Expect(call => call.GetPage(new Uri("http://www.example.com/api/xml/")))
                .Returns(XmlFactory.Load("BuildResponse.xml"));

            var descriptor = new BuildDescriptor { Url = new Uri("http://www.example.com/") };

            var build = service.GetBuild(descriptor);

            Assert.IsNotNull(build);
        }
Example #5
0
        public void TestGetBuildWhenCacheNotHitDoesntInsertRunningBuilds()
        {
            var descriptor = new BuildDescriptor { Number = 10, Url = new Uri("http://www.example.com/") };

            buildService
                .Setup(call => call.GetBuild(descriptor))
                .Returns(new Build{ Building = true});

            var build = cache.GetBuild(descriptor);

            Assert.IsNotNull(build);
            Assert.IsFalse(cache.Cache.ContainsKey("10-http://www.example.com/"));
        }
        public void TestGetBuildWhenCacheNotHit()
        {
            var descriptor = new BuildDescriptor { Number = 10, Url = new Uri("http://www.example.com/") };

            buildService
                .Expect(call => call.GetBuild(descriptor))
                .Returns(new Build());

            var build = cache.GetBuild(descriptor);

            Assert.IsNotNull(build);
            Assert.IsTrue(cache.Cache.ContainsKey("10-http://www.example.com/"));
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NullBuild"/> class.
        /// </summary>
        /// <param name="buildDescriptor">The build descriptor.</param>
        public NullBuild(BuildDescriptor buildDescriptor)
        {
            if (buildDescriptor != null)
            {
                Number = buildDescriptor.Number;
                Url = buildDescriptor.Url;            
            }
            else
            {
                Url = new Uri("http://null.build/");
            }

            Description = "Unable to load this build";            
        }
        /// <summary>
        /// Maps the specified XML.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <returns></returns>
        public BuildDescriptor Map(XmlNode xml)
        {
            BuildDescriptor descriptor = null;

            if (xml != null)
            {
                descriptor = new BuildDescriptor
                                 {
                                     Number = xml.FindInteger("//number"),
                                     Url = new Uri(xml.Find("//url"))
                                 };
            }

            return descriptor;
        }
        /// <summary>
        /// Maps the specified XML.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <param name="xpath">The xpath.</param>
        /// <returns></returns>
        public BuildDescriptor Map(XmlNode xml, string xpath)
        {
            BuildDescriptor descriptor = null;

            var node = xml.SelectSingleNode(xpath);

            if (node != null)
            {
                descriptor = new BuildDescriptor
                                 {
                                     Number = xml.FindInteger(xpath + "/number"),
                                     Url = new Uri(xml.Find(xpath + "/url"))
                                 };
            }

            return descriptor;
        }
Example #10
0
        /// <summary>
        /// Gets the build.
        /// </summary>
        /// <param name="buildDescriptor">The build descriptor.</param>
        /// <returns></returns>
        public Build GetBuild(BuildDescriptor buildDescriptor)
        {
            Build build = new NullBuild(buildDescriptor);

            var url = new XmlApiPrepender().Prepend(build.Url);

            if (buildDescriptor != null)
            {
                var xml = XmlService.GetPage(url);

                if (xml.IsValid)
                {
                    build = new BuildMapper().Map(xml.Contents);
                }
            }

            return build;
        }