public async Task allow_to_tag_features_with_existing_tags() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature1 = Builders.Feature() .WithName("barfeatureone") .Build(); var feature2 = Builders.Feature() .WithName("barfeaturetwo") .Build(); var tag = Builders.Tag() .WithName("performance") .Build(); var featureTag = Builders.FeatureTag() .WithFeature(feature1) .WithTag(tag) .Build(); feature1.FeatureTags.Add(featureTag); product.Features.Add(feature1); product.Features.Add(feature2); await _fixture.Given.AddProduct(product); var request = new AddTagRequest("performance"); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Tags.Tag(product.Name, feature2.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task post_response_bad_request_if_try_to_duplicate_toggle() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType(typeof(EnvironmentToggle).FullName) .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var body = new AddToggleRequest() { FeatureId = feature.Id, ToggleType = typeof(EnvironmentToggle).FullName, Parameters = new List <AddToggleRequestDetailParameter>() }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Post()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(body); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task delete_response_no_content_when_delete_product_with_features_toggles_and_parameters() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("toggle-type-1") .Build(); var parameter = Builders.Parameter() .WithName("param#1") .WithValue("value#1") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.Delete(product.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task allow_to_tag_features_with_existing_tags() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature1 = Builders.Feature() .WithName("feature#1") .Build(); var feature2 = Builders.Feature() .WithName("feature#2") .Build(); var tag = Builders.Tag() .WithName("performance") .Build(); var featureTag = Builders.FeatureTag() .WithFeature(feature1) .WithTag(tag) .Build(); feature1.FeatureTags.Add(featureTag); product.Features.Add(feature1); product.Features.Add(feature2); await _fixture.Given.AddProduct(product); var request = new AddTagRequest("performance"); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Tags.Tag(feature2.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status200OK); }
public async Task knowntypes_response_ok() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.KnownTypes()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <KnownTypesToggleResponse>(); content.Toggles .Where(t => t.Assembly == (typeof(FromToToggle).Assembly.GetName().Name)) .Any().Should().BeTrue(); content.Toggles .Where(t => t.Type == (typeof(FromToToggle).ShorthandAssemblyQualifiedName())) .Any().Should().BeTrue(); content.Toggles .Where(t => t.Type == (typeof(FromToToggle).ShorthandAssemblyQualifiedName())) .Select(t => t.Description) .Single() .Should().BeEquivalentTo("Current UTC date falls within the interval."); content.Toggles .Where(t => t.Type == (typeof(FromToToggle).ShorthandAssemblyQualifiedName())) .Select(t => t.FriendlyName) .Single() .Should().BeEquivalentTo("Between dates"); content.Toggles .Where(t => t.Type == (typeof(ClaimValueToggle).ShorthandAssemblyQualifiedName())) .Select(t => t.Description) .Single() .Should().BeEquivalentTo("The identity claim of the current user exists and its value is in the list."); }
public async Task update_response_bad_request_if_product_name_is_greater_than_200() { var request = new UpdateProductRequest() { Name = new string('n', 201), Description = "description" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.Update("fooproduct")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task add_response_created_when_create_new_apikey() { var addApiKeyRequest = new AddApiKeyRequest() { Name = "apikey#1", Description = "description", }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.ApiKeys.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(addApiKeyRequest); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public async Task add_response_badrequest_if_description_is_greater_than_2000() { var addApiKeyRequest = new AddApiKeyRequest() { Name = "name", Description = new string('d', 2001) }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.ApiKeys.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(addApiKeyRequest); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public void CreateMapping <TSource, TTarget>(Action <IMappingBuilder <TSource, TTarget> > mappingFactory) { var key = new MappingKey(typeof(TSource), typeof(TTarget)); if (Builders.ContainsKey(key)) { throw new MappingAlreadyExistsException("Another mapping already exists with the supplied types"); } var builder = new MappingBuilder <TSource, TTarget>(this); mappingFactory(builder); builder.CreateDefaultBindings(); // Should be run after the explicit mappings Builders.Add(key, builder); BuilderDescriptors.Add(new BuilderDescriptor(typeof(TSource), typeof(TTarget), builder.Dependencies, true)); }
public async Task add_response_created_when_success() { var productRequest = new AddProductRequest() { Name = "product#1", Description = "some description" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(productRequest); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public async Task add_response_badrequest_if_product_name_length_is_greater_than_200() { var productRequest = new AddProductRequest() { Name = new string('c', 201), Description = "some description" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(productRequest); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public void SelectSimpleNullable() { var subq = Builders <MyModel> .Select(x => (int?)x.Id) .Where(x => x.Id == 1) .AsSubquery(); var q = Builders <MyModel2> .Select(x => x.Id) .Where(x => x.Id.PgIn(subq)); Utils.AssertRawQuery(q, @" SELECT ""id"" FROM ""public"".model2 WHERE (""id"") IN ( SELECT ""id"" FROM model WHERE (""id"") = (1) )"); }
public async Task Game(string region, [Remainder] string summonerName) { Platforms platform = (Platforms)Enum.Parse(typeof(Platforms), region.ToUpper()); var riotClient = new RiotClient(OptionManager.RiotKey); var champions = new RiotData().Champions; var summoner = riotClient.Summoner.GetSummonerByName(summonerName, platform); var match = riotClient.Specate.GameBySummoner(platform, summoner.SummonerId); var builder = Builders.BaseBuilder("", "", Color.DarkBlue, new EmbedAuthorBuilder().WithName(summonerName + "'s game"), ""); TimeSpan time = new TimeSpan(0, 0, (int)match.GameLength); builder.AddField($"Information", $"**Map: **{match.MapId}\n**Time: **{Math.Round(time.TotalMinutes,2)} minutes\n**Mode: **{match.GameMode}"); for (int i = 1; i < 3; i++) { string bans1 = ""; foreach (var matchBannedChampion in match.BannedChampions) { if (matchBannedChampion.TeamId == i * 100) { try { bans1 += champions.FirstOrDefault(x => x.ChampionId == matchBannedChampion.ChampionId).name + ", "; } catch { bans1 += "None, "; } } } bans1 = bans1.Remove(bans1.Length - 2, 2); builder.AddField("Bans Team " + i, bans1); string names = ""; string championsNames = ""; foreach (var currentGameParticipant in match.Participants.Where(x => x.TeamId == i * 100).ToList()) { names += currentGameParticipant.SummonerName + "\n"; championsNames += champions.FirstOrDefault(x => x.ChampionId == currentGameParticipant.ChampionId)?.name + "\n"; } builder.AddInlineField("Summoners", names); builder.AddInlineField("Champion", championsNames); } await ReplyAsync("", embed : builder.Build()); }
public async Task not_allow_to_tag_features_when_it_has_been_previously_tagged_with_the_same_tag() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle") .Build(); var tag = Builders.Tag() .Build(); var featureTag = Builders.FeatureTag() .WithFeature(feature) .WithTag(tag) .Build(); feature.Toggles.Add(toggle1); feature.FeatureTags.Add(featureTag); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var request = new AddTagRequest(tag.Name); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Tags.Tag(product.Name, feature.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task postparameter_response_bad_request_if_value_is_empty() { var parameterToggleRequest = new AddParameterToggleRequest() { Name = "Environment", Value = string.Empty }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.PostParameter(toggleId: 1)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public override void Initialize(IApp app) { base.Initialize(app); Builders.ForEach(b => { var iface = default(Type); if ((iface = b.Type.GetInterface(typeof(ICodeBuilder <>).FullName)) == null) { throw new ElideException("Builder '{0}' doesn't implement ICodeBuilder<> interface.", b.Type); } var arg = iface.GetGenericArguments()[0]; BuilderInstances.Add(arg, TypeCreator.New(b.Type)); }); }
public async Task get_response_bad_request_if_feature_not_exist() { var product = Builders.Product() .WithName("product#1") .Build(); await _fixture.Given.AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Get(featureId: 1)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status404NotFound); }
public async Task list_response_forbidden_if_user_is_not_authorized() { var permission = Builders.Permission() .WithReaderPermission() .Build(); await _fixture.Given .AddPermission(permission); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Permissions.List()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status401Unauthorized); }
public void InsertWithSubqueryOptional() { var subq = Builders <MyModel> .Select(x => x.Id) .Where(x => x.Name == "subtest4") .AsSubquery(); var obj = new MyModel2 { }; var q = Builders <MyModel2> .Insert(obj) .UseField(x => x.ModelId, subq); Utils.AssertRawQuery(q, @"INSERT INTO ""public"".model2(model_id) VALUES ((SELECT ""id"" FROM model WHERE (""name"") = ('subtest4'))) RETURNING ""id"";"); }
public async Task delete_response_not_found_if_specified_feature_not_exist() { var product = Builders.Product() .WithName("product#2") .Build(); await _fixture.Given.AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Delete(featureId: 1)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task postparameter_response_ok_if_toggle_exist_but_is_new_parameter() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType(typeof(EnvironmentToggle).FullName) .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var parameterToggleRequest = new AddParameterToggleRequest() { Name = "Environments", Value = "Production", }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.PostParameter(toggleId: toggle.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public void InsertWithSubquery() { var subq = Builders <MyModel> .Select(x => x.Name) .Where(x => x.Id == 1) .AsSubquery(); var obj = new MyModel2 { }; var q = Builders <MyModel2> .Insert(obj) .UseField(x => x.Name1, subq); Utils.AssertRawQuery(q, @"INSERT INTO ""public"".model2(name1) VALUES ((SELECT ""name"" FROM model WHERE (""id"") = (1))) RETURNING ""id"";"); }
public async Task reveal_response_forbidden_if_user_is_not_authorized() { var deployment = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(deployment.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.Reveal("Esquio.Toggles.EnvironmentToggle")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status403Forbidden); }
public async Task postparameter_response_badrequest_if_toggle_does_not_exist() { var parameterToggleRequest = new AddParameterToggleRequest() { Name = "Environments", Value = "Development" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.PostParameter(toggleId: 100)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task postparameter_response_forbidden_if_user_is_not_authorized() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .WithWritePermission(false) .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType(typeof(EnvironmentToggle).FullName) .Build(); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var parameterToggleRequest = new AddParameterToggleRequest() { Name = "Environments", Value = "Development", }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.PostParameter(toggleId: toggle.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status403Forbidden); }
public async Task postparameter_response_notfound_if_toggleid_is_non_positve_int() { var parameterToggleRequest = new AddParameterToggleRequest() { Name = "Environments", Value = "Development" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.PostParameter(toggleId: -1)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status404NotFound); }
public async Task get_response_not_found_if_toggle_is_not_positive_int() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Get(toggleId: -1)) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status404NotFound); }
public async Task list_response_ok_and_use_default_skip_take_values() { var apiKey1 = Builders.ApiKey() .WithName("apikey#1") .Withkey("key-1") .WithValidTo(DateTime.UtcNow.AddYears(1)) .Build(); var apiKey2 = Builders.ApiKey() .WithName("apikey#2") .Withkey("key-2") .WithValidTo(DateTime.UtcNow.AddYears(1)) .Build(); await _fixture.Given .AddApiKey(apiKey1, apiKey2); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.ApiKeys.List()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <ListApiKeyResponse>(); content.Total .Should().Be(2); content.Count .Should().Be(2); content.PageIndex .Should().Be(0); content.Result .First().Name .Should().BeEquivalentTo("apikey#1"); content.Result .Last().Name .Should().BeEquivalentTo("apikey#2"); }
public async Task Profile(string region, [Remainder] string summonerName) { var message = await ReplyAsync("Getting data..."); var riotClient = new RiotClient(OptionManager.RiotKey); Platforms platform = RiotWrapper.Helpers.PlatformHelper.StringToPlatform(region); var summoner = riotClient.Summoner.GetSummonerByName(summonerName, platform); var leagues = riotClient.League.GetPositionDto(platform, summoner.SummonerId); var masteries = riotClient.Masteries.GetchampionMasteries(platform, summoner.SummonerId); var matches = masteries = masteries.OrderByDescending(x => x.Level).ThenByDescending(x => x.ChampionPoints).ToList(); var builder = Builders.BaseBuilder("", "", Color.DarkBlue, new EmbedAuthorBuilder().WithName(summoner.Name), $"http://ddragon.leagueoflegends.com/cdn/6.24.1/img/profileicon/{summoner.ProfileIconId}.png"); builder.AddInlineField($"Information", $"**Name: **{summoner.Name}\n**Region: **region\n**Level: **{summoner.SummonerLevel}"); string rankings = ""; leagues.Reverse(); foreach (var leaguePositionDto in leagues) { rankings += $"**{RankedHelper.NormalizedQueue(leaguePositionDto.QueueType)}: **{leaguePositionDto.Tier.First().ToString().ToUpper() + leaguePositionDto.Tier.ToLower().Substring(1)} {leaguePositionDto.Rank}\n"; } if (rankings == "") { rankings = "Unranked"; } builder.AddInlineField($"Ranking", rankings); int champions = 4; if (champions > masteries.Count) { champions = masteries.Count; } builder.AddField("Top Mastery Champions", $"The top {champions} champions by mastery score"); for (int i = 0; i < champions; i++) { int id = Convert.ToInt32(masteries[i].ChampionId); var database = new RiotData(); var champion = database.Champions.FirstOrDefault(x => x.ChampionId == id); builder.AddInlineField(champion.name, $"**Level: **{masteries[i].Level}\n**Points: **{masteries[i].ChampionPoints}"); } await ReplyAsync("", embed : builder.Build()); await message.DeleteAsync(); }
public async Task list_response_ok_and_use_specific_skip_take_values() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product1 = Builders.Product() .WithName("fooproduct") .Build(); var product2 = Builders.Product() .WithName("barproduct") .Build(); await _fixture.Given .AddProduct(product1, product2); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.List(pageIndex: 1, pageCount: 1)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <PaginatedResult <ListProductResponseDetail> >(); content.Total .Should().Be(2); content.Count .Should().Be(1); content.PageIndex .Should().Be(1); content.Items .Single().Name .Should().BeEquivalentTo(product1.Name); }
public void Process(Builders.Execute.PerformDBOperationExpression expression) { Announcer.Say("Performing DB Operation"); }
/// <summary> /// Formats the database name. /// </summary> /// <param name="database"></param> /// <returns></returns> protected virtual String ParseDatabase(Builders.Database database) { return String.Format("`{0}`", database.Name); }