Ejemplo n.º 1
0
            public void should_log_warning_on_duplicate_foo()
            {
                var warnings = MockLogger.MessagesFor(LogLevel.Warn);

                warnings.Count.Should().Be(1);
                warnings[0].Should().BeEquivalentTo("A value for 'foo' has already been added with the value '1'. Ignoring foo='2'.");
            }
Ejemplo n.º 2
0
            public void should_log_warning_on_duplicate_foo()
            {
                var warnings = MockLogger.MessagesFor(LogLevel.Warn);

                warnings.Count.ShouldEqual(1);
                warnings[0].ShouldEqual("A value for 'foo' has already been added with the value '1'. Ignoring foo='2'.", StringComparer.OrdinalIgnoreCase);
            }
Ejemplo n.º 3
0
            public void property_settings_should_be_logged_as_debug_messages()
            {
                var messages = MockLogger.MessagesFor(LogLevel.Debug);

                messages.Count.ShouldEqual(2);
                messages.Contains("Setting property 'commitId': 1234abcd");
                messages.Contains("Setting property 'version': 0.1.0");
            }
Ejemplo n.º 4
0
            public void should_log_the_message_we_expect()
            {
                var messages = MockLogger.MessagesFor(LogLevel.Info);

                messages.ShouldNotBeEmpty();
                messages.Count.ShouldEqual(1);
                messages[0].ShouldContain("Export would have been with options");
            }
Ejemplo n.º 5
0
            public void should_log_the_message_we_expect()
            {
                var messages = MockLogger.MessagesFor(LogLevel.Info);

                messages.ShouldNotBeEmpty();
                messages.Count.ShouldEqual(1);
                messages[0].ShouldContain("Pin would have called");
            }
            public void should_log_current_directory_if_no_outputdirectory()
            {
                because();

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual("Would have generated a new package specification at c:\\chocolatey\\Bob");
            }
Ejemplo n.º 7
0
            public void should_log_template_location_if_no_template_name()
            {
                because();

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual("Would have listed templates in {0}".format_with(ApplicationParameters.TemplatesLocation));
            }
            public void should_write_file_withe_replaced_tokens()
            {
                because();

                var debugs = MockLogger.MessagesFor(LogLevel.Debug);

                debugs.Count.ShouldEqual(1);
                debugs[0].ShouldEqual("Bob");
            }
Ejemplo n.º 9
0
            public void generated_package_should_be_in_current_directory()
            {
                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(2);
                infos[0].ShouldEqual("Attempting to build package from 'myPackage.nuspec'.");
                infos[1].ShouldEqual(string.Concat("Successfully created package '", package_path, "'"));

                File.Exists(package_path).ShouldBeTrue();
            }
Ejemplo n.º 10
0
            public void should_log_template_name_if_template_name()
            {
                config.TemplateCommand.Name = "msi";
                because();

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual("Would have listed information about {0}".format_with(config.TemplateCommand.Name));
            }
Ejemplo n.º 11
0
            public void generated_package_should_be_in_current_directory()
            {
                Context();

                because();

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual("Chocolatey would have searched for a nuspec file in \"c:\\projects\\chocolatey\" and attempted to compile it.");
            }
            public void should_log_output_directory_if_outputdirectory_is_specified()
            {
                config.OutputDirectory = "c:\\packages";

                because();

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual("Would have generated a new package specification at c:\\packages\\Bob");
            }
Ejemplo n.º 13
0
            public void should_log_the_expected_error_message()
            {
                reset();

                FaultTolerance.try_catch_with_logging_exception(
                    () => { throw new Exception("This is the message"); },
                    "You have an error"
                    );

                MockLogger.MessagesFor(LogLevel.Error)[0].ShouldEqual("You have an error:{0} This is the message".format_with(Environment.NewLine));
            }
Ejemplo n.º 14
0
            public void should_log_an_error_message()
            {
                reset();

                FaultTolerance.try_catch_with_logging_exception(
                    () => { throw new Exception("This is the message"); },
                    "You have an error"
                    );

                MockLogger.MessagesFor(LogLevel.Error).Count.ShouldEqual(1);
            }
Ejemplo n.º 15
0
            public void should_return_immediately_when_successful()
            {
                reset();

                var i = 0;

                FaultTolerance.retry(3, () => { i += 1; }, waitDurationMilliseconds: 0);

                i.ShouldEqual(1);

                MockLogger.MessagesFor(LogLevel.Warn).Count.ShouldEqual(0);
            }
Ejemplo n.º 16
0
            public void should_log_a_warning_message_when_set_to_warn()
            {
                reset();

                FaultTolerance.try_catch_with_logging_exception(
                    () => { throw new Exception("This is the message"); },
                    "You have an error",
                    logWarningInsteadOfError: true
                    );

                MockLogger.MessagesFor(LogLevel.Warn).Count.ShouldEqual(1);
            }
Ejemplo n.º 17
0
            public void generated_package_should_be_in_specified_directory()
            {
                Context();

                config.OutputDirectory = "c:\\packages";

                because();

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual("Chocolatey would have searched for a nuspec file in \"c:\\packages\" and attempted to compile it.");
            }
Ejemplo n.º 18
0
            public void should_log_a_warning_about_locked_files()
            {
                bool lockedFiles = false;

                foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
                {
                    if (message.Contains("The process cannot access the file"))
                    {
                        lockedFiles = true;
                    }
                }

                lockedFiles.Should().BeTrue();
            }
