File: CommandLineExceptionTests.cs

package info (click to toggle)
mono 3.2.8%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 527,964 kB
  • ctags: 623,327
  • sloc: cs: 3,938,236; xml: 1,891,753; ansic: 418,737; java: 59,920; sh: 15,754; makefile: 11,067; sql: 7,956; perl: 2,279; cpp: 1,380; yacc: 1,203; python: 594; asm: 422; sed: 16; php: 1
file content (103 lines) | stat: -rw-r--r-- 4,385 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

namespace CmdLine
{
    extern alias migrate;
    using System;
    using System.Data.Entity;
    using Xunit;

    public class CommandLineExceptionTests
    {
        [Fact]
        public void Constructors_allow_for_nulls_message_and_inner_exception()
        {
            Assert.True(new migrate::CmdLine.CommandLineException((string)null).Message.Contains("'CmdLine.CommandLineException'"));
            Assert.Null(
                new migrate::CmdLine.CommandLineException(
                    new migrate::CmdLine.CommandArgumentHelp(typeof(SomeCommandLineClass)), null).InnerException);
        }

        [Fact]
        public void Constructors_throw_when_given_null_CommandArgumentHelp()
        {
            Assert.Equal(
                "argumentHelp",
                Assert.Throws<ArgumentNullException>(
                    () => new migrate::CmdLine.CommandLineException((migrate::CmdLine.CommandArgumentHelp)null)).ParamName);

            Assert.Equal(
                "argumentHelp",
                Assert.Throws<ArgumentNullException>(
                    () => new migrate::CmdLine.CommandLineException(null, new Exception())).ParamName);
        }

        [Fact]
        public void Constructor_uses_given_message_and_sets_up_serialization()
        {
            var exception = new migrate::CmdLine.CommandLineException("I'm a DOS prompt.");

            Assert.Equal("I'm a DOS prompt.", exception.Message);
            Assert.Null(exception.ArgumentHelp);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("I'm a DOS prompt.", exception.Message);
            Assert.Null(exception.ArgumentHelp);
        }

        [Fact]
        public void Constructor_uses_given_ArgumentHelp_and_sets_up_serialization()
        {
            var exception =
                new migrate::CmdLine.CommandLineException(
                    new migrate::CmdLine.CommandArgumentHelp(typeof(SomeCommandLineClass), "CLI"));

            Assert.Equal("CLI", exception.Message);
            Assert.Equal("Code First Migrations Command Line Utility", exception.ArgumentHelp.Title);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("CLI", exception.Message);
            Assert.Equal("Code First Migrations Command Line Utility", exception.ArgumentHelp.Title);
        }

        [Fact]
        public void Constructor_uses_given_ArgumentHelp_and_inner_exception_and_sets_up_serialization()
        {
            var innerException = new Exception("You are so exceptional!");
            var exception =
                new migrate::CmdLine.CommandLineException(
                    new migrate::CmdLine.CommandArgumentHelp(typeof(SomeCommandLineClass), "Look inside."), innerException);

            Assert.Equal("Look inside.", exception.Message);
            Assert.Same(innerException, exception.InnerException);
            Assert.Equal("Code First Migrations Command Line Utility", exception.ArgumentHelp.Title);

            exception = ExceptionHelpers.SerializeAndDeserialize(exception);

            Assert.Equal("Look inside.", exception.Message);
            Assert.Equal(innerException.Message, exception.InnerException.Message);
            Assert.Equal("Code First Migrations Command Line Utility", exception.ArgumentHelp.Title);
        }

        [Fact]
        public void ArgumentHelp_can_be_read_and_set()
        {
            var argHelp = new migrate::CmdLine.CommandArgumentHelp(typeof(SomeCommandLineClass));
            Assert.Same(
                argHelp, new migrate::CmdLine.CommandLineException("")
                {
                    ArgumentHelp = argHelp
                }.ArgumentHelp);
        }

        [migrate::CmdLine.CommandLineArgumentsAttribute(
            Program = "migrate",
            TitleResourceId = migrate::System.Data.Entity.Migrations.Console.Resources.EntityRes.MigrateTitle,
            DescriptionResourceId = migrate::System.Data.Entity.Migrations.Console.Resources.EntityRes.MigrateDescription)]
        public class SomeCommandLineClass
        {
        }
    }
}