public Task <List <CiCdBuildDto> > GetBuildsAsync(RepositoryDto repository, CiCdDto cicd) { var picker = new UniqueRandomPicker <string>(With.Between(1).And(FakeBuilds.Length).Elements, new UniqueRandomGenerator()); var items = picker.From(FakeBuilds); return(Task.FromResult(items.Select(x => new CiCdBuildDto { Name = x, WebUrl = $"http://ci.rbxd.ds:8090/path/to/build/{x}" }).ToList())); }
public void UniqueRandomPickerShouldBeAbleToPickFromList() { var list = Substitute.For <IList <MyClass> >(); var picker = new UniqueRandomPicker <MyClass>(constraint, uniqueRandomGenerator); var capacity = 10; var randomIndex = 3; var end = 2; list.Count.Returns(capacity); constraint.GetEnd().Returns(end); uniqueRandomGenerator.Next(0, capacity).Returns(randomIndex); list[randomIndex].Returns(new MyClass()); picker.From(list); uniqueRandomGenerator.Received().Reset(); }
public void UniqueRandomPickerShouldBeAbleToPickFromList() { var list = mocks.DynamicMock <IList <MyClass> >(); var picker = new UniqueRandomPicker <MyClass>(constraint, uniqueRandomGenerator); using (mocks.Record()) { var capacity = 10; var randomIndex = 3; var end = 2; uniqueRandomGenerator.Expect(x => x.Reset()); list.Expect(x => x.Count).Return(capacity); constraint.Expect(x => x.GetEnd()).Return(end); uniqueRandomGenerator.Expect(x => x.Next(0, capacity)).Return(randomIndex).Repeat.Times(end); list.Expect(x => x[randomIndex]).Return(new MyClass()); } picker.From(list); }
public void UniqueRandomPickerShouldBeAbleToPickFromList() { var list = mocks.DynamicMock<IList<MyClass>>(); var picker = new UniqueRandomPicker<MyClass>(constraint, uniqueRandomGenerator); using (mocks.Record()) { var capacity = 10; var randomIndex = 3; var end = 2; uniqueRandomGenerator.Expect(x => x.Reset()); list.Expect(x => x.Count).Return(capacity); constraint.Expect(x => x.GetEnd()).Return(end); uniqueRandomGenerator.Expect(x => x.Next(0, capacity)).Return(randomIndex).Repeat.Times(end); list.Expect(x => x[randomIndex]).Return(new MyClass()); } picker.From(list); }
private async Task PopulateDependencyVersionVulnerabilities() { foreach (Dependency dependency in context.Dependencies) { UniqueRandomPicker <DependencyVersion> picker = Pick <DependencyVersion> .UniqueRandomList(With.Between(0).And(dependency.Versions.Count).Elements); foreach (DependencyVersion version in picker.From(dependency.Versions.ToList())) { context.Vulnerabilities.Add(new Vulnerability { DependencyVersion = version, DependencyVersionId = version.Id, Id = Guid.NewGuid(), CheckTime = DateTime.Now, Kind = ReporterKind.OSSIndex, ResponseData = FakeResponseData, Link = $"https://ossindex.sonatype.org/component/pkg:nuget/[email protected]" }); } } await context.SaveChangesAsync(); }