Example #1
0
        public ComparerSpecialized(ITestOutputHelper output)
        {
            _output  = output;
            _options = this
                       .CreateUniqueClassOptions <SpecializedDbContext>();

            using (var context = new SpecializedDbContext(_options))
            {
                _connectionString = context.Database.GetDbConnection().ConnectionString;
                context.Database.EnsureCreated();
            }
        }
        public void CompareSpecializedDbContext()
        {
            //SETUP
            using (var context = new SpecializedDbContext(_options))
            {
                var comparer = new CompareEfSql();

                //ATTEMPT
                var hasErrors = comparer.CompareEfWithDb(context);

                //VERIFY
                hasErrors.ShouldBeFalse(comparer.GetAllErrors);
            }
        }
Example #3
0
        public void CompareSpecializedDbContext()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <SpecializedDbContext>();

            using var context = new SpecializedDbContext(options);
            context.Database.EnsureClean();

            var comparer = new CompareEfSql();

            //ATTEMPT
            var hasErrors = comparer.CompareEfWithDb(context);

            //VERIFY
            hasErrors.ShouldBeFalse(comparer.GetAllErrors);
        }
        public void TestResetKeysSingleEntityPrivateSetter()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SpecializedDbContext>();

            using (var context = new SpecializedDbContext(options))
            {
                var entity = new AllTypesEntity();
                entity.SetId(123);

                //ATTEMPT
                var resetter = new DataResetter(context);
                resetter.ResetKeysSingleEntity(entity);

                //VERIFY
                entity.Id.ShouldEqual(0);
            }
        }
Example #5
0
        public void CompareSpecializedDbContext()
        {
            //SETUP
            using (var context = new SpecializedDbContext(_options))
            {
                var comparer = new CompareEfSql();

                //ATTEMPT
                var hasErrors = comparer.CompareEfWithDb(context);

                //VERIFY
#if NETCOREAPP2_1
                hasErrors.ShouldBeFalse(comparer.GetAllErrors);
#elif NETCOREAPP3_0
                hasErrors.ShouldBeTrue(comparer.GetAllErrors);
                comparer.GetAllErrors.ShouldEqual("DIFFERENT: BookDetail->Property 'Price', nullability. Expected = NOT NULL, found = NULL");
#endif
            }
        }
Example #6
0
        public void TestRelationalTypeMappingSourceOk()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <SpecializedDbContext>();

            using var context = new SpecializedDbContext(options);
            context.Database.EnsureClean();

            var typeMappingSource = context.GetService <IRelationalTypeMappingSource>();

            //ATTEMPT
            var constantString = typeMappingSource.FindMapping(typeof(string)).GenerateSqlLiteral("hello");
            var constantInt    = typeMappingSource.FindMapping(typeof(int)).GenerateSqlLiteral(123);
            var constantEnum   = typeMappingSource.FindMapping(typeof(Settings)).GenerateSqlLiteral(Settings.One);
            var constantBool   = typeMappingSource.FindMapping(typeof(bool)).GenerateSqlLiteral(true);

            //VERIFY
            constantString.ShouldEqual("N'hello'");
            constantInt.ShouldEqual("123");
            constantEnum.ShouldEqual("1");
            constantBool.ShouldEqual("CAST(1 AS bit)");
        }
        public void TestAllTypesEntity()
        {
            //SETUP
            var logs = new List <LogOutput>();
            //var options = SqliteInMemory.CreateOptionsWithLogging<SpecializedDbContext>(log => logs.Add(log));
            var options = this.CreateUniqueClassOptionsWithLogging <SpecializedDbContext>(log => logs.Add(log));

            using (var context = new SpecializedDbContext(options))
            {
                context.Database.EnsureCreated();
                logs.Clear();

                var entity = new AllTypesEntity
                {
                    MyGuid           = Guid.NewGuid(),
                    MyDateTime       = new DateTime(2000, 1, 2),
                    MyDateTimeOffset = new DateTimeOffset(new DateTime(2004, 5, 6), new TimeSpan(1, 0, 0)),
                    MyTimeSpan       = new TimeSpan(4, 5, 6),
                    MyByteArray      = new byte[] { 1, 2, 3 }
                };
                context.Add(entity);
                context.SaveChanges();

                //ATTEMPT
                var decoded = logs.Last().DecodeMessage();

                //VERIFY
                var sqlCommand = decoded.Split('\n').Skip(1).Select(x => x.Trim()).ToArray();
                int i          = 0;
                sqlCommand[i++].ShouldEqual("SET NOCOUNT ON;");
                sqlCommand[i++].ShouldEqual("INSERT INTO [AllTypesEntities] ([MyAnsiNonNullString], [MyBool], [MyBoolNullable], [MyByteArray], [MyDateTime], [MyDateTimeNullable], [MyDateTimeOffset], [MyDecimal], [MyDouble], [MyGuid], [MyGuidNullable], [MyInt], [MyIntNullable], [MyString], [MyStringEmptyString], [MyStringNull], [MyTimeSpan])");
                //can't test for new Guid so do before and after
                sqlCommand[i].ShouldStartWith("VALUES ('ascii only', 1, NULL, '0x010203', '2000-01-02T00:00:00', NULL, '2004-05-06T00:00:00.0000000+01:00', '3456.789', '5678.9012', '");
                sqlCommand[i++].ShouldEndWith("', NULL, '1234', NULL, 'string with '' in it', NULL, NULL, '04:05:06');");
                sqlCommand[i++].ShouldEqual("SELECT [Id]");
                sqlCommand[i++].ShouldEqual("FROM [AllTypesEntities]");
                sqlCommand[i++].ShouldEqual("WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity();");
            }
        }