Beispiel #1
0
        public void does_not_throw_exception_when_same_command_is_added_multiple_times()
        {
            var sut = new DefaultCommandRegistry();

            sut.Register(typeof(FooCommand));
            sut.Register(typeof(FooCommand));
        }
Beispiel #2
0
        public void throws_exception_if_commands_with_same_name_are_added()
        {
            var firstCommand  = typeof(FooCommand);
            var secondCommand = typeof(BarCommand);

            var sut = new DefaultCommandRegistry();

            sut.Register("foo", firstCommand);

            Assert.Throws <Exception>(() => sut.Register("foo", secondCommand));
        }
Beispiel #3
0
        public void throws_exception_if_command_is_not_a_real_command()
        {
            var invalidCommandType = typeof(string);
            var sut = new DefaultCommandRegistry();

            Assert.Throws <NotSupportedException>(() => sut.Register(invalidCommandType));
        }
Beispiel #4
0
        public void GetAll_returns_expected_when_multiple_commands_are_added()
        {
            var sut = new DefaultCommandRegistry();

            sut.Register(typeof(FooCommand));
            sut.Register(typeof(BarCommand));

            var result = sut
                         .GetAll()
                         .Select(x => x.ImplementationType)
                         .ToArray();

            Assert.Equal(new[]
            {
                typeof(FooCommand),
                typeof(BarCommand),
            }, result);
        }
Beispiel #5
0
        public void registers_with_expected_command_name(Type commandType, string expectedCommandName)
        {
            var sut = new DefaultCommandRegistry();

            sut.Register(commandType);

            var result = sut.GetAll().Single();

            Assert.Equal(expectedCommandName, result.CommandName);
        }
Beispiel #6
0
        public void favor_command_name_from_class_annotation()
        {
            var sut = new DefaultCommandRegistry();

            sut.Register(typeof(NamedByClassAnnotationCommand));

            var result = sut.GetAll().Single();

            Assert.Equal("foo", result.CommandName);
        }
Beispiel #7
0
        public void Find_returns_expected_command_when_direct_match()
        {
            var expected = typeof(FooCommand);
            var sut      = new DefaultCommandRegistry();

            sut.Register(expected);

            var result = sut.Find("Foo");

            Assert.Equal(expected, result);
        }
Beispiel #8
0
        public void Find_is_case_insensitive()
        {
            var expected = typeof(FooCommand);
            var sut      = new DefaultCommandRegistry();

            sut.Register(expected);

            var result = sut.Find("foo");

            Assert.Equal(expected, result);
        }
Beispiel #9
0
        public void can_use_specific_command_name()
        {
            var expected = new CommandRegistration(
                commandName: "anoterCommandName",
                commandType: typeof(ICommand <EmptyArgument>),
                argumentType: typeof(EmptyArgument),
                implementationType: typeof(FooCommand)
                );

            var sut    = new DefaultCommandRegistry();
            var result = sut.Register(expected.CommandName, expected.ImplementationType);

            Assert.Equal(expected, result);
        }
Beispiel #10
0
        public void can_use_custom_command_name_convention()
        {
            // arrange
            var expectedCommandName = "another command name";

            var sut = new DefaultCommandRegistry();

            sut.ChangeCommandNameConvention(new StubCommandNameConvention(expectedCommandName));

            // act
            var result = sut.Register(typeof(FooCommand));

            // assert
            Assert.Equal(expectedCommandName, result.CommandName);
        }
Beispiel #11
0
        public void Register_returns_expected_command_registration()
        {
            var dummyCommand = typeof(FooCommand);

            var sut    = new DefaultCommandRegistry();
            var result = sut.Register(dummyCommand);

            var expected = new CommandRegistration(
                commandName: "foo",
                commandType: typeof(ICommand <EmptyArgument>),
                argumentType: typeof(EmptyArgument),
                implementationType: typeof(FooCommand)
                );

            Assert.Equal(expected, result);
        }
Beispiel #12
0
        public void can_add_multiple_commands_at_once()
        {
            var sut = new DefaultCommandRegistry();

            sut.Register(new[]
            {
                typeof(FooCommand),
                typeof(BarCommand),
            });

            var result = sut
                         .GetAll()
                         .Select(x => x.ImplementationType)
                         .ToArray();

            Assert.Equal(new[]
            {
                typeof(FooCommand),
                typeof(BarCommand),
            }, result);
        }
Beispiel #13
0
        public void throws_exception_if_registering_a_type_with_multiple_command_implementations_3()
        {
            var sut = new DefaultCommandRegistry();

            Assert.Throws <NotSupportedException>(() => sut.Register("dummyName", typeof(MultiArgumentCommand)));
        }