ILRepacking.Steps.SourceServerData.HttpSourceServerDescriptor.MergeWith C# (CSharp) Method

MergeWith() public method

public MergeWith ( IEnumerable others ) : HttpSourceServerDescriptor
others IEnumerable
return HttpSourceServerDescriptor
        public HttpSourceServerDescriptor MergeWith(IEnumerable<HttpSourceServerDescriptor> others)
        {
            var files = new[] { this }
                    .Concat(others.Where(descriptor => descriptor.VersionControl == VersionControl))
                    .SelectMany(descriptor =>
                        descriptor.SourceFiles.Select(file => new { descriptor.Target, file.Variables }))
                    .Select(
                        tuple =>
                        {
                            return new SourceFileDescriptor(
                                tuple.Variables.FirstOrDefault() ?? "",
                                Enumerable.Range(1, tuple.Variables.Length - 1)
                                    .Select(index => new { N = index + 1, Value = tuple.Variables[index] })
                                    .Aggregate(tuple.Target, (var2, var) => var2.Replace(VarName(var.N), var.Value)));
                        });
            return new HttpSourceServerDescriptor(Version, VersionControl, VarName(2), files.ToArray());
        }

Usage Example

 public static void GivenAListOfSourceServerDescriptor_WhenMergingThem_ThenItShouldBeProperlyMerged(
     int expectedVersion,
     string expectedVersionControl,
     string expectedTarget,
     IDictionary<string, string> expectedSourceFiles,
     HttpSourceServerDescriptor primary,
     IEnumerable<HttpSourceServerDescriptor> other)
 {
     var merged = primary.MergeWith(other);
     Assert.That(merged.Version, Is.EqualTo(expectedVersion));
     Assert.That(merged.VersionControl, Is.EqualTo(expectedVersionControl));
     Assert.That(merged.Target, Is.EqualTo(expectedTarget));
     CollectionAssert.AreEquivalent(
         expectedSourceFiles,
         merged.SourceFiles.Select(file => file.Variables)
             .ToDictionary(vars => vars.ElementAt(0), vars => vars.ElementAt(1)));
 }