Exemplo n.º 1
0
 internal static IEnumerable <SnapApp> BuildSnapApps([NotNull] this SnapApps snapApps, [NotNull] INuGetPackageSources nuGetPackageSources, [NotNull] ISnapFilesystem snapFilesystem)
 {
     foreach (var snapsApp in snapApps.Apps)
     {
         foreach (var snapsTarget in snapsApp.Targets)
         {
             yield return(snapApps.BuildSnapApp(snapsApp.Id, snapsTarget.Rid, nuGetPackageSources, snapFilesystem));
         }
     }
 }
Exemplo n.º 2
0
        public async Task TestBuildSnapApp_Ignore_Non_Existant_Feeds()
        {
            await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem);

            var testChannel = new SnapChannel
            {
                Name     = "test",
                PushFeed = new SnapNugetFeed {
                    Name = Guid.NewGuid().ToString("N")
                },
                UpdateFeed = new SnapNugetFeed {
                    Name = Guid.NewGuid().ToString("N")
                },
                Current = true
            };

            var snapAppBefore = new SnapApp
            {
                Id           = "demoapp",
                SuperVisorId = Guid.NewGuid().ToString(),
                Version      = new SemanticVersion(1, 0, 0),
                Channels     = new List <SnapChannel>
                {
                    testChannel
                },
                Target = new SnapTarget
                {
                    Os               = OSPlatform.Windows,
                    Framework        = "netcoreapp2.1",
                    Rid              = "win-x64",
                    PersistentAssets = new List <string>
                    {
                        "subdirectory",
                        "myjsonfile.json"
                    }
                }
            };

            var snapApps = new SnapApps(snapAppBefore);

            var snapAppAfter = snapApps.BuildSnapApp(snapAppBefore.Id, snapAppBefore.Target.Rid,
                                                     snapAppBefore.BuildNugetSources(nugetTempDirectory), _fileSystem,
                                                     false, false);

            Assert.NotNull(snapAppAfter);
            Assert.Single(snapAppAfter.Channels.Select(x => x.UpdateFeed is {}));
Exemplo n.º 3
0
        public async Task TestBuildSnapApp_Throws_If_Multiple_Nuget_Push_Feed_Names()
        {
            await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem);

            var nugetOrgFeed = new SnapNugetFeed
            {
                Name            = "nuget.org",
                Source          = new Uri(NuGetConstants.V3FeedUrl),
                ProtocolVersion = NuGetProtocolVersion.V3,
                Username        = "******",
                Password        = "******",
                ApiKey          = "myapikey"
            };

            var nugetOrgFeed2 = new SnapNugetFeed
            {
                Name            = "nuget2.org",
                Source          = new Uri(NuGetConstants.V3FeedUrl),
                ProtocolVersion = NuGetProtocolVersion.V3,
                Username        = "******",
                Password        = "******",
                ApiKey          = "myapikey"
            };

            var testChannel = new SnapChannel
            {
                Name       = "test",
                PushFeed   = nugetOrgFeed,
                UpdateFeed = nugetOrgFeed,
                Current    = true
            };

            var stagingChannel = new SnapChannel
            {
                Name       = "staging",
                PushFeed   = nugetOrgFeed2,
                UpdateFeed = nugetOrgFeed2
            };

            var productionChannel = new SnapChannel
            {
                Name       = "production",
                PushFeed   = nugetOrgFeed,
                UpdateFeed = nugetOrgFeed
            };

            var snapAppBefore = new SnapApp
            {
                Id           = "demoapp",
                SuperVisorId = Guid.NewGuid().ToString(),
                Version      = new SemanticVersion(1, 0, 0),
                Channels     = new List <SnapChannel>
                {
                    testChannel,
                    stagingChannel,
                    productionChannel
                },
                Target = new SnapTarget
                {
                    Os        = OSPlatform.Windows,
                    Framework = "netcoreapp2.1",
                    Rid       = "win-x64",
                    Shortcuts = new List <SnapShortcutLocation>
                    {
                        SnapShortcutLocation.Desktop,
                        SnapShortcutLocation.Startup
                    },
                    PersistentAssets = new List <string>
                    {
                        "subdirectory",
                        "myjsonfile.json"
                    }
                }
            };

            var snapApps = new SnapApps(snapAppBefore);

            var ex = Assert.Throws <Exception>(() => snapApps.BuildSnapApp(snapAppBefore.Id, snapAppBefore.Target.Rid,
                                                                           snapAppBefore.BuildNugetSources(nugetTempDirectory), _fileSystem));

            Assert.Equal($"Multiple nuget push feeds is not supported: nuget.org,nuget2.org. Application id: {snapAppBefore.Id}", ex.Message);
        }
