コード例 #1
0
        public void B_Get()
        {
            RestController api = new RestController(GetConnectionString());

            ApplicationResultRecords result1 = api.Get();

            Assert.IsTrue(result1.Success);
            Assert.IsTrue(result1.Records.Count() >= 2);

            ApplicationResultRecord result2 = api.Get(result1.Records[0].ID);

            Assert.IsTrue(result2.Success);
            Assert.IsNotNull(result2.Record);
            Assert.IsTrue(result2.Record.ID == result1.Records[0].ID);

            ApplicationResultRecords result3 = api.Get("Test", null);

            Assert.IsTrue(result3.Success);
            Assert.IsNotNull(result3.Records);
            Assert.IsTrue(result3.Records.Count() == 2);
            Assert.IsTrue(result3.Records[0].FirstName == "Test");

            ApplicationResultRecords result4 = api.Get(null, "Two");

            Assert.IsTrue(result4.Success);
            Assert.IsNotNull(result4.Records);
            Assert.IsTrue(result4.Records.Count() == 1);
            Assert.IsTrue(result4.Records[0].LastName == "Two");
        }
コード例 #2
0
ファイル: RestController.cs プロジェクト: T2Dev/AgeRanger
        public ApplicationResultRecord Get(long id)
        {
            ApplicationResultRecord result = null;

            try
            {
                Models.AgeRanger record;
                string           error = _Storage.Get(id, out record);

                if (record != null)
                {
                    result = new ApplicationResultRecord(record);
                }
                else if (string.IsNullOrEmpty(error))
                {
                    result = new ApplicationResultRecord("Record not found!");
                }
                else
                {
                    result = new ApplicationResultRecord("Fail to read record!");
                }
            }
            catch (Exception ex)
            {
                result = new ApplicationResultRecord("Fail to read record!", ex);
            }

            return(result);
        }
コード例 #3
0
        public void A_Post()
        {
            RestController api = new RestController(GetConnectionString());

            AgeRanger ar1 = new AgeRanger()
            {
                FirstName = "Test", LastName = "One", Age = 10
            };
            AgeRanger ar2 = new AgeRanger()
            {
                FirstName = "Test", LastName = "Two", Age = 20
            };

            ApplicationResultRecord result1 = api.Post(ar1);

            Assert.IsTrue(result1.Success);
            Assert.IsNotNull(result1.Record);
            Assert.IsTrue(result1.Record.ID > 0);

            ApplicationResultRecord result2 = api.Post(ar2);

            Assert.IsTrue(result2.Success);
            Assert.IsNotNull(result2.Record);
            Assert.IsTrue(result2.Record.ID > 0);
        }
コード例 #4
0
ファイル: RestController.cs プロジェクト: T2Dev/AgeRanger
        public ApplicationResultRecord Post([FromBody] AgeRanger value)
        {
            ApplicationResultRecord result = null;

            try
            {
                string error = _Storage.Save(ref value);
                if (string.IsNullOrEmpty(error))
                {
                    result = new ApplicationResultRecord(value);
                }
                else
                {
                    result = new ApplicationResultRecord(error, null);
                }
            }
            catch (Exception ex)
            {
                result = new ApplicationResultRecord("Fail to save record!", ex);
            }

            return(result);
        }