Example #1
0
        public void ShouldReturnNoSpecimenForNullSpecimenContext(
            [Frozen] Mock <IRequestSpecification> optionsSpecification)
        {
            var optionsType = typeof(DbContextOptions <TestDbContext>);
            var options     = new DbContextOptions <TestDbContext>();
            var builder     = new DelegatingDbContextOptionsBuilder(optionsSpecification.Object)
            {
                BuildOptions = _ => options
            };

            optionsSpecification
            .Setup(x => x.IsSatisfiedBy(It.Is <Type>(x => x == optionsType)))
            .Returns(true);

            Action act = () => builder.Create(typeof(DbContextOptions <TestDbContext>), default);

            act.Should().ThrowExactly <ArgumentNullException>();
        }
Example #2
0
        public void ShouldReturnNoSpecimenForNonOptionsRequestt(
            object request,
            Mock <ISpecimenContext> contextMock,
            [Frozen] Mock <IRequestSpecification> optionsSpecification)
        {
            var optionsType = typeof(DbContextOptions <TestDbContext>);
            var options     = new DbContextOptions <TestDbContext>();
            var builder     = new DelegatingDbContextOptionsBuilder(optionsSpecification.Object)
            {
                BuildOptions = _ => options
            };

            optionsSpecification
            .Setup(x => x.IsSatisfiedBy(It.Is <Type>(x => x == optionsType)))
            .Returns(true);

            var actual = builder.Create(request, contextMock.Object);

            actual.Should().BeOfType <NoSpecimen>();
        }
Example #3
0
        public void ShouldCreateDbContext(
            Mock <ISpecimenContext> contextMock,
            [Frozen] Mock <IRequestSpecification> optionsSpecification)
        {
            var optionsType = typeof(DbContextOptions <TestDbContext>);
            var options     = new DbContextOptions <TestDbContext>();
            var builder     = new DelegatingDbContextOptionsBuilder(optionsSpecification.Object)
            {
                BuildOptions = _ => options
            };

            optionsSpecification
            .Setup(x => x.IsSatisfiedBy(It.Is <Type>(x => x == optionsType)))
            .Returns(true);

            var actual = builder.Create(typeof(DbContextOptions <TestDbContext>), contextMock.Object);

            actual.Should().NotBeNull()
            .And.Subject.Should().BeOfType(optionsType);
        }