Пример #1
0
        public void FindDetailsFromEid_GetsSqlAndExecutesAsQuery()
        {
            const string sql            = "sql";
            const string path           = @"C:\Temp\MYDATABASE.db";
            var          correctSqlData = new SqlData()
            {
                Eid                  = 1,
                Relationship         = "HasValue",
                ExtendedRelationship = "ObjectType",
                Value                = "Int"
            };

            A.CallTo(() => _databaseBuilder.Build(path)).Returns(_sqLiteDatabase);
            _database.Connect(path);
            var nameValueData = new List <NameValueCollection>
            {
                new NameValueCollection()
                {
                    { "Subject", "1" },
                    { "Relationship", "HasValue" },
                    { "ExtendedRelationship", "ObjectType" },
                    { "Value", "Int" }
                },
            };

            A.CallTo(() => _sqlQueryConstructor.FindObjectDetailsFromEidQuery(A <int> .Ignored)).Returns(sql);
            A.CallTo(() => _sqLiteDatabase.ExecuteReader(sql)).Returns(nameValueData);

            var response = _database.FindObjectDetailsFromEid(1);

            response.ShouldBeEquivalentTo(new List <SqlData>()
            {
                correctSqlData
            });
        }
Пример #2
0
        public List <SqlData> FindObjectDetailsFromEid(int eid)
        {
            var sql = _sqlQueryConstructor.FindObjectDetailsFromEidQuery(eid);
            var nameValueCollections = _sqLiteDatabase.ExecuteReader(sql);
            var response             = new List <SqlData>();

            foreach (var nvc in nameValueCollections)
            {
                int subjectEid;
                int.TryParse(nvc.Get("Subject"), out subjectEid);
                response.Add(new SqlData()
                {
                    Eid                  = subjectEid,
                    Relationship         = nvc.Get("Relationship"),
                    ExtendedRelationship = nvc.Get("ExtendedRelationship"),
                    Value                = nvc.Get("Value")
                });
            }
            return(response);
        }