public void Add(string projectName, int runId, IDictionary <string, string> attributes, ThreadResult result) { if (string.IsNullOrWhiteSpace(projectName)) { throw new ArgumentNullException(nameof(projectName)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } if (runId <= 0) { runId = GetProjectLastRunId(projectName) + 1; } var items = new List <GlutResultItem>(); SaveProject(projectName); SaveRunAttributes(projectName, runId, attributes); foreach (var pair in result.Results) { for (int i = 0; i < pair.Value.IsSuccessStatusCodes.Count; i++) { var item = new GlutResultItem { GlutProjectName = projectName, GlutProjectRunId = runId, StartDateTimeUtc = pair.Value.StartDateTimes[i], EndDateTimeUtc = pair.Value.EndDateTimes[i], Url = pair.Key, IsSuccessStatusCode = pair.Value.IsSuccessStatusCodes[i], StatusCode = pair.Value.StatusCodes[i], HeaderLength = pair.Value.HeaderLengths[i], ResponseLength = pair.Value.ResponseLengths[i], TotalLength = pair.Value.HeaderLengths[i] + pair.Value.ResponseLengths[i], RequestSentTicks = pair.Value.RequestSentTicks[i], ResponseTicks = pair.Value.ResponseTicks[i], TotalTicks = pair.Value.RequestSentTicks[i] + pair.Value.ResponseTicks[i], ResponseHeaders = (pair.Value.ResponseHeaders.Count > i) ? pair.Value.ResponseHeaders[i] : null, Exception = (pair.Value.Exceptions.Count > i) ? pair.Value.Exceptions[i].ToString() : null, CreatedDateTimeUtc = _environment.SystemDateTimeUtc, CreatedByUserName = _environment.UserName }; items.Add(item); } } _context.AddRange(items); _context.SaveChanges(); }
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()); }