Пример #1
0
    void AddProfileAlias()
    {
        var alias = anyOf("алиас", "alias", "псевдоним", "погоняло", "кличку", "позывной");

        this.AddReRule(
            bot + (s + add).opt + s + alias + s + phrase("alias") + s + "для" + s + phrase("name"),
            async(request, match, cancel) =>
        {
            var to = await _dao.FindProfile(match.Value("name"), cancel);
            if (to == null)
            {
                return(Ok(await _telegram.ReplyAsync(request, "Профиль не найден", cancel)));
            }
            var name = match.Value("alias").Trim().Trim('@');
            await _dao.AddAlias(to.Id, name, cancel);
            return(Ok(await _telegram.ReplyAsync(request, "Ок", cancel)));
        });
    }
Пример #2
0
        public async Task Test()
        {
            //Attribute_ShouldBeCreated
            {
                await _dao.CreateAttribute(_attribute);

                var dst = await _dao.FindAttribute(_attribute.Name);

                dst.Id.Should().Be(_attribute.Id);
            }
            //Profile_ShouldBeCreated
            {
                await _dao.CreateProfile(_profile);

                var dst = await _dao.FindProfile(_profile.MainName);

                dst.Id.Should().Be(_profile.Id);
                dst.MainName.Should().Be(_profile.MainName);
                dst.Slivi.Should().Be(_profile.Slivi);
                dst.Loisy.Should().Be(_profile.Loisy);
                dst.Zashkvory.Should().Be(_profile.Zashkvory);
            }
            //Alias_ShouldBeAddedAndFound
            {
                const string alias = "foo";
                await _dao.AddAlias(_profile.Id, alias);

                var dst = await _dao.FindProfile(alias);

                dst.Names.Single().Should().Be(alias);
                dst.MainName.Should().Be(_profile.MainName);
                dst.Id.Should().Be(_profile.Id);
            }
            //Loisy_ShouldBeIncremented
            {
                await _dao.AddLois(_profile.Id);

                var dst = await _dao.FindProfile(_profile.MainName);

                dst.Loisy.Should().Be(_profile.Loisy + 1);
            }
            //Zashkvory_ShouldBeIncremented
            {
                await _dao.AddZashkvor(_profile.Id);

                var dst = await _dao.FindProfile(_profile.MainName);

                dst.Zashkvory.Should().Be(_profile.Zashkvory + 1);
            }
            //Slivi_ShouldBeIncremented
            {
                await _dao.AddSliv(_profile.Id);

                var dst = await _dao.FindProfile(_profile.MainName);

                dst.Slivi.Should().Be(_profile.Slivi + 1);
            }
            //AllProfiles_ShouldBeReturned
            {
                await _dao.CreateProfile(new YobaProfile
                {
                    Id = Guid.NewGuid(), MainName = "kekek"
                });

                var profiles = await _dao.GetProfiles();

                profiles.Count.Should().Be(2);
                profiles.Any(x => x.Id == _profile.Id).Should().Be(true);
            }
            //AllAttributes_ShouldBeReturned
            {
                await _dao.CreateAttribute(new YobaAttribute
                {
                    Id   = Guid.NewGuid(),
                    Name = "baz"
                });

                var attributes = await _dao.GetAttributes();

                attributes.Count.Should().Be(2);
                attributes.Any(x => x.Id == _attribute.Id).Should().Be(true);
            }
            //ProfileAttribute_ShouldBeCreatedAndListed
            {
                var profileAttribute = new YobaProfileAttribute
                {
                    AttributeId   = _attribute.Id,
                    AttributeName = _attribute.Name,
                    Value         = "peka",
                    ProfileId     = _profile.Id,
                    ProfileName   = _profile.MainName,
                };

                await _dao.SetProfileAttribute(profileAttribute);

                var dst = await _dao.FindProfile(_profile.MainName);

                dst.Attributes.Single().Value.Should().Be(profileAttribute.Value);
                var profileAttributes = await _dao.GetProfileAttributes(_attribute.Name);

                profileAttributes.Count.Should().Be(1);
                profileAttributes.Single().Value.Should().Be(profileAttribute.Value);
            }
        }
Пример #3
0
        public async Task Test()
        {
            //NewAttribute
            {
                await Handle($"ёба создай атрибут {_attribute.Name}");

                var attribute = await _dao.FindAttribute(_attribute.Name);

                attribute.Should().NotBeNull();
            }

            //NewProfile
            {
                await Handle($"ёба создай профиль {_profile.MainName}");

                var profile = await _dao.FindProfile(_profile.MainName);

                profile.Should().NotBeNull();
            }

            //AddProfileAlias
            {
                const string alias = "foo";
                await Handle($"ёба алиас {alias} для {_profile.MainName}");

                var dst = await _dao.FindProfile(alias);

                dst.Names.Single().Should().Be(alias);
                dst.MainName.Should().Be(_profile.MainName);
            }

            //AddProfileKarma
            {
                var from = "user1";
                await _dao.CreateProfile(new YobaProfile
                {
                    Id       = Guid.NewGuid(),
                    MainName = "user1",
                    CanVote  = true
                });

                var before = await _dao.FindProfile(_profile.MainName);

                // Lois from unknown user don't change karma
                var result = await Handle($"ёба лойс {_profile.MainName}");

                result.Response.Text.Should().Be("Вы не можете голосовать");
                // Lois from self to self don't change karma
                result = await Handle($"ёба лойс {from}", from);

                result.Response.Text.Should().Be("Нельзя менять карму самому себе");
                var after = await _dao.FindProfile(_profile.MainName);

                after.Loisy.Should().Be(before.Loisy);
                // Lois, sliv, Zashkvory should be incremented
                await Handle($"ёба Лойс {_profile.MainName}", from);
                await Handle($"ёба слив {_profile.MainName}", from);
                await Handle($"ёба зашквор {_profile.MainName}", from);

                after = await _dao.FindProfile(_profile.MainName);

                after.Loisy.Should().Be(before.Loisy + 1);
                after.Slivi.Should().Be(before.Slivi + 1);
                after.Zashkvory.Should().Be(before.Zashkvory + 1);
            }

            //SetProfileAttributeValue
            var attributeValue = Guid.NewGuid().ToString();
            {
                await Handle($"ёба атрибут {_attribute.Name} для {_profile.MainName} : {attributeValue}");

                var after = await _dao.FindProfile(_profile.MainName);

                after.Attributes.Single(x => x.AttributeName == _attribute.Name).Value.Should().Be(attributeValue);
            }

            //ListAttributes
            {
                var result = await Handle("ёба покажи список атрибутов");

                result.Response.Text.Should().Contain($"{_attribute.Name}");
            }

            //ShowAttributeValues
            {
                var result = await Handle($"ёба покажи атрибут {_attribute.Name}");

                result.Response.Text.Should().Contain($"{_profile.MainName}");
                result.Response.Text.Should().Contain($"{attributeValue}");
            }

            //ShowTop
            {
                var result = await Handle($"ёба покажи топ -10");

                result.Response.Text.Should().Contain($"{_profile.MainName}");
            }

            //ShowProfile
            { var result = await Handle($"ёба покажи профиль {_profile.MainName}");

              result.Response.Text.Should().Contain($"{_profile.MainName}"); }
        }