Exemplo n.º 4
0
        public async Task TestBuildSnapApp()
        {
            await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem);

            var nugetOrgFeed = new SnapNugetFeed
            {
                Name            = "nuget.org",
                Source          = new Uri(NuGetConstants.V3FeedUrl),
                ProtocolVersion = NuGetProtocolVersion.V3,
                Username        = "******",
                Password        = "******",
                ApiKey          = "myapikey"
            };

            var updateFeedHttp = new SnapHttpFeed
            {
                Source = new Uri("https://mydynamicupdatefeed.com")
            };

            var testChannel = new SnapChannel
            {
                Name       = "test",
                PushFeed   = nugetOrgFeed,
                UpdateFeed = nugetOrgFeed,
                Current    = true
            };

            var stagingChannel = new SnapChannel
            {
                Name       = "staging",
                PushFeed   = nugetOrgFeed,
                UpdateFeed = updateFeedHttp
            };

            var productionChannel = new SnapChannel
            {
                Name       = "production",
                PushFeed   = nugetOrgFeed,
                UpdateFeed = nugetOrgFeed
            };

            var snapAppBefore = new SnapApp
            {
                Id      = "demoapp",
                MainExe = "demoapp",
                InstallDirectoryName = "demoapp",
                SuperVisorId         = Guid.NewGuid().ToString(),
                Version  = new SemanticVersion(1, 0, 0),
                Channels = new List <SnapChannel>
                {
                    testChannel,
                    stagingChannel,
                    productionChannel
                },
                Target = new SnapTarget
                {
                    Os        = OSPlatform.Windows,
                    Framework = "netcoreapp2.1",
                    Rid       = "win-x64",
                    Shortcuts = new List <SnapShortcutLocation>
                    {
                        SnapShortcutLocation.Desktop,
                        SnapShortcutLocation.Startup
                    },
                    PersistentAssets = new List <string>
                    {
                        "subdirectory",
                        "myjsonfile.json"
                    }
                }
            };

            var snapApps = new SnapApps(snapAppBefore);

            var snapAppAfter = snapApps.BuildSnapApp(snapAppBefore.Id, snapAppBefore.Target.Rid,
                                                     snapAppBefore.BuildNugetSources(nugetTempDirectory), _fileSystem);

            snapAppAfter.Version = snapAppBefore.Version.BumpMajor();

            // Generic
            Assert.Equal(snapAppBefore.Id, snapAppAfter.Id);
            Assert.Equal(snapAppBefore.InstallDirectoryName, snapAppAfter.InstallDirectoryName);
            Assert.Equal(snapAppBefore.MainExe, snapAppAfter.MainExe);
            Assert.NotNull(snapAppAfter.MainExe);
            Assert.Equal(snapAppBefore.SuperVisorId, snapAppAfter.SuperVisorId);
            Assert.True(snapAppBefore.Version < snapAppAfter.Version);

            // Target
            Assert.NotNull(snapAppBefore.Target);
            Assert.NotNull(snapAppAfter.Target);
            Assert.Equal(snapAppBefore.Target.Os, snapAppAfter.Target.Os);
            Assert.Equal(snapAppBefore.Target.Rid, snapAppAfter.Target.Rid);
            Assert.NotNull(snapAppBefore.Target.Framework);
            Assert.NotNull(snapAppAfter.Target.Framework);
            Assert.Equal(snapAppBefore.Target.Framework, snapAppAfter.Target.Framework);
            Assert.Equal(snapAppBefore.Target.Rid, snapAppAfter.Target.Rid);
            Assert.Equal(snapAppBefore.Target.Shortcuts, snapAppAfter.Target.Shortcuts);
            Assert.Equal(snapAppBefore.Target.PersistentAssets, snapAppAfter.Target.PersistentAssets);

            // Channels
            Assert.Equal(snapAppBefore.Channels.Count, snapAppAfter.Channels.Count);
            for (var index = 0; index < snapAppAfter.Channels.Count; index++)
            {
                var lhsChannel = snapAppBefore.Channels[index];
                var rhsChannel = snapAppAfter.Channels[index];

                Assert.Equal(lhsChannel.Name, rhsChannel.Name);
                Assert.NotNull(lhsChannel.PushFeed);
                Assert.NotNull(rhsChannel.PushFeed);
                Assert.NotNull(lhsChannel.UpdateFeed);
                Assert.NotNull(rhsChannel.UpdateFeed);

                if (index == 0)
                {
                    Assert.True(lhsChannel.Current);
                    Assert.True(rhsChannel.Current);
                }
                else
                {
                    Assert.False(lhsChannel.Current);
                    Assert.False(rhsChannel.Current);
                }

                var lhsNugetPushFeed = lhsChannel.PushFeed;
                var rhsNugetPushFeed = rhsChannel.PushFeed;

                Assert.Equal(lhsNugetPushFeed.Name, rhsNugetPushFeed.Name);
                Assert.Equal(lhsNugetPushFeed.Source, rhsNugetPushFeed.Source);
                Assert.Equal(lhsNugetPushFeed.ProtocolVersion, rhsNugetPushFeed.ProtocolVersion);
                Assert.Equal(lhsNugetPushFeed.ApiKey, rhsNugetPushFeed.ApiKey);
                Assert.Equal(lhsNugetPushFeed.Username, rhsNugetPushFeed.Username);

                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (lhsNugetPushFeed.IsPasswordEncryptionSupported())
                {
                    Assert.Equal(EncryptionUtility.DecryptString(lhsNugetPushFeed.Password), rhsNugetPushFeed.Password);
                }
                else
                {
                    Assert.Equal(lhsNugetPushFeed.Password, rhsNugetPushFeed.Password);
                }

                var lhsUpdateFeed = lhsChannel.UpdateFeed;
                var rhsUpdateFeed = rhsChannel.UpdateFeed;

                switch (rhsUpdateFeed)
                {
                case SnapNugetFeed rhsNugetUpdateFeed:
                    var lhsNugetUpdateFeed = (SnapNugetFeed)lhsUpdateFeed;
                    Assert.Equal(lhsNugetUpdateFeed.Name, rhsNugetUpdateFeed.Name);
                    Assert.Equal(lhsNugetUpdateFeed.Source, rhsNugetUpdateFeed.Source);
                    Assert.Equal(lhsNugetUpdateFeed.ProtocolVersion, rhsNugetUpdateFeed.ProtocolVersion);
                    Assert.Equal(lhsNugetUpdateFeed.ApiKey, rhsNugetUpdateFeed.ApiKey);
                    Assert.Equal(lhsNugetUpdateFeed.Username, rhsNugetUpdateFeed.Username);
                    Assert.Equal(
                        lhsNugetUpdateFeed.IsPasswordEncryptionSupported()
                                ? EncryptionUtility.DecryptString(lhsNugetUpdateFeed.Password)
                                : lhsNugetUpdateFeed.Password, rhsNugetUpdateFeed.Password);
                    break;

                case SnapHttpFeed rhsHttpUpdateFeed:
                    var lhsHttpUpdateFeed = (SnapHttpFeed)lhsUpdateFeed;
                    Assert.NotNull(lhsHttpUpdateFeed.Source);
                    Assert.NotNull(rhsHttpUpdateFeed.Source);
                    Assert.Equal(lhsHttpUpdateFeed.Source, rhsHttpUpdateFeed.Source);
                    break;

                default:
                    throw new NotSupportedException(rhsUpdateFeed.GetType().ToString());
                }
            }
        }