示例#1
0
        private IServiceTest Verify()
        {
            using (var context = new CatSharpContext(base.Options))
            {
                Assert.True(context.Cats.Any(x => x.Name.Equals("Cat B")));
                Assert.False(context.Cats.Any(x => x.Name.Equals("Cat 1")));
            }

            return(this);
        }
示例#2
0
        private IServiceTest Verify()
        {
            using (var context = new CatSharpContext(base.Options))
            {
                Assert.Equal(1, context.Cats.Count());
                Assert.Equal("Cat 1", context.Cats.Single().Name);
            }

            return(this);
        }
示例#3
0
        private IServiceTest Execute()
        {
            using (var context = new CatSharpContext(base.Options))
            {
                var service = new CatService(context);
                service.Create(new CatCreateDto("Cat 1", new DateTime(2018, 01, 01), null));
            }

            return(this);
        }
示例#4
0
        private IServiceTest Execute()
        {
            using (var context = new CatSharpContext(base.Options))
            {
                var service = new CatService(context);
                base.Result = service.GetAll();
            }

            return(this);
        }
示例#5
0
        private IServiceTest SeedData()
        {
            using (var context = new CatSharpContext(base.Options))
            {
                context.Cats.Add(new Cat()
                {
                    Name = "Cat 1"
                });
                context.SaveChanges();
            }

            return(this);
        }
示例#6
0
        public virtual IServiceTest Start()
        {
            Connection = new SqliteConnection("DataSource=:memory:");
            Connection.Open();

            Options = new DbContextOptionsBuilder <CatSharpContext>().UseSqlite(Connection).Options;

            // Create the schema in the database
            using (var context = new CatSharpContext(Options))
            {
                context.Database.EnsureCreated();
            }

            return(this);
        }
示例#7
0
        private IServiceTest Execute()
        {
            using (var context = new CatSharpContext(base.Options))
            {
                // Get the cat created
                var cat = context.Cats.AsNoTracking().Single(x => x.Name.Equals("Cat 1"));
                // Simulate the return value as CatGetDto
                var oldDto = cat.ToDto();
                // Create the new CatUpdateDto with the date to be updated
                var newDto = new CatUpdateDto(oldDto.Id, "Cat B", oldDto.BirthDate, oldDto.Weights);
                // Update
                var service = new CatService(context);
                service.Update(newDto);
            }

            return(this);
        }
示例#8
0
 public CatService(CatSharpContext context)
 {
     _context = context;
     _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 }