rksoftware

Visual Studio とか C# とかが好きです

Pleasanter のテストの準備 対象のクラスを選ぶ

Pleasanter で遊ぼう! ということで Pleasanter にテストを書いていきたいと思います。

これまでの記事で、狙うプロジェクトを決めたので、狙うクラスを狙ていきましょう。
Implem.Libraries と Implem.ParameterAccessor が狙いどころのようだったので、いくつかクラスをサンプリングしてみます。

Implem.ParameterAccessor

namespace Implem.ParameterAccessor.Parts
{
    public class User
    {
        public bool DisableTopSiteCreation;
        public bool DisableGroupAdmin;
        public bool DisableGroupCreation;
        public bool DisableMovingFromTopSite;
        public bool DisableApi;
        public SelectorToolTipKind? SelectorToolTip;
        public string Theme;

        public enum SelectorToolTipKind
        {
            LoginId,
            MailAddress
        }

        public bool IsMailAddressSelectorToolTip()
        {
            return SelectorToolTip == SelectorToolTipKind.MailAddress;
        }
    }
}
using System.Collections.Generic;
using System.ComponentModel;
namespace Implem.ParameterAccessor.Parts
{
    public class SysLog
    {
        public int RetentionPeriod { get; set; }
        public List<string> NotLoggingIp { get; set; }
        public bool LoginSuccess { get; set; }
        public bool LoginFailure { get; set; }
        public bool SignOut { get; set; }
        public bool ClientId { get; set; }
        public int ExportLimit { get; set; }
        [DefaultValue(true)]
        public bool EnableLoggingToDatabase { get; set; } = true;
        public bool EnableLoggingToFile { get; set; }
    }
}

Implem.Libraries

namespace Implem.Libraries.Utilities
{
    public static class Decimals
    {
        public static string TrimEndZero(this decimal? self)
        {
            return self.ToDecimal().TrimEndZero();
        }

        public static string TrimEndZero(this decimal self)
        {
            var data = self.ToString();
            return data.Contains(".")
                ? data.TrimEnd('0').EndsWith(".")
                    ? data.TrimEnd('0').TrimEnd('.')
                    : data.TrimEnd('0')
                : data;
        }
    }
}
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Implem.Libraries.Utilities
{
    public static class Regexes
    {
        public static string RegexFirst(
            this string self,
            string pattern,
            RegexOptions regexOptions = RegexOptions.Singleline)
        {
            foreach (Match match in self.RegexMatches(pattern, regexOptions))
            {
                return match.Value;
            }
            return string.Empty;
        }

        public static bool RegexExists(
            this string self,
            string pattern,
            RegexOptions regexOptions = RegexOptions.Singleline)
        {
            return self.RegexMatches(pattern, regexOptions).Count > 0;
        }

        public static MatchCollection RegexMatches(
            this string self,
            string pattern,
            RegexOptions regexOptions = RegexOptions.Singleline)
        {
            return Regex.Matches(self, pattern, regexOptions);
        }

        public static MatchCollection RegexLike(this string self, string pattern)
        {
            return Regex.Matches(self, Regex.Escape(pattern), RegexOptions.IgnoreCase);
        }

        public static IEnumerable<string> RegexValues(
            this string self,
            string pattern,
            RegexOptions regexOptions = RegexOptions.Singleline)
        {
            foreach (Match match in Regex.Matches(self, pattern, regexOptions))
            {
                yield return match.Value;
            }
        }
    }
}

狙う

Implem.ParameterAccessor の方は、あまりテストしがいのない感じですね。Implem.Libraries の方はいくらかテストできそうなロジックがありそうです。

というところで、次回から Decimals を狙っていってみようと思います。