public async Task JsonSearch() { var scope = GetScope(); var dbContext = scope.GetDbContext(); var count = await dbContext.Sections.CountAsync(); var section = new TestSection { Id = Guid.NewGuid(), Title = "Test section 4", Url = "test4", DatePublished = DateTimeOffset.Now, IsPublished = true, SiteIds = new[] {Guid.NewGuid()}, Data = new TestSectionData {SomeNumber = 5} }; await dbContext.AddAsync(section); await dbContext.SaveChangesAsync(); var newCount = await dbContext.Sections.CountAsync(); Assert.Equal(count + 1, newCount); var search = await dbContext.Set<TestSection>().Where(s => s.Data.SomeNumber == 5).FirstOrDefaultAsync(); Assert.NotNull(search); Assert.Equal(section.Id, search.Id); }
private void SectionToJson(StringBuilder jsonBuilder, TestSection section, bool includeComma = true) { string ValueToJson(object value) => value == null ? "null" : $"\"{value}\""; jsonBuilder.AppendLine("{"); foreach (var tuple in section.Values) { jsonBuilder.AppendLine(tuple.Value.AsArray != null ? $"\"{tuple.Key}\": [{string.Join(", ", tuple.Value.AsArray.Select(ValueToJson))}]," : $"\"{tuple.Key}\": {ValueToJson(tuple.Value.AsString)},"); } foreach (var tuple in section.Sections) { jsonBuilder.Append($"\"{tuple.Key}\": "); SectionToJson(jsonBuilder, tuple.Section); } if (includeComma) { jsonBuilder.AppendLine("},"); } else { jsonBuilder.AppendLine("}"); } }
private void SectionToXml(StringBuilder xmlBuilder, string sectionName, TestSection section) { xmlBuilder.AppendLine($"<{sectionName}>"); foreach (var tuple in section.Values) { if (tuple.Value.AsString != null) { xmlBuilder.AppendLine($"<{tuple.Key}>{tuple.Value.AsString}</{tuple.Key}>"); } else { for (var i = 0; i < tuple.Value.AsArray.Length; i++) { xmlBuilder.AppendLine($"<{tuple.Key} Name=\"{i}\">{tuple.Value.AsArray[i]}</{tuple.Key}>"); } } } foreach (var tuple in section.Sections) { SectionToXml(xmlBuilder, tuple.Key, tuple.Section); } xmlBuilder.AppendLine($"</{sectionName}>"); }
public void IntegerValidatorMaxValueTest() { var section = new TestSection(); section.Load(@"<someSection><integerValidatorMaxValue theProperty=""25"" /></someSection>"); Assert.Equal(25, section.IntegerValidatorMaxValue.TheProperty); }
public IActionResult AddTask(long sectionId, [FromBody] long taskId) { TestSection section = _db.TestSections.Where(s => s.Id == sectionId) .Include(s => s.TestSectionsAndTasks).FirstOrDefault(); if (section == null) { return(NotFound($"TestSection with id={sectionId} doesn't exist")); } StpTask task = _db.Tasks.Find(taskId); if (task == null) { return(NotFound($"Task with id={taskId} doesn't exist")); } if (section.TestSectionsAndTasks.FirstOrDefault(t => t.TaskId == task.Id) != null) { return(BadRequest($"Task with id={taskId} is already present in TestSection with id={sectionId}")); } _db.TestSectionAndTasks.Add(new TestSectionAndTask() { TaskId = taskId, TaskPosition = section.TestSectionsAndTasks.Count(), TestSectionId = sectionId }); _db.SaveChanges(); return(Ok()); }
public IActionResult UpdateSectionPosition(long sectionId, [FromBody] int newPosition) { TestSection section = _db.TestSections.Find(sectionId); if (section == null) { return(NotFound($"TestSection with id={sectionId} doesn't exist")); } var sections = _db.TestSections.Where(s => s.TestId == section.TestId).ToList().OrderBy(s => s.Position); if (sections.Count() == 0) { return(NotFound($"TestSection with id={sectionId} and TestId={section.TestId} doesn't exist")); } if (newPosition > sections.Max(s => s.Position) || newPosition < sections.Min(s => s.Position)) { return(BadRequest($"New position newPosition={newPosition} is out of positions range")); } var maxPosition = Math.Max(section.Position, newPosition); var minPosition = Math.Min(section.Position, newPosition); section.Position = newPosition; int shift = newPosition == minPosition ? 1 : -1; sections.Where(s => (s.Position >= minPosition && s.Position <= maxPosition && s.Id != section.Id)) .ToList() .ForEach(c => c.Position += shift); _db.SaveChanges(); return(Ok()); }
protected override (IConfigurationProvider Provider, System.Action Initializer) LoadThroughProvider( TestSection testConfig) { var values = new List <KeyValuePair <string, string> >(); SectionToValues(testConfig, "", values); return(FromKeyVault(values), () => {}); }
public void Setup() { _testSection = TestSection.Create(); var bookmakerDetailsProviderMock = new Mock<BookmakerDetailsProvider>("bookmakerDetailsUriFormat", new TestDataFetcher(), new Deserializer<bookmaker_details>(), new BookmakerDetailsMapperFactory()); bookmakerDetailsProviderMock.Setup(x => x.GetData(It.IsAny<string>())).Returns(TestConfigurationInternal.GetBookmakerDetails()); _defaultBookmakerDetailsProvider = bookmakerDetailsProviderMock.Object; }
protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider( TestSection testConfig) { var values = new List <KeyValuePair <string, string> >(); SectionToValues(testConfig, "", values); var provider = new EnvironmentVariablesConfigurationProvider(null); return(provider, () => provider.Load(new Hashtable(values.ToDictionary(e => e.Key, e => e.Value)))); }
protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider( TestSection testConfig) { var args = new List <string>(); SectionToArgs(args, "", testConfig); var provider = new CommandLineConfigurationProvider(args); return(provider, () => { }); }
private static void Main() { Common.SetLocalException(); TestAppSettings.Create(); Console.WriteLine(TestAppSettings.Load()); TestConnectionStrings.Create(); Console.WriteLine(TestConnectionStrings.Load()); TestSection.Create(); Console.WriteLine(TestSection.Load()); Console.ReadKey(true); }
private void SectionToArgs(List <string> args, string sectionName, TestSection section) { foreach (var tuple in section.Values.SelectMany(e => e.Value.Expand(e.Key))) { args.Add($"--{sectionName}{tuple.Key}={tuple.Value}"); } foreach (var tuple in section.Sections) { SectionToArgs(args, sectionName + tuple.Key + ":", tuple.Section); } }
private void SectionToTestFiles(List <IFileInfo> testFiles, string sectionName, TestSection section) { foreach (var tuple in section.Values.SelectMany(e => e.Value.Expand(e.Key))) { testFiles.Add(new TestFile(sectionName + tuple.Key, tuple.Value)); } foreach (var tuple in section.Sections) { SectionToTestFiles(testFiles, sectionName + tuple.Key + "__", tuple.Section); } }
public static void Initialize(TestContext context) { AssemblyResolver.Initialize(); CompositionInitializer.Preload(typeof(IAsyncCloudGateway)); testSection = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).Sections[TestSection.Name] as TestSection; if (testSection == null) { throw new ConfigurationErrorsException("Test configuration missing"); } CompositionInitializer.Initialize(testSection.LibPath); }
public void BuildResult_WhenMetricNotInRange_ThrowsException() { //Given WidaTestBuilder builder = new WidaTestBuilder(new TestAssigner(), new BogusFabricator()); TestSession session = new TestSession(); TestSection section = new TestSection(); Student student = new Student(); DateTime date = DateTime.Now; //When, Then Assert.Throws <ArgumentException>(() => builder.BuildResult(section, date)); }
public void AssignSection_AddsSectionToTest() { //Given TestAssigner assigner = new TestAssigner(); Test test = new Test(); TestSection section = new TestSection(); //When assigner.AssignSection(test, section); //Then Assert.Equal(section, test.Sections[0]); Assert.Equal(test, section.Test); }
private void SectionToIni(StringBuilder iniBuilder, string sectionName, TestSection section) { foreach (var tuple in section.Values.SelectMany(e => e.Value.Expand(e.Key))) { iniBuilder.AppendLine($"{tuple.Key}={tuple.Value}"); } foreach (var tuple in section.Sections) { iniBuilder.AppendLine($"[{sectionName}{tuple.Key}]"); SectionToIni(iniBuilder, tuple.Key + ":", tuple.Section); } }
public IActionResult UpdateSectionName(long sectionId, [FromBody] string name) { TestSection section = _db.TestSections.Find(sectionId); if (section == null) { return(NotFound($"TestSection with id={sectionId} doesn't exist")); } section.Name = name; _db.SaveChanges(); return(Ok()); }
public IActionResult DeleteSection(long sectionId) { TestSection section = _db.TestSections.Find(sectionId); if (section == null) { return(NotFound($"TestSection with id={sectionId} doesn't exist")); } section.IsDeleted = true; _db.SaveChanges(); return(NoContent()); }
public async Task DiscriminatorFill() { var scope = GetScope(); var repository = scope.Get <TestSectionRepository>(); var section = new TestSection { Title = "Test type", Url = "testurl", SiteIds = new[] { CoreTestScope.SiteId } }; Assert.True(string.IsNullOrEmpty(section.Type)); var result = await repository.AddAsync(section); Assert.True(result.IsSuccess, $"Errors: {result.ErrorsString}"); Assert.Equal("testsection", section.Type); }
protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider( TestSection testConfig) { var testFiles = new List <IFileInfo>(); SectionToTestFiles(testFiles, "", testConfig); var provider = new KeyPerFileConfigurationProvider( new KeyPerFileConfigurationSource { Optional = true, FileProvider = new TestFileProvider(testFiles.ToArray()) }); return(provider, () => { }); }
public async Task SiteIdsAutoFill() { var scope = GetScope(); var repository = scope.Get <TestSectionRepository>(); var section = new TestSection { Title = "Test Section 2", Url = "test2" }; var result = await repository.AddAsync(section); Assert.True(result.IsSuccess); Assert.Single(section.SiteIds); }
protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider( TestSection testConfig) { var iniBuilder = new StringBuilder(); SectionToIni(iniBuilder, "", testConfig); var provider = new IniConfigurationProvider( new IniConfigurationSource { Optional = true }); var ini = iniBuilder.ToString(); return(provider, () => provider.Load(TestStreamHelpers.StringToStream(ini))); }
public void UpdateTest(ViewModels.TestDefinitionDetail test) { repository.Upsert(test.DeepCopyTo <TestDefinition>()); TestSection[] existingSections = repository.All <TestSection>().Where(o => o.TestID == test.ID).ToArray(); TestQuestion[] existingQuestions = repository.All <TestQuestion>().Where(o => o.TestID == test.ID).ToArray(); if (test.QuestionsSelectedRandomly) { foreach (TestSection sectionToUpdate in test.Sections) { TestSection existingItem = existingSections.FirstOrDefault(s => s.SectionID == sectionToUpdate.SectionID); if (existingItem == null) { sectionToUpdate.ID = Guid.NewGuid(); sectionToUpdate.TestID = test.ID; repository.Upsert(sectionToUpdate); } } } else { foreach (TestQuestion questionToupdate in test.Questions) { TestQuestion existingItem = existingQuestions.FirstOrDefault(s => s.QuestionID == questionToupdate.QuestionID); if (existingItem == null) { questionToupdate.ID = Guid.NewGuid(); questionToupdate.TestID = test.ID; repository.Upsert(questionToupdate); } } } foreach (TestSection item in existingSections.Where(eq => test.Sections == null || !test.Sections.Any(q => q.SectionID == eq.SectionID))) { repository.Delete(item); } foreach (TestQuestion item in existingQuestions.Where(eq => test.Questions == null || !test.Questions.Any(q => q.QuestionID == eq.QuestionID))) { repository.Delete(item); } repository.SaveChanges(); }
protected override void InitDbContext(BioContext dbContext) { var site = new Site { Id = SiteId, Title = "Test site", Url = "https://test.ru" }; dbContext.Add(site); dbContext.SaveChanges(); var section = new TestSection { Title = "Test section", Url = "test", DatePublished = DateTimeOffset.Now, IsPublished = true, SiteIds = new[] { site.Id } }; dbContext.Add(section); dbContext.SaveChanges(); var content = new TestContent { Title = "Test content", Url = "test2", DatePublished = DateTimeOffset.Now, IsPublished = true, SiteIds = new[] { site.Id }, SectionIds = new[] { section.Id } }; dbContext.Add(content); var page = new TestContent { Title = "Test page", Url = "test3", DatePublished = DateTimeOffset.Now, IsPublished = true, SiteIds = new[] { site.Id } }; dbContext.Add(page); dbContext.SaveChanges(); }
public void BuildResult_ReturnsResultWithScore(TestMetric metric, int scoreFrom, int scoreTo) { // Given WidaTestBuilder builder = new WidaTestBuilder(new TestAssigner(), new BogusFabricator()); TestSession session = new TestSession(); TestSection section = new TestSection() { Metric = metric }; Student student = new Student(); DateTime date = DateTime.Now; // When TestResult result = builder.BuildResult(section, date); // Then Assert.NotNull(result.Score); Assert.InRange(Int32.Parse(result.Score), scoreFrom, scoreTo); }
private void SectionToJson(StringBuilder jsonBuilder, TestSection section) { jsonBuilder.AppendLine("{"); foreach (var tuple in section.Values) { jsonBuilder.AppendLine(tuple.Value.AsArray != null ? $"'{tuple.Key}': [{string.Join(", ", tuple.Value.AsArray.Select(v => $"'{v}'"))}]," : $"'{tuple.Key}': '{tuple.Value.AsString}',"); } foreach (var tuple in section.Sections) { jsonBuilder.Append($"'{tuple.Key}': "); SectionToJson(jsonBuilder, tuple.Section); } jsonBuilder.AppendLine("},"); }
public void BuildResult_ReturnsPopulatedResult() { //Given WidaTestBuilder builder = new WidaTestBuilder(new TestAssigner(), new BogusFabricator()); TestSession session = new TestSession(); TestSection section = new TestSection() { Metric = TestMetric.Point0To15 }; Student student = new Student(); DateTime date = DateTime.Now; //When TestResult result = builder.BuildResult(section, date); //Then Assert.NotEqual(Guid.Empty, result.Id); Assert.Equal(section, result.Section); Assert.Equal(date, result.Date); }
private void SectionToJson(StringBuilder jsonBuilder, TestSection section) { string ValueToJson(object value) => value == null ? "null" : $"'{value}'"; jsonBuilder.AppendLine("{"); foreach (var tuple in section.Values) { jsonBuilder.AppendLine(tuple.Value.AsArray != null ? $"'{tuple.Key}': [{string.Join(", ", tuple.Value.AsArray.Select(ValueToJson))}]," : $"'{tuple.Key}': {ValueToJson(tuple.Value.AsString)},"); } foreach (var tuple in section.Sections) { jsonBuilder.Append($"'{tuple.Key}': "); SectionToJson(jsonBuilder, tuple.Section); } jsonBuilder.AppendLine("},"); }
public ActionResult <TestSectionDto> AddTestSection([FromBody] CreateTestSectionCommand cmd) { // TODO: Check presences the section in specified test TestSection testSection = new TestSection() { Name = cmd.Name, Position = cmd.Position, TestId = cmd.TestId }; _db.TestSections.Add(testSection); _db.SaveChanges(); var result = new TestSectionDto() { Id = testSection.Id, Name = testSection.Name, Position = testSection.Position, }; return(Created(nameof(AddTestSection), result)); }
public void IntegerValidatorMaxValueTest () { var section = new TestSection (); section.Load (@"<someSection><integerValidatorMaxValue theProperty=""25"" /></someSection>"); Assert.AreEqual (25, section.IntegerValidatorMaxValue.TheProperty); }