private int New(NewOptions opts)
        {
            string version = opts.Version ?? installationManager.GetLatestDarkRiftVersion();
            ServerTier tier = opts.Pro ? ServerTier.Pro : ServerTier.Free;
            string targetDirectory = opts.TargetDirectory ?? Environment.CurrentDirectory;

            installationManager.Install(version, tier, opts.Platform, false);

            try
            {
                templater.Template(opts.Type, targetDirectory, version, tier, opts.Platform, opts.Force);
            }
            catch (DirectoryNotEmptyException)
            {
                Console.Error.WriteLine(Output.Red("Cannot create from template, the directory is not empty. Use -f to force creation."));
                Console.Error.WriteLine("\t" + Environment.GetCommandLineArgs()[0] + " " + Parser.Default.FormatCommandLine(new NewOptions { Type = opts.Type, TargetDirectory = opts.TargetDirectory, Force = true }));
                return 1;
            }
            catch (ArgumentException e)
            {
                Console.Error.WriteLine(Output.Red(e.Message));
                return 1;
            }

            return 0;
        }
Example #2
0
        public void TestGetLatestDarkRiftVersionWhenMemoised()
        {
            // GIVEN the remote can fetch the latest DarkRift version
            mockIRemoteRepository.Setup(r => r.GetLatestDarkRiftVersion()).Returns("a-version");

            // WHEN I get the latest DarkRift version
            InstallationManager classUnderTest = new InstallationManager(mockIRemoteRepository.Object, null, null, null);
            string result1 = classUnderTest.GetLatestDarkRiftVersion();

            // THEN the returned version is correct
            Assert.AreEqual("a-version", result1);

            // WHEN I get the latest DarkRift version a second time
            string result2 = classUnderTest.GetLatestDarkRiftVersion();

            // THEN the returned version is correct
            Assert.AreEqual("a-version", result2);

            // AND the remote was not contacted again
            mockIRemoteRepository.Verify(r => r.GetLatestDarkRiftVersion(), Times.Once);
        }
Example #3
0
        public void TestGetLatestDarkRiftVersionWhenRemoteAvailable()
        {
            // GIVEN the remote can fetch the latest DarkRift version
            mockIRemoteRepository.Setup(r => r.GetLatestDarkRiftVersion()).Returns("a-version");

            // WHEN I get the latest DarkRift version
            InstallationManager classUnderTest = new InstallationManager(mockIRemoteRepository.Object, null, null, null);
            string result = classUnderTest.GetLatestDarkRiftVersion();

            // THEN the returned version is correct
            Assert.AreEqual("a-version", result);
        }
Example #4
0
        public void TestGetLatestDarkRiftVersionWhenRemoteNotAvailableNorInProfile()
        {
            // GIVEN the remote cannot fetch the latest DarkRift version
            mockIRemoteRepository.Setup(r => r.GetLatestDarkRiftVersion()).Returns((string)null);

            // AND the profile does not contain a known version
            Profile profile = new Profile();

            mockIContext.Setup(c => c.Profile).Returns(profile);
            profile.LatestKnownDarkRiftVersion = null;

            // WHEN I get the latest DarkRift version
            InstallationManager classUnderTest = new InstallationManager(mockIRemoteRepository.Object, null, null, mockIContext.Object);
            string result = classUnderTest.GetLatestDarkRiftVersion();

            // THEN the returned version is null
            Assert.IsNull(result);
        }