Ejemplo n.º 19
0
            public void should_generate_all_files_and_directories()
            {
                because();

                directoryCreated.Count.ShouldEqual(2, "There should be only 2 directories, but there was: " + string.Join(", ", directoryCreated));
                directoryCreated[0].ShouldEqual("c:\\chocolatey\\Bob");
                directoryCreated[1].ShouldEqual("c:\\chocolatey\\Bob\\tools");

                files.Count.ShouldEqual(2, "There should be only 2 files, but there was: " + string.Join(", ", files));
                files[0].ShouldEqual("c:\\chocolatey\\Bob\\__name_replace__.nuspec");
                files[1].ShouldEqual("c:\\chocolatey\\Bob\\random.txt");

                MockLogger.MessagesFor(LogLevel.Info).Last().ShouldEqual(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\chocolatey\Bob'", Environment.NewLine));
            }
Ejemplo n.º 20
0
            public void should_contain_a_warning_message_that_it_was_unable_to_install_a_package()
            {
                bool installedSuccessfully = false;

                foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
                {
                    if (message.Contains("0/1"))
                    {
                        installedSuccessfully = true;
                    }
                }

                installedSuccessfully.ShouldBeTrue();
            }
Ejemplo n.º 21
0
            public void should_contain_a_message_that_it_would_have_run_a_powershell_script()
            {
                bool expectedMessage = false;

                foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
                {
                    if (message.Contains("chocolateyuninstall.ps1"))
                    {
                        expectedMessage = true;
                    }
                }

                expectedMessage.ShouldBeTrue();
            }
Ejemplo n.º 22
0
            public void should_contain_a_message_that_it_would_have_uninstalled_a_package()
            {
                bool expectedMessage = false;

                foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
                {
                    if (message.Contains("Would have uninstalled installpackage v1.0.0"))
                    {
                        expectedMessage = true;
                    }
                }

                expectedMessage.ShouldBeTrue();
            }
Ejemplo n.º 23
0
            public void should_contain_a_message_that_it_was_unable_to_find_package()
            {
                bool expectedMessage = false;

                foreach (var message in MockLogger.MessagesFor(LogLevel.Error).or_empty_list_if_null())
                {
                    if (message.Contains("somethingnonexisting is not installed. Cannot uninstall a non-existent package"))
                    {
                        expectedMessage = true;
                    }
                }

                expectedMessage.ShouldBeTrue();
            }
Ejemplo n.º 24
0
            public void should_contain_a_message_that_it_was_not_able_to_uninstall()
            {
                bool expectedMessage = false;

                foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
                {
                    if (message.Contains("uninstalled 0/1"))
                    {
                        expectedMessage = true;
                    }
                }

                expectedMessage.ShouldBeTrue();
            }
Ejemplo n.º 25
0
            public void should_log_warning_each_time()
            {
                reset();

                try
                {
                    FaultTolerance.retry(3, () => { throw new Exception("YIKES"); }, waitDurationMilliseconds: 0);
                }
                catch
                {
                    // don't care
                }

                MockLogger.MessagesFor(LogLevel.Warn).Count.ShouldEqual(2);
            }
            public void should_log_info_if_regular_output()
            {
                config.RegularOutput = true;

                because();

                var debugs = MockLogger.MessagesFor(LogLevel.Debug);

                debugs.Count.ShouldEqual(1);
                debugs[0].ShouldEqual("Bob");

                var infos = MockLogger.MessagesFor(LogLevel.Info);

                infos.Count.ShouldEqual(1);
                infos[0].ShouldEqual(string.Format(@"Generating template to a file{0} at 'c:\packages\bob.nuspec'", Environment.NewLine));
            }
            public void should_generate_all_files_and_directories_even_with_outputdirectory()
            {
                config.OutputDirectory = "c:\\packages";

                because();

                var directories = directoryCreated.ToList();

                directories.Count.ShouldEqual(2, "There should be 2 directories, but there was: " + string.Join(", ", directories));
                directories[0].ShouldEqual("c:\\packages\\Bob");
                directories[1].ShouldEqual("c:\\packages\\Bob\\tools");

                files.Count.ShouldEqual(2, "There should be 2 files, but there was: " + string.Join(", ", files));
                files[0].ShouldEqual("c:\\packages\\Bob\\__name_replace__.nuspec");
                files[1].ShouldEqual("c:\\packages\\Bob\\random.txt");

                MockLogger.MessagesFor(LogLevel.Info).Last().ShouldEqual(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\packages\Bob'", Environment.NewLine));
            }
Ejemplo n.º 28
0
            public void should_generate_all_files_and_directories()
            {
                because();

                var directories = directoryCreated.ToList();

                directories.Count.Should().Be(3, "There should be 3 directories, but there was: " + string.Join(", ", directories));
                directories[0].Should().Be("c:\\chocolatey\\Bob");
                directories[1].Should().Be("c:\\chocolatey\\Bob\\tools");
                directories[2].Should().Be("c:\\chocolatey\\Bob\\tools\\lower");

                files.Count.Should().Be(4, "There should be 4 files, but there was: " + string.Join(", ", files));
                files[0].Should().Be("c:\\chocolatey\\Bob\\__name_replace__.nuspec");
                files[1].Should().Be("c:\\chocolatey\\Bob\\random.txt");
                files[2].Should().Be("c:\\chocolatey\\Bob\\tools\\chocolateyInstall.ps1");
                files[3].Should().Be("c:\\chocolatey\\Bob\\tools\\lower\\another.ps1");

                MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\chocolatey\Bob'", Environment.NewLine));
            }
Ejemplo n.º 29
0
 public void should_log_a_warning()
 {
     MockLogger.MessagesFor(LogLevel.Warn).Count.ShouldEqual(1);
 }
Ejemplo n.º 30
0
 public void should_log_a_message_about_what_it_would_have_done()
 {
     MockLogger.MessagesFor(LogLevel.Info).FirstOrDefault().ShouldContain("This would have unpacked");
 }