Example #1
0
        public void TryAddIsFalse_WithExistingHandlersRegistered_RegistersExtra()
        {
            var fakeCollection = new TestServiceCollection();

            fakeCollection.Add(new ServiceDescriptor(typeof(CommandHandler), new object()));
            fakeCollection.Add(new ServiceDescriptor(typeof(QueryHandler), new object()));

            fakeCollection.AddSeaOrDewHandlers(options =>
            {
                options.TryAdd = false;
            });

            Assert.Equal(2, fakeCollection.Count(s => s.ServiceType == typeof(CommandHandler)));
            Assert.Equal(2, fakeCollection.Count(s => s.ServiceType == typeof(QueryHandler)));
            Assert.Equal(4, fakeCollection.Count);
        }
Example #2
0
        public void TryAddIsFalse_WithExistingInstanceRegistered_RegistersExtra()
        {
            var fakeCollection = new TestServiceCollection();
            var testDescriptor = new ServiceDescriptor(
                typeof(ICustomCommandHandler <CustomTestCommand, CustomTestCommandResult>),
                new object());

            fakeCollection.Add(testDescriptor);

            fakeCollection.AddSeaOrDewHandlers(options =>
            {
                options.LoadCommandHandlersFromAssemblyUnderNamespace(TestHandlersAssembly, "csMACnz.SeaOrDew.Tests.TestHandlers.SetA");
                options.TryAdd = false;
            });

            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(CommandHandler));
            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(QueryHandler));
            Assert.Equal(SetACommandCount + 2 + 1, fakeCollection.Count);
            Assert.Contains(fakeCollection, s => s == testDescriptor);
            Assert.Equal(2, fakeCollection.Count(s => s.ServiceType == typeof(ICustomCommandHandler <CustomTestCommand, CustomTestCommandResult>)));
        }