public void Should_ResetIsDefault_WhenNewIsDefault() { var models = CreateDataContext().AddDataSources(5); var model = TestFactory.Create <InfluxDataSource>(); model.IsDefault = true; Assert.False(_repo .Create(model) .HasError); var list = GetRepo <DataSourceRepository>() .All .Value; var isDefaultDatasources = list .Where(x => x.IsDefault) .ToList(); Assert.Single(isDefaultDatasources); Assert.True(model.Equals(isDefaultDatasources [0])); }
public void ShouldNot_CreateTeam_WhenWrongOrgId() { var models = TestFactory.Create <ModelTeam>(5); var orgs = GetRepo <OrgRepository>().All.Value; foreach (var m in models) { Assert.True(GetRepo <TeamRepository>() .ForActiveOrg(0) .Create(m) .Error .Code == ErrorCode.BadCreateTeam); var org = TestFactory.SelectRandomObject <ModelOrg>(orgs); var res = GetRepo <TeamRepository>() .ForActiveOrg(org.Id) .Create(m); Assert.False(res.HasError); Assert.True(res.Value.Equals(m)); } }
public void Should_CreateDashboard_WhenDuplicateTitleOrUid_InVariousOrgs() { var model = TestFactory.Create <ModelDashboard>(); var res = GetRepo <DashboardRepository>().Create(model); Assert.False(res.HasError); var model2 = TestFactory.Create <ModelDashboard>(); model2.Title = model.Title; Assert.False(GetRepo <DashboardRepository>() .ForActiveOrg(2) .Create(model2) .HasError); var model3 = TestFactory.Create <ModelDashboard>(); model3.Uid = model.Uid; Assert.False(GetRepo <DashboardRepository>() .ForActiveOrg(3) .Create(model3) .HasError); var list = CreateDataContext() .Dashboards .Select(x => x.ToModel()) .ToList(); Assert.True(list.Count == 3); Assert.True(list [0].Equals(model)); Assert.True(list [1].Equals(model2)); Assert.True(list [2].Equals(model3)); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Program.ServiceProviderRoot = new ServiceCollection() .AddTransient <IMyTransientService, MyTransientService>() .AddSingleton <IMySingletonService, MySingletonService>() .AddScoped <IMyScopedService, MyScopedOtherService>() .AddScoped <IMyScopedService, MyScopedService>() .BuildServiceProvider(); while (true) { Console.WriteLine($"\r\n请输入测试用例编号:{TestFactory.Selections.AsFormatJsonStr()}"); string num = Console.ReadLine(); if (string.IsNullOrWhiteSpace(num)) { continue; } ITest test = TestFactory.Create(num); test.Run(); } }
public void Should_AddTeamMembers() { var team = _repo .Create(TestFactory.Create <ModelTeam>()) .Value; var users = CreateDataContext().AddUsers(5); users .Select(x => x.Id) .ToList() .ForEach(x => _repo.AddMember(team.Id, x)); var linkUsers = GetRepo <TeamRepository>() .GetMembers(team.Id) .Value; Assert.Equal(linkUsers.Count, users.Count); for (int i = 0; i < users.Count; ++i) { Assert.True(users [i].Equals(linkUsers [i])); } }
/// <summary> /// /// </summary> /// <param name="dc"></param> public static ModelTeams AddTeams(this DataContext dc, int count = 10) { var repo = new TeamRepository(dc); var teams = TestFactory.Create <ModelTeam>(count); var orgs = dc .Orgs .Select(x => x.ToModel()) .ToList(); foreach (var t in teams) { var o = TestFactory.SelectRandomObject <ModelOrg>(orgs); t.Name = $"{o.Name.Substring( 0, 3 )}-{t.Name}"; GetRepo <TeamRepository>(dc) .ForActiveOrg(o.Id) .Create(t); } return(teams); }
/// <summary> /// /// </summary> /// <param name="dc"></param> public static ModelFolders AddFolders(this DataContext dc, int fCount = 5) { var repo = new TeamRepository(dc); var folders = TestFactory.Create <ModelFolder>(fCount); var orgs = dc .Orgs .Select(x => x.ToModel()) .ToList(); foreach (var f in folders) { var o = TestFactory.SelectRandomObject <ModelOrg>(orgs); //t.Name = $"{o.Name.Substring( 0, 3 )}-{t.Name}"; GetRepo <FolderRepository>(dc) .ForActiveOrg(o.Id) .Create(f); } return(folders); }
private static Test <T> MuteTestFailure <T>(Test <T> test) { // Create a test that always passes using the same input. We don't care if a property passes or fails when // we're sampling the input. return(TestFactory.Create(test.Input, () => true, test.PresentedInput)); }
private static Test <T> MuteTestFailure <T>(Test <T> test) => TestFactory.Create(test.Input, () => true, test.PresentedInput);
public static Property <object[]> Nullary(Func <bool> func) => new Property <object[]>( Gen.Constant(new object[] { }).Select(x => TestFactory.Create <object[]>( x, func, x)));
Gen.Zip(gen0, gen1).Select(tuple => TestFactory.Create( tuple, () => func(tuple.Item1, tuple.Item2), new object?[] { tuple.Item1, tuple.Item2 })));
public static Property <T0> ForAll <T0>(IGen <T0> gen0, Func <T0, bool> func) => new Property <T0>( gen0.Select(x => TestFactory.Create( x, () => func(x), new object?[] { x })));