Beispiel #1
0
        public void TestGetManifestAsync_GetsExistingManifest()
        {
            var command = new SampleTestCommand(HostEnvironment);

            command.Configure(null);

            string content = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": []
}";

            string libmanFilePath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanFilePath, content);

            command.Execute();

            Manifest manifest = command.Manifest;

            Assert.IsTrue(!manifest.Libraries.Any());
            Assert.AreEqual("wwwroot", manifest.DefaultDestination);
            Assert.AreEqual("cdnjs", manifest.DefaultProvider);
        }
Beispiel #2
0
        public void TestGetManifest()
        {
            var command = new SampleTestCommand(HostEnvironment);

            command.Configure(null);
            command.CreateNewManifest  = true;
            command.DefaultDestination = "wwwroot/lib";
            command.DefaultProvider    = "cdnjs";
            command.Execute();

            Assert.AreEqual("1.0", command.Manifest.Version);
        }
Beispiel #3
0
        public void TestGetManifestAsync_ThrowsIfNotCreatingNewOne()
        {
            var command = new SampleTestCommand(HostEnvironment);

            command.Configure(null);
            try
            {
                command.Execute();
            }
            catch (AggregateException age)
            {
                Assert.AreEqual(1, age.InnerExceptions.Count);
                Assert.AreEqual(typeof(InvalidOperationException), age.InnerExceptions[0].GetType());

                return;
            }

            Assert.Fail();
        }
Beispiel #4
0
        public void TestGetManifest_FailsIfInvalidManifest()
        {
            var command = new SampleTestCommand(HostEnvironment);

            command.Configure(null);

            // Invalid Json content. No commas after fields.
            string content = @"{
  ""version"": ""1.0""
  ""defaultProvider"": ""cdnjs""
  ""defaultDestination"": ""wwwroot""
  ""libraries"": []
}";

            string libmanFilePath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanFilePath, content);
            try
            {
                command.Execute();
            }
            catch (AggregateException age)
            {
                var ioe = age.InnerExceptions[0] as InvalidOperationException;
                if (ioe == null)
                {
                    Assert.Fail("Unexpected exception thrown");
                }

                Assert.AreEqual("Please fix the libman.json file and try again", ioe.Message);
            }

            Manifest manifest = command.Manifest;

            Assert.IsNull(manifest);
            var logger = HostEnvironment.Logger as TestLogger;

            Assert.AreEqual("Library Manager manifest contains syntax errors. Please fix the errors in libman.json, then try again.", logger.Messages[0].Value);
        }