private static void VerifyTargets(XBuild expectedBuild, Build actualBuild)
        {
            var expectedTargets = expectedBuild.Targets.Target;
            var expectedTargetNames = expectedBuild.Targets.Target.Select(t => t.Name);
            
            var actualTargets = actualBuild.Targets;
            actualTargets.Should().NotBeNull();
            actualTargets.Should().NotBeEmpty().And.HaveCount(expectedTargets.Count);
            actualTargets.Should().OnlyContain(aTarget => aTarget.Name.IsIn(expectedTargetNames) &&
                                                          aTarget.Build.IsNotNull() &&
                                                          aTarget.Metrics.IsNotNullOrEmpty());

            VerifyModules(expectedTargets, actualTargets);
        }
        public async Task Import(XBuild metricsXmlData, string buildName)
        {
            var build = new Build
            {
                Name = buildName, 
                Targets = new List<Target>()
            };

            CreateTargets(build, metricsXmlData.Targets.Target);

            UpdateBuildMetrics(build);

            _metricsStore.Builds.Add(build);

            await _metricsStore.SaveChangesAsync();
        }
        private static void CreateTargets(Build build, IEnumerable<XTarget> targets)
        {
            foreach (var target in targets)
            {
                var buildTarget = new Target
                {
                    Name = target.Name,
                    Build = build,
                    Modules = new List<Module>()
                };

                CreateModules(buildTarget, target.Modules.Module);

                UpdateTargetMetrics(buildTarget);

                build.Targets.Add(buildTarget);
            }
        }
        private static void UpdateBuildMetrics(Build build)
        {
            var buildMetrics = 
                build.Targets
                     .SelectMany(t => t.Metrics)
                     .GroupBy(m => m.Name)
                     .Select(m => new Metric
                     {
                         Name = m.Key,
                         Value = m.Average(v => v.Value)
                     });

            build.Metrics = buildMetrics.ToList();
        }