Esempio n. 1
0
        public void NoOptions_WithoutHandlers_OnlyDefaultsRegistered()
        {
            var fakeCollection = new TestServiceCollection();

            fakeCollection.AddSeaOrDewHandlers();

            ServicesAssert.OnlyHandlerResolversRegistered(fakeCollection);
        }
Esempio n. 2
0
        public void LifetimeOption_WithoutHandlers_OnlyDefaultsRegistered(ServiceLifetime lifetime)
        {
            var fakeCollection = new TestServiceCollection();

            fakeCollection.AddSeaOrDewHandlers(options =>
            {
                options.UseLifetimeScope(lifetime);
            });

            ServicesAssert.OnlyHandlerResolversRegistered(fakeCollection);
        }
Esempio n. 3
0
        public void TryAdd_WithoutExistingInstanceRegistered_AllRegister()
        {
            var fakeCollection = new TestServiceCollection();

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

            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(CommandHandler));
            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(QueryHandler));
            Assert.Equal(SetACommandCount + 2, fakeCollection.Count);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void TryAdd_WithExistingHandlersRegistered_DoesNotReregister()
        {
            var fakeCollection            = new TestServiceCollection();
            var commandInstanceDescriptor = new ServiceDescriptor(typeof(CommandHandler), new object());

            fakeCollection.Add(commandInstanceDescriptor);
            var queryInstanceDescriptor = new ServiceDescriptor(typeof(QueryHandler), new object());

            fakeCollection.Add(queryInstanceDescriptor);

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

            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(CommandHandler) && s == commandInstanceDescriptor);
            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(QueryHandler) && s == queryInstanceDescriptor);
            Assert.Equal(2, fakeCollection.Count);
        }
Esempio n. 6
0
        public void TryAdd_WithExistingInstanceRegistered_DoesNotReregister()
        {
            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 = true;
            });

            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(CommandHandler));
            Assert.Contains(fakeCollection, s => s.ServiceType == typeof(QueryHandler));
            Assert.Equal(SetACommandCount + 2, fakeCollection.Count);
            Assert.Contains(fakeCollection, s => s == testDescriptor);
        }
Esempio n. 7
0
        public void NoLifeTimeOption_WithHandlers_DefaultLifetimeIsScoped()
        {
            var fakeCollection = new TestServiceCollection();

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

            Assert.All(fakeCollection, s =>
            {
                if (s.ServiceType == typeof(CommandHandler))
                {
                    return;
                }
                if (s.ServiceType == typeof(QueryHandler))
                {
                    return;
                }
                Assert.Equal(ServiceLifetime.Scoped, s.Lifetime);
            });
        }
Esempio n. 8
0
        public void LifetimeOption_WithHandlers_CorrectlyRegistersScope(ServiceLifetime lifetime)
        {
            var fakeCollection = new TestServiceCollection();

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

            Assert.All(fakeCollection, s =>
            {
                if (s.ServiceType == typeof(CommandHandler))
                {
                    return;
                }
                if (s.ServiceType == typeof(QueryHandler))
                {
                    return;
                }
                Assert.Equal(lifetime, s.Lifetime);
            });
        }