public void Verify_QueriesMethods_WorksProperly() { int setCalls = 0; var dbsetMock = new Mock <DbSet <TestEntity> >(); var dbModelMock = new Mock <EfDbModel>(); dbModelMock.Setup(x => x.Set <TestEntity>()).Returns(dbsetMock.Object); Func <string, EfDbModel> createDbContextBehaviour = (cs) => { return(dbModelMock.Object); }; var dbContext = new EfDbContext(createDbContextBehaviour); dbContext.CreateDbContext(); var queryable = dbContext.Query <TestEntity>(); setCalls++; dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls)); dbContext.Add(new TestEntity()); setCalls++; dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls)); dbsetMock.Verify(x => x.Add(It.IsAny <TestEntity>()), Times.Once()); dbContext.AddRange(new List <TestEntity>()); setCalls++; dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls)); dbsetMock.Verify(x => x.AddRange(It.IsAny <List <TestEntity> >()), Times.Once()); dbContext.Remove(new TestEntity()); setCalls++; dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls)); dbsetMock.Verify(x => x.Remove(It.IsAny <TestEntity>()), Times.Once()); dbContext.RemoveRange(new List <TestEntity>()); setCalls++; dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls)); dbsetMock.Verify(x => x.RemoveRange(It.IsAny <List <TestEntity> >()), Times.Once()); }
private void SaveRunAttributes(string projectName, int runId, IDictionary <string, string> attributes) { // Clear before if multiple CLI runners use same runId. var existing = _context.RunAttributes.Where(x => x.GlutProjectName == projectName && x.GlutProjectRunId == runId); _context.RemoveRange(existing); var items = from x in attributes select new GlutRunAttribute { GlutProjectName = projectName, GlutProjectRunId = runId, AttributeName = x.Key, AttributeValue = x.Value, CreatedDateTimeUtc = _environment.SystemDateTimeUtc, CreatedByUserName = _environment.UserName }; _context.AddRange(items); }