Esempio n. 1
0
        public void Should_Register_Default_Repositories_With_Custom_Base()
        {
            //Arrange

            var services = new ServiceCollection();

            var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext), services);

            options
            .AddDefaultRepositories(true)
            .SetDefaultRepositoryClasses(typeof(MyTestCustomBaseRepository <,>), typeof(MyTestCustomBaseRepository <>));

            //Act

            new MyTestRepositoryRegistrar(options).AddRepositories();

            //Assert

            //MyTestAggregateRootWithoutPk
            services.ShouldContainTransient(typeof(IBasicRepository <MyTestAggregateRootWithoutPk>), typeof(MyTestCustomBaseRepository <MyTestAggregateRootWithoutPk>));
            services.ShouldContainTransient(typeof(IRepository <MyTestAggregateRootWithoutPk>), typeof(MyTestCustomBaseRepository <MyTestAggregateRootWithoutPk>));

            //MyTestAggregateRootWithGuidPk
            services.ShouldContainTransient(typeof(IBasicRepository <MyTestAggregateRootWithGuidPk>), typeof(MyTestCustomBaseRepository <MyTestAggregateRootWithGuidPk, Guid>));
            services.ShouldContainTransient(typeof(IRepository <MyTestAggregateRootWithGuidPk>), typeof(MyTestCustomBaseRepository <MyTestAggregateRootWithGuidPk, Guid>));
            services.ShouldContainTransient(typeof(IBasicRepository <MyTestAggregateRootWithGuidPk, Guid>), typeof(MyTestCustomBaseRepository <MyTestAggregateRootWithGuidPk, Guid>));
            services.ShouldContainTransient(typeof(IRepository <MyTestAggregateRootWithGuidPk, Guid>), typeof(MyTestCustomBaseRepository <MyTestAggregateRootWithGuidPk, Guid>));

            //MyTestEntityWithInt32Pk
            services.ShouldContainTransient(typeof(IBasicRepository <MyTestEntityWithInt32Pk, int>), typeof(MyTestCustomBaseRepository <MyTestEntityWithInt32Pk, int>));
            services.ShouldContainTransient(typeof(IRepository <MyTestEntityWithInt32Pk, int>), typeof(MyTestCustomBaseRepository <MyTestEntityWithInt32Pk, int>));
        }
Esempio n. 2
0
        public void Should_Register_Default_Repositories_For_AggregateRoots()
        {
            //Arrange

            var services = new ServiceCollection();

            var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext));

            options.AddDefaultRepositories();

            //Act

            new MyTestRepositoryRegistrar(options).AddRepositories(services);

            //Assert

            services.ShouldContainTransient(typeof(IBasicRepository <MyTestAggregateRootWithoutPk>), typeof(MyTestDefaultRepository <MyTestAggregateRootWithoutPk>));
            services.ShouldContainTransient(typeof(IBasicRepository <MyTestAggregateRootWithGuidPk>), typeof(MyTestDefaultRepository <MyTestAggregateRootWithGuidPk, Guid>));
            services.ShouldContainTransient(typeof(IBasicRepository <MyTestAggregateRootWithGuidPk, Guid>), typeof(MyTestDefaultRepository <MyTestAggregateRootWithGuidPk, Guid>));

            services.ShouldNotContainService(typeof(IBasicRepository <MyTestEntityWithInt32Pk, int>));
        }
Esempio n. 3
0
        public void Should_Not_Register_Custom_Repository_If_Does_Not_Implement_Standard_Interfaces()
        {
            //Arrange

            var services = new ServiceCollection();

            var options = new TestDbContextRegistrationOptions(typeof(MyFakeDbContext), services);

            options
            .AddDefaultRepositories(true)
            .AddRepository <MyTestAggregateRootWithGuidPk, MyTestAggregateRootWithDefaultPkEmptyRepository>();

            //Act

            new MyTestRepositoryRegistrar(options).AddRepositories();

            //Assert

            services.ShouldNotContainService(typeof(IBasicRepository <MyTestAggregateRootWithGuidPk>));
            services.ShouldNotContainService(typeof(IRepository <MyTestAggregateRootWithGuidPk>));
            services.ShouldNotContainService(typeof(IBasicRepository <MyTestAggregateRootWithGuidPk, Guid>));
            services.ShouldNotContainService(typeof(IRepository <MyTestAggregateRootWithGuidPk, Guid>));
        }