コード例 #1
0
ファイル: SQLiteTestData.cs プロジェクト: inorton/testvault
        public List<string> GetBuilds(TestProject project, TestGroup grp, DateTime? since, DateTime? until)
        {
            var rv = new List<string>();
            using (var conn = Connect())
            {
                if ((project == null) && (grp == null) && (since == null) && (until == null))
                {
                    rv = GetDistinct(conn, "BuildId");
                } else {

                    using ( var cmd = new SqliteCommand( conn ) )
                    {
                        List<string> constraints = new List<string>();
                        if ( project != null ){
                            constraints.Add( "Project = :PROJ" );
                            cmd.Parameters.Add( new SqliteParameter(":PROJ", project.Project ));
                        }

                        if ( grp != null ){
                            constraints.Add( "TestGroup = :GRP" );
                            cmd.Parameters.Add( new SqliteParameter(":GRP", grp.Name) );
                        }
                        string conds = "";
                        if ( constraints.Count > 0 )
                            conds = " WHERE " + string.Join(" AND ", constraints.ToArray() );

                        cmd.CommandText = string.Format("SELECT BuildId, Timestamp FROM results {0}", conds);

                        using ( var sth = cmd.ExecuteReader() ){

                            while ( sth.Read() ){
                                var buildid = sth.GetString(0);
                                var buildtime = sth.GetDateTime(1);
                                if ( ( since == null ) || ( buildtime > since.Value ) ){
                                    if ( ( until == null ) || ( buildtime <= until.Value ) ){
                                        rv.Add( buildid );
                                    }
                                }
                            }
                        }
                    }
                }
                rv = new List<string>( rv.Distinct() );
            }
            return rv;
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: inorton/testvault
        public void SubmitResult( HttpListenerContext ctx )
        {
            var req = ctx.Request;
            var args = QueryDictionary(ctx.Request);

            var resp = ctx.Response;
            resp.StatusCode = 500;

            var sb = new StringBuilder();

            try {
                TestResult tr;
                if ( req.HttpMethod.ToUpper().Equals("POST") ) {
                    var xsc = new XmlSerializer(typeof(TestResult));
                    tr = (TestResult)xsc.Deserialize(req.InputStream);
                } else {
                    var project = new TestProject()
                    {
                        Project = args["project"],
                        DataStore = DataStore
                    };
                    var pgroup = new TestGroup() {
                        Project = project, Name = args["group"] };
                    var build = args["buildid"];
                    var name = args["name"];
                    var date = DateTime.Now;
                    var outc = args["outcome"];
                    var sess = args["session"];
                    var outcome = (TestOutcome)Enum.Parse(typeof(TestOutcome), outc);

                    tr = new TestResult(){
                        Group = pgroup,
                        Time = date,
                        BuildID = build,
                        Name = name,
                        Outcome = outcome,
                        TestSession = sess,
                    };

                    if ( args.ContainsKey("desc") ){
                        tr.Description = args["desc"];
                    }
                    if ( args.ContainsKey("note") ){
                        tr.Notes = args["note"];
                    }
                    if ( args.ContainsKey("personal") )
                    {
                        bool pers = false;
                        bool.TryParse( args["personal"], out pers );
                        tr.IsPersonal = pers;
                    }
                }

                DataStore.Save(tr);

                sb.AppendFormat("OK");
                resp.StatusCode = 200;
            } catch ( KeyNotFoundException e ){
                sb.AppendFormat("one or more test params not specified \n: {0}", e.ToString());
            }

            var buf = Encoding.UTF8.GetBytes(sb.ToString());

            resp.OutputStream.Write(buf, 0, buf.Length);
            resp.OutputStream.Close();
        }
コード例 #3
0
ファイル: SQLiteTestData.cs プロジェクト: inorton/testvault
        public List<TestResult> GetResults(TestGroup tgroup,  string buildId)
        {
            var rv = new List<TestResult>();
            using (var conn = Connect())
            {
                using ( var cmd = new SqliteCommand( conn ) ){
                    var build = "";
                    if ( !string.IsNullOrEmpty(buildId) ){
                        build = @" AND BuildId = :BID";
                        cmd.Parameters.Add( new SqliteParameter( ":BID", buildId ) );
                    }

                    cmd.Parameters.Add( new SqliteParameter( ":PROJ", tgroup.Project.Project ) );
                    cmd.Parameters.Add( new SqliteParameter( ":GRP", tgroup.Name ) );

                    cmd.CommandText = @"SELECT
             Name,
             Outcome,
             Description,
             Notes,
             Timestamp,
             IsPersonal,
             BuildId,
             Session
            FROM results
             WHERE Project = :PROJ
             AND TestGroup = :GRP " + build + " ORDER BY Timestamp DESC";

                    using ( var sth = cmd.ExecuteReader() ){
                        while ( sth.Read() ){
                            var t = new TestResult();
                            t.Group = tgroup;
                            t.Name = sth.GetString(0);
                            t.Outcome = (TestOutcome) Enum.ToObject( typeof(TestOutcome), sth.GetInt32(1) );
                            if ( sth[2] != DBNull.Value ){

                                t.Description = sth.GetString(2);
                            }
                            if ( sth[3] != DBNull.Value )
                                t.Notes = sth.GetString(3);
                            t.Time = sth.GetDateTime(4);
                            t.IsPersonal = sth.GetBoolean(5);

                            if ( sth[6] != DBNull.Value )
                                t.BuildID = sth.GetString(6);

                            if ( sth[7] != DBNull.Value )
                                t.TestSession = sth.GetString(7);

                            rv.Add(t);
                        }
                    }
                }
            }

            return rv;
        }
コード例 #4
0
ファイル: SQLiteTestData.cs プロジェクト: inorton/testvault
 public List<TestResult> GetResults(TestGroup grp)
 {
     return GetResults( grp, null);
 }
コード例 #5
0
ファイル: SQLiteTestData.cs プロジェクト: inorton/testvault
        public List<TestGroup> GetGroups(TestProject project)
        {
            var rv = new List<TestGroup>();
            using (var conn = Connect())
            {
                using ( var cmd = new SqliteCommand( conn ) ){
                    cmd.CommandText = @"SELECT DISTINCT TestGroup FROM results WHERE Project = :PROJ ORDER BY Timestamp DESC";
                    cmd.Parameters.Add( new SqliteParameter( ":PROJ", project.Project ) );
                    using ( var sth = cmd.ExecuteReader() ){
                        while ( sth.Read() ){
                            var g = new TestGroup();
                            g.Project = project;
                            g.Name = sth.GetString(0);
                            rv.Add(g);
                        }
                    }
                }
            }

            return rv;
        }