예제 #1
0
        public void TestCreateOneEntrySqlServerWithLogs()
        {
            //SETUP
            var connection     = this.GetUniqueDatabaseConnectionString();
            var optionsBuilder =
                new DbContextOptionsBuilder <SimpleDbContext>();

            optionsBuilder.UseSqlServer(connection);
            var logs = new List <string>();

            using (var context = new SimpleDbContext(optionsBuilder.Options))
            {
                context.Database.EnsureCreated();
                SqliteInMemory.SetupLogging(context, logs);

                var itemToAdd = new ExampleEntity
                {
                    MyMessage = "Hello World"
                };

                //ATTEMPT
                context.SingleEntities.Add(
                    itemToAdd);
                context.SaveChanges();

                //VERIFY
                foreach (var log in logs)
                {
                    _output.WriteLine(log);
                }
            }
        }
예제 #2
0
        public void TestListBloggersAutoMapperMapperConfigDto()
        {
            //SETUP
            var config = new MapperConfiguration(cfg => { cfg.CreateMap <Mapper, Mapper>(); });

            var options = SqliteInMemory.CreateOptions <CodeDataContext>();

            using (var context = new CodeDataContext(options))
            {
                context.Database.EnsureCreated();
                context.AddRange(SetupPosts());
                context.SaveChanges();
                var logs = new List <string>();
                SqliteInMemory.SetupLogging(context, logs);

                //ATTEMPT
                var dtos = context.Bloggers
                           .ProjectTo <ListBloggersDto>(config)
                           .ToList();

                //VERIFY
                dtos.Count.ShouldEqual(2);
                dtos.Select(x => x.Name).ShouldEqual(new[] { AdaName, SherlockName });
                dtos.Select(x => x.PostsCount).ShouldEqual(new[] { 2, 1 });

                foreach (var log in logs)
                {
                    _output.WriteLine(log);
                }
            }
        }
예제 #3
0
        public void TestCreateOneEntryWithLogs()
        {
            //SETUP
            var logs = new List <string>();

            using (var context = new SimpleDbContext(
                       SqliteInMemory.CreateOptions <SimpleDbContext>()))
            {
                context.Database.EnsureCreated();
                SqliteInMemory.SetupLogging(context, logs);

                var itemToAdd = new ExampleEntity
                {
                    MyMessage = "Hello World"
                };

                //ATTEMPT
                context.SingleEntities.Add(
                    itemToAdd);
                context.SaveChanges();

                //VERIFY
                context.SingleEntities.Count()
                .ShouldEqual(1);
                foreach (var log in logs)
                {
                    _output.WriteLine(log);
                }
            }
        }