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); } } }
private static void LoadAborigens() { using (var context = new SimpleDbContext <AborigenModel>()) { aborigens.AddRange(context.Objects.ToList()); } }
public void TestCreateOneEntryWithLogs() { //SETUP var showLog = false; var options = SqliteInMemory.CreateOptionsWithLogging <SimpleDbContext>(log => { if (showLog) { _output.WriteLine(log.DecodeMessage()); } }); using (var context = new SimpleDbContext(options)) { context.Database.EnsureCreated(); showLog = true; var itemToAdd = new ExampleEntity { MyMessage = "Hello World" }; //ATTEMPT context.SingleEntities.Add( itemToAdd); context.SaveChanges(); //VERIFY context.SingleEntities.Count().ShouldEqual(1); } }
public static void SaveOrUpdateOwnRelation(string aborigenId, int flatNumber) { lock (Locker) { FlatsProvider.VerifyFlatNumber(flatNumber); LoadRelations(); OwnRelationModel ownRelationModel = ownRelations.FirstOrDefault(relation => relation.OwnerId == aborigenId); if (ownRelationModel != null) { ownRelationModel.FlatNumber = flatNumber; } else { ownRelations.Add(new OwnRelationModel { FlatNumber = flatNumber, OwnerId = aborigenId }); } using (var context = new SimpleDbContext <OwnRelationModel>()) { context.Objects.RemoveRange(context.Objects); context.Objects.AddRange(ownRelations); context.SaveChanges(); } } }
public void TestCreateOneEntry() { //SETUP var options = SqliteInMemory.CreateOptions <SimpleDbContext>(); using (var context = new SimpleDbContext(options)) { context.Database.EnsureCreated(); var itemToAdd = new ExampleEntity { MyMessage = "Hello World" }; //ATTEMPT context.Add(itemToAdd); //#A context.SaveChanges(); //#B /********************************************************* #A It use the Add method to add the SingleEntity to the application's DbContext. The DbContext works what table to add it to based on its type of its parameter #B It calls the SaveChanges() method from the application's DbContext to update the database * ***********************************************************/ //VERIFY context.SingleEntities.Count() .ShouldEqual(1); itemToAdd.ExampleEntityId .ShouldNotEqual(0); } }
private static void Seed(SimpleDbContext context) { context.Categories.AddRange(new Domain.Entities.Category[] { new Domain.Entities.Category() { CategoryId = 1, Title = "Non-empty Category" }, new Domain.Entities.Category() { CategoryId = 2, Title = "Empty Category" }, }); context.Topics.AddRange(new Domain.Entities.Topic[] { new Domain.Entities.Topic() { CategoryId = 1, TopicId = 1, Title = "Non-empty Topic" }, new Domain.Entities.Topic() { CategoryId = 1, TopicId = 2, Title = "Empty Topic" }, }); context.Contents.AddRange(new Domain.Entities.Content[] { new Domain.Entities.Content() { TopicId = 1, ContentId = 1, Title = "Content One" }, }); context.SaveChanges(); }
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); } } }
public static void SaveOrUpdateAborigen(AborigenModel aborigen) { lock (Locker) { using (var context = new SimpleDbContext <AborigenModel>()) { var existingAborigen = context.Objects.FirstOrDefault(abo => abo.Id == aborigen.Id); if (existingAborigen != null) { existingAborigen.AcceptProps(aborigen); } else { context.Objects.Add(aborigen); } context.SaveChanges(); var cachedAborigen = aborigens.FirstOrDefault(abo => abo.Id == aborigen.Id); if (cachedAborigen != null) { cachedAborigen.AcceptProps(aborigen); EventAborigenChanged(aborigen); } else { aborigens.Add(aborigen); EventAborigenAdded(aborigen); } } } }
private static void LoadBookRelations() { using (var bookContext = new SimpleDbContext <OwnRelationModel>()) { bookRelations.AddRange(bookContext.Objects.ToList()); } }
public ShopService(SimpleDbContext dbContext, IPublicProfileService users, ITagService tags, IActivityStreamRepository activityStreams, IReactionService reactions, IObjectReferenceService handles) { _dbContext = dbContext; _users = users; _tags = tags; _activityStreams = activityStreams; _handles = handles; }
public SystemController(IAuthService auth, SimpleDbContext db, IPeerService peers, IApiDescriptionGroupCollectionProvider apiExplorer, IActivityStreamRepository activityStreams) { _auth = auth; _db = db; _peers = peers; _apiExplorer = apiExplorer; _activityStreams = activityStreams; }
private static void LoadOwnRelations() { using (var ownContext = new SimpleDbContext <OwnRelationModel>()) { //System.Threading.Thread.Sleep(int.MaxValue); ownRelations.AddRange(ownContext.Objects.ToList()); } }
public async Task <IEnumerable <T> > GetAllSnippets() { using (SimpleDbContext db = new SimpleDbContext()) { IEnumerable <T> entities = await db.Set <T>().ToListAsync(); return(entities); } }
public async Task <IEnumerable <T> > GetSnippet(string filter) { using (SimpleDbContext db = new SimpleDbContext()) { IEnumerable <T> entities = await db.Set <T>().Where(x => x.Title.Contains(filter)).ToListAsync(); return(entities); } }
public SqlSearchProfilesService(UserManager <UserProfileModel> userManager, IUserProfileService profiles, IPublicProfileService publicProfiles, SimpleDbContext dbContext) { _userManager = userManager; _profiles = profiles; _publicProfiles = publicProfiles; _dbContext = dbContext; }
public BindSqlReferencesToActivityStreamWhenReading( RedisRepository redis, StringRepository strings, SimpleDbContext db, IActivityStreamContentRepository contentRepository) { _redis = redis; _strings = strings; _db = db; _contentRepository = contentRepository; }
public async Task <T> CreateSnippet(T entity) { using (SimpleDbContext db = new SimpleDbContext()) { EntityEntry <T> createdResult = await db.Set <T>().AddAsync(entity); await db.SaveChangesAsync(); return(createdResult.Entity); } }
public IdentityController(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, SimpleDbContext context, ILogger <IdentityController> logger) { _context = context; this.userManager = userManager; this.signInManager = signInManager; _logger = logger; }
public async Task <bool> DeleteSnippet(int id) { using (SimpleDbContext db = new SimpleDbContext()) { T entity = await db.Set <T>().FirstOrDefaultAsync((e) => e.Id == id); db.Set <T>().Remove(entity); await db.SaveChangesAsync(); return(true); } }
public async Task <T> UpdateSnippet(int id, T entity) { using (SimpleDbContext db = new SimpleDbContext()) { entity.Id = id; db.Set <T>().Update(entity); await db.SaveChangesAsync(); return(entity); } }
public static SimpleDbContext Create() { var options = new DbContextOptionsBuilder <SimpleDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new SimpleDbContext(options); context.Database.EnsureCreated(); Seed(context); return(context); }
public UserProfileService( UserManager <UserProfileModel> userManager, SignInManager <UserProfileModel> signInManager, RoleManager <UserGroupModel> roleManager, SimpleDbContext dbContext, StringRepository strings ) { _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _dbContext = dbContext; _strings = strings; }
public void Simple_GroupByCategory() { var options = new DbContextOptionsBuilder <SimpleDbContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; // Run the test against one instance of the context using (var dc = new SimpleDbContext(options)) { var entities = new[] { new SimpleEntity { Name = "Bir", Category = "Bir" }, new SimpleEntity { Name = "İki", Category = "Bir" }, new SimpleEntity { Name = "Üç", Category = "Bir" }, new SimpleEntity { Name = "Dört", Category = "Bir" }, new SimpleEntity { Name = "Beş", Category = "Bir" }, new SimpleEntity { Name = "On Bir", Category = "İki" }, new SimpleEntity { Name = "On İki", Category = "İki" }, new SimpleEntity { Name = "On Üç", Category = "İki" }, new SimpleEntity { Name = "On Dört", Category = "İki" }, new SimpleEntity { Name = "On Beş", Category = "İki" } }; dc.Simples.AddRange(entities); dc.SaveChanges(); var gp = dc.Simples.GroupBy(x => x.Category).ToList(); gp.ShouldNotBeNull(); gp.Count.ShouldBeGreaterThan(0); } }
public async Task Ensure_we_can_deleteAndSave() { var name = Guid.NewGuid().ToString("N"); var email = $"{name}@test.com"; var item = new User { Email = email, Name = name }; SimpleDbContext.Users.Add(item); await SimpleDbContext.SaveChangesAsync(); SimpleDbContext.Users.Any(t => t.Email == email).ShouldBe(true); Sut.DeleteAndSave(item); SimpleDbContext.Users.Any(t => t.Email == email).ShouldBe(false); }
private List <User> WhatWeShouldHave() { var users = Enumerable.Range(1, 10).Select(f => Guid.NewGuid().ToString("N")) .Select(f => new User { Name = f, Email = $"{f}@gmail.com", Posts = new List <Post>() { new Post { CreatedAt = DateTime.Now, Text = f + " Text" } } }).ToList(); SimpleDbContext.Users.AddRange(users); SimpleDbContext.SaveChanges(); return(users); }
public ArchiveService(SimpleDbContext dbContext, IUserProfileService users, IPostService posts, IWebHostEnvironment env, ISettingsService settings) { _dbContext = dbContext; _users = users; _posts = posts; _env = env; _settings = settings; var path = _env.ContentRootPath + "/Upload/Archive"; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } }
public async Task Ensure_we_can_GetFirst() { var name = Guid.NewGuid().ToString("N"); var email = $"{name}@test.com"; var item = new User { Email = email, Name = name }; SimpleDbContext.Users.Add(item); await SimpleDbContext.SaveChangesAsync(); SimpleDbContext.Users.Any(t => t.Email == email).ShouldBe(true); var item2 = await Sut.GetFirst <User>(f => f.Email == email); item2.ShouldNotBeNull(); item2.Email.ShouldBe(item.Email); item2.Name.ShouldBe(item.Name); item2.Id.ShouldBe(item.Id); }
public GetTopicsListQueryTests(QueryTestFixture fixture) { _context = fixture.Context; _mapper = fixture.Mapper; }
public MultiModel(SimpleDbContext dbContext) { _dbContext = dbContext; }
public AboutResturantsController(SimpleDbContext context) { _context = context; }