Пример #1
0
 public void WhenExecuteExtensionWithNullCommands_ThenThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           CommandRegistryExtensions.Execute(
                                               Mock.Of <ICommandRegistry <BaseCommand> >(),
                                               default(IEnumerable <BaseCommand>)));
 }
Пример #2
0
 public void WhenExecuteExtensionOnNullBusWithEmptyCommands_ThenThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           CommandRegistryExtensions.Execute(
                                               default(ICommandRegistry <BaseCommand>),
                                               Enumerable.Empty <BaseCommand>()));
 }
Пример #3
0
 public void WhenExecuteExtensionOnNullBus_ThenThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           CommandRegistryExtensions.Execute(
                                               default(ICommandRegistry <BaseCommand>),
                                               new FooCommand()));
 }
Пример #4
0
 public void WhenExecuteExtensionWithNullHeadersAndCommands_ThenThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           CommandRegistryExtensions.Execute(
                                               Mock.Of <ICommandRegistry <BaseCommand> >(),
                                               Enumerable.Empty <BaseCommand>(),
                                               default(IDictionary <string, object>)));
 }
Пример #5
0
        public void WhenExecuteExtensionWithHeadersAndCommands_ThenCopiesDictionary()
        {
            var headers = new Dictionary <string, object>();

            headers.Add("IP", "localhost");

            var bus = new Mock <ICommandRegistry <BaseCommand> >();

            CommandRegistryExtensions.Execute(
                bus.Object,
                new BaseCommand[] { new FooCommand() },
                headers);

            bus.Verify(x => x.Execute(It.IsAny <BaseCommand>(), It.Is <IDictionary <string, object> >(dict => Object.ReferenceEquals(dict, headers))), Times.Never());
            bus.Verify(x => x.Execute(It.IsAny <BaseCommand>(), It.Is <IDictionary <string, object> >(dict =>
                                                                                                      dict.ContainsKey("IP") && ((string)dict["IP"]) == "localhost")));
        }
Пример #6
0
        public void WhenExecuteExtensionWithCommands_ThenCreatesNewHeadersForEach()
        {
            var headers = new HashSet <IDictionary <string, object> >();
            var bus     = new Mock <ICommandRegistry <BaseCommand> >();

            bus.Setup(x => x.Execute(It.IsAny <BaseCommand>(), It.IsAny <IDictionary <string, object> >()))
            .Callback((BaseCommand cmd, IDictionary <string, object> h) => headers.Add(h));

            CommandRegistryExtensions.Execute(
                bus.Object,
                new BaseCommand[] { new FooCommand(), new FooCommand() });

            Assert.Equal(2, headers.Count);
            var dupe = new Dictionary <string, object>();

            headers.Add(dupe);
            headers.Add(dupe);

            Assert.Equal(3, headers.Count);
        }