public string GetResponse()
        {
            var response = new
            {
                About = compositionRoot.GetSimplePageRepository(SimplePageType.About).GetPlainContent(),
                Contacts = compositionRoot.GetSimplePageRepository(SimplePageType.Contacts).GetPlainContent()
            };

            return response.ToJSON();
        }
示例#2
0
        public ActionResult data_to_redis()
        {
            DataTable table = GetDataTable("select distinct road from   familiarrealty_f.houseinfo");

            HashSet<string> non_rep_address = new HashSet<string>();
            List<String> json_strings = new List<String>();

            ServiceStack.Redis.RedisClient redis = new ServiceStack.Redis.RedisClient();
            redis.FlushDb();

            foreach (DataRow row in table.Rows) {
                var json_result = new { road = row["road"].ToString() };
                redis.AddItemToList("road:geo", json_result.ToJSON());
                json_strings.Add(json_result.ToJSON());
                non_rep_address.Add(json_result.ToJSON());
            }

            //Response.Write(String.Format(@"non_rep_address count is {0},json_string_count is {1}",non_rep_address.Count,json_strings.Count));
            return new RenderJsonResult {
                  Result =  json_strings
            };
        }
示例#3
0
 public void ToJSON_SingleEntryList_ConformsToStandards()
 {
     string entry = String.Format("Single entry {0}.", Random.Next());
     // Should not include characters which need escaping due to last Assert.
     IEnumerable<string> list = new[] {entry};
     string json = list.ToJSON();
     Match contentsMatch = MatchListContents.Match(json);
     Assert.IsTrue(
         contentsMatch.Success,
         "The JSON representation of a list should be enclosed in square brackets. Found <{0}>.",
         json);
     Match stringMatch = MatchStringContents.Match(contentsMatch.Groups["contents"].Value);
     Assert.IsTrue(
         stringMatch.Success,
         "The JSON representation of a string should be enclosed in double quotation marks with backslash escapes. Found <{0}>.",
         json);
     Assert.AreEqual(
         entry,
         stringMatch.Groups["contents"].Value,
         "An alphanumeric value should be unchanged when encapsulated using ToJSON.");
 }
示例#4
0
        public void JSON()
        {
            var data = new {name="aaa", amount=new Amount("usd", 1234.12M)};
               var json = data.ToJSON();

               Console.WriteLine(json);

               Assert.AreEqual(@"{""amount"":{""iso"":""usd"",""v"":1234.12},""name"":""aaa""}", json);
        }
        public void AddVideoDevice_DeviceIdDoesNotExist_ValidateFailedScenario()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                var myContext = new SIMPLTestContext();
                var fakeUserDto = myContext.GetFakeUserDtoObject();
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                var context = new ShimHttpContext();
                ShimHttpContext.CurrentGet = () => context;
                var session = new ShimHttpSessionState
                {
                    ItemGetString = s =>
                    {
                        if (s == "")
                            return null;
                        return null;
                    }
                };
                ShimHttpContext.AllInstances.SessionGet = o => session;

                // current subscriber
                const string currentSubscriberId = "SUBIDWITHANYVALUE";

                // current location
                const string currentLocationId = "LOCIDWITHANYVALUE";

                // deviceId to be added
                const string deviceId = "DEVICEIDDOESNOTEXIST";

                // set location Id
                ShimCurrentSubscriber.AllInstances.LocationIdGet = o => currentLocationId;

                // set subscriber id
                ShimCurrentSubscriber.AllInstances.SubIdGet = o => currentSubscriberId;

                // set LoadEquipment for the IP device to be empty since it does not exist
                ShimRosettianClient.AllInstances.LoadEquipmentStringBooleanUserDto =
                    (myTestClient, myEquipmentId, returnExtraData, myUserDto) => new EquipmentDto();

                // expected AddVideoDevice Json result
                var expectedResult = new
                {
                    status = "error",
                    errorMessage = string.Format("Error adding device [{0}]: Activation is not allowed, device [{0}] does not exist",
                        deviceId)
                };

                // get service for ResidentialGatewayController
                var residentialController = DependencyResolver.Current.GetService<ResidentialGatewayController>();

                // call AddVideoDevice action method
                var actualResult = residentialController.AddVideoDevice(deviceId) as JsonResult;

                // validate result
                Assert.IsNotNull(actualResult, "AddVideoDevice Json result is null");
                Assert.IsTrue(actualResult != null && actualResult.Data != null);
                Assert.AreEqual(expectedResult.ToJSON(), actualResult.Data.ToJSON());
            }
        }
示例#6
0
 public void ToJSON_Backslashes_AreEscaped()
 {
     string entry = String.Format("Double escape test (\\) {0}.", Random.Next());
     IEnumerable<string> list = new[] {entry};
     string json = list.ToJSON();
     Match contentsMatch = MatchListContents.Match(json);
     Assert.IsTrue(
         contentsMatch.Success,
         "The JSON representation of a list should be enclosed in square brackets. Found <{0}>.",
         json);
     Match stringMatch = MatchQuotationContents.Match(contentsMatch.Groups["contents"].Value);
     Assert.IsTrue(
         stringMatch.Success,
         "The JSON representation of a string should be enclosed in double quotation marks with backslash escapes. Found <{0}>.",
         json);
     Assert.AreEqual(
         "\\\\",
         MatchParenthesesContents.Match(stringMatch.Groups["contents"].Value).Groups["contents"].
             Value,
         "Backslashes should be double-escaped with backslashes by ToJSON.");
 }
示例#7
0
            public void ShouldImportAttributes()
            {
                var obj = new
                    {
                        Name = "Some Page",
                        Attributes = new Dictionary<string, dynamic> { { "foobar", null } }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.IsNotNull( page.Attributes );
                Assert.IsNotEmpty( page.Attributes );
                Assert.IsNull( page.Attributes.First().Value );
            }
示例#8
0
            public void ShouldImportPagesRecursively()
            {
                const string PAGE_NAME = "Child Page";
                var obj = new
                    {
                        Name = "Grandparent Page",
                        Pages = new List<dynamic>
                            {
                                new
                                    {
                                        Name = "Parent Page",
                                        Pages = new List<dynamic> { new { Name = PAGE_NAME } }
                                    }
                            }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                var childPages = page.Pages.First().Pages;
                Assert.IsNotNull( childPages );
                Assert.IsNotEmpty( childPages );
                Assert.AreEqual( childPages.First().Name, PAGE_NAME );
            }
        public void SwapRG_SwapOldRgWithNewRgThatDoesNotExist_Failed_ValidateError()
        {
            // Data
            var sub = TestData.Data.RgTestSubWith1ActiveRg();
            Assert.IsTrue(sub.Accounts!=null && sub.Accounts.Any());

            // Swap RG Parameters
            var locId = sub.Accounts[0].Location.ID;
            var oldRgSerialNumber = sub.Accounts[0].Equipment.First().SerialNumber;
            oldRgSerialNumber = oldRgSerialNumber.Substring(0, oldRgSerialNumber.Length - 3);
            const string newRgSerialNumber = "NONEXISTRGSERIALNUMBER";

            // set current subscriber
            CurrentSubscriber.SetInstance(sub);

            // Expected Result
            var expectedErrorMesasge =
                    string.Format("Error swapping old Residential Gateway {0} with new Residential Gateway {1}: {2}",
                        oldRgSerialNumber, newRgSerialNumber, "Swap is not allowed: New residential gateway [NONEXISTRGSERIALNUMBER] does not exist");

            var expectedResult = new
                {
                    status = "error",
                    errorMessage = expectedErrorMesasge
                };

            // Call Swap RG action method
            var actualResult = RgController.SwapResidentialGateway(locId, oldRgSerialNumber, newRgSerialNumber) as JsonResult;

            // Assert
            Assert.IsTrue(actualResult!=null && actualResult.Data!=null);
            Assert.AreEqual(expectedResult.ToJSON(), actualResult.Data.ToJSON());
        }
示例#10
0
            public void ShouldImportPageContexts()
            {
                Random random = new Random();
                var id = random.Next();
                var obj = new
                    {
                        Name = "Some Page",
                        PageContexts = new List<dynamic> { new { PageId = id } }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.IsNotNull( page.PageContexts );
                Assert.IsNotEmpty( page.PageContexts );
                Assert.AreEqual( page.PageContexts.First().PageId, id );
            }
示例#11
0
            public void ShouldImportPageRoutes()
            {
                var obj = new
                    {
                        Name = "Some Page",
                        PageRoutes = new List<dynamic> { new { Route = "/some/route" } }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.IsNotNull( page.PageRoutes );
                Assert.IsNotEmpty( page.PageRoutes );
                Assert.AreEqual( page.PageRoutes.First().Route, obj.PageRoutes[0].Route );
            }
示例#12
0
            public void ShouldImportChildPages()
            {
                var obj = new
                    {
                        Name = "Parent",
                        Pages = new List<dynamic> { new { Name = "Child" } }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.IsNotNull( page.Pages );
                Assert.IsNotEmpty( page.Pages );
                Assert.AreEqual( page.Pages.First().Name, obj.Pages[0].Name );
            }
示例#13
0
            public void ShouldImportBlocks()
            {
                var obj = new
                    {
                        Name = "Some Page",
                        Blocks = new List<dynamic> { new { Name = "Some Block" } }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.IsNotNull( page.Blocks );
                Assert.IsNotEmpty( page.Blocks );
                Assert.AreEqual( page.Blocks.First().Name, obj.Blocks[0].Name );
            }
示例#14
0
            public void ShouldImportAttributeValues()
            {
                var obj = new
                    {
                        Name = "Some Page",
                        AttributeValues =
                            new Dictionary<string, List<dynamic>> { { "foobar", new List<dynamic> { new { Value = "baz" } } } }
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.IsNotNull( page.AttributeValues );
                Assert.IsNotEmpty( page.AttributeValues );
                Assert.AreEqual( page.AttributeValues.First().Value.First().Value, "baz" );
            }
示例#15
0
 public void ToJSON_ControlCharactersInList_AreEscaped()
 {
     foreach (KeyValuePair<string, string> controlChar in _controlChars)
     {
         string entry = String.Format("Control char ({1}) {0}.", Random.Next(), controlChar.Value);
         IEnumerable<string> list = new[] {entry};
         string json = list.ToJSON();
         Match contentsMatch = MatchListContents.Match(json);
         Assert.IsTrue(
             contentsMatch.Success,
             "The JSON representation of a list should be enclosed in square brackets. Found <{0}>.",
             json);
         Match stringMatch = MatchStringContents.Match(contentsMatch.Groups["contents"].Value);
         Assert.IsTrue(
             stringMatch.Success,
             "The JSON representation of a string should be enclosed in double quotation marks with backslash escapes. Found <{0}>.",
             json);
         Assert.AreEqual(
             controlChar.Key,
             MatchParenthesesContents.Match(stringMatch.Groups["contents"].Value).Groups["contents"].
                 Value,
             "Control characters should be escaped with backslashes by ToJSON.");
     }
 }
        public void AddVideoDevice_DeviceIdDoesNotExist_Failed()
        {
            // Set current subscriber
            const string subId = "SUBIDWITHANYVALUE";
            const string locId = "LOCIDWITHANYVALUE";
            var compositeSubscriber = new CompositeSubscriber
            {
                SubscriberTriad = new SubscriberDto
                {
                    ID = subId,
                    Accounts = new List<AccountDto> {new AccountDto {Location = new LocationDto {ID = locId}}}
                }
            };
            var subscriberModel = new SubscriberModel
            {
                SubDetailsModel = new SubscriberDetailsModel{USI = subId},
                SubLocationModel = new SubscriberLocationModel{LocationID = locId}
            };
            CurrentSubscriber.SetInstance(compositeSubscriber, subscriberModel);

            // DeviceId to be added
            const string deviceId = "DEVICEIDDOESNOTEXIST";

            // Expected Result
            var expectedErrorMesasge =
                string.Format("Error adding device [{0}]: Activation is not allowed, device [{0}] does not exist",
                    deviceId);

            var expectedResult = new
            {
                status = "error",
                errorMessage = expectedErrorMesasge
            };

            // Call AddVideoDevice action method
            var actualResult = RgController.AddVideoDevice(deviceId) as JsonResult;

            // Test results validation
            Assert.IsTrue(actualResult != null && actualResult.Data != null);
            Assert.AreEqual(expectedResult.ToJSON(), actualResult.Data.ToJSON());
        }
示例#17
0
 public void ToJSON_SpeechMarks_AreEscaped()
 {
     string entry = String.Format("\"Ahoy!\", said the Captain. {0}.", Random.Next());
     IEnumerable<string> list = new[] {entry};
     string json = list.ToJSON();
     Match contentsMatch = MatchListContents.Match(json);
     Assert.IsTrue(
         contentsMatch.Success,
         "The JSON representation of a list should be enclosed in square brackets. Found <{0}>.",
         json);
     Match stringMatch = MatchQuotationContents.Match(contentsMatch.Groups["contents"].Value);
     Assert.IsTrue(
         stringMatch.Success,
         "The JSON representation of a string should be enclosed in double quotation marks with backslash escapes. Found <{0}>.",
         json);
     Assert.AreEqual(
         entry.Replace("\"", "\\\""),
         stringMatch.Groups["contents"].Value,
         "Quotation marks should be escaped with backslashes by ToJSON.");
 }
        public void SwapResidentialGateway_NewRGDoesNotExist_ValidateFailedScenario()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                var myContext = new SIMPLTestContext();
                var fakeUserDto = myContext.GetFakeUserDtoObject();
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                var context = new ShimHttpContext();
                ShimHttpContext.CurrentGet = () => context;
                var session = new ShimHttpSessionState
                {
                    ItemGetString = s =>
                    {
                        if (s == "")
                            return null;
                        return null;
                    }
                };
                ShimHttpContext.AllInstances.SessionGet = o => session;

                // current location
                const string currentLocationId = "123456789";

                // Set location Id
                ShimCurrentSubscriber.AllInstances.LocationIdGet = o => currentLocationId;

                // expected all devices on current location
                var customFieldsDto = RgTestData_CustomFieldsCollection();
                var mainRg = RgTestData_MainRg(customFieldsDto, currentLocationId);

                // old RG serial number
                var oldRgSerialNumber = mainRg[0].SerialNumber;

                // new RG serial number
                const string newRgSerialNumber = "NONEXISTRGSERIALNUMBER";

                // expected ROZ error message
                var expectedRozErrorMessage =
                    string.Format("Swap is not allowed: New residential gateway [NONEXISTRGSERIALNUMBER] does not exist");

                // set ROZ SwapResidentialGateway exception
                ShimRosettianClient.AllInstances.SwapResidentialGatewayStringStringStringUserDto =
                    (myTestClient, myLocationId, myOldRgSerialNumber, myNewRgSerialNumber, myUserDto) =>
                    {
                        throw new Exception(expectedRozErrorMessage);
                    };

                // expected SwapResidentialGateway Json result
                var expectedResult = new
                {
                    status = "error",
                    errorMessage = string.Format
                    (
                        "Error swapping old Residential Gateway {0} with new Residential Gateway {1}: {2}",
                        oldRgSerialNumber, newRgSerialNumber, expectedRozErrorMessage
                    )
                };

                // get service for ResidentialGatewayController
                var residentialController = DependencyResolver.Current.GetService<ResidentialGatewayController>();

                // call SwapResidentialGateway action method
                var actualResult = residentialController.SwapResidentialGateway(currentLocationId, oldRgSerialNumber, newRgSerialNumber) as JsonResult;

                // validate result
                Assert.IsNotNull(actualResult, "SwapResidentialGateway Json result is null");
                Assert.IsTrue(actualResult != null && actualResult.Data != null);
                Assert.AreEqual(expectedResult.ToJSON(), actualResult.Data.ToJSON());
            }
        }
示例#19
0
文件: GDIDTest.cs 项目: itadapter/nfx
 public void GDID_JSON_2()
 {
     var obj = new{ id = new GDID(22, 3, 57), Name = "Tezter"};
     var s = obj.ToJSON();
     Console.WriteLine(s);
     Assert.AreEqual("{\"id\":\"22:3:57\",\"Name\":\"Tezter\"}", s);
 }
示例#20
0
            public void ShouldCopyPropertiesToEntity()
            {
                var obj = new
                    {
                        Name = "Foo Page",
                        IsSystem = true
                    };

                var json = obj.ToJSON();
                var page = new Page();
                page.ImportJson( json );
                Assert.AreEqual( obj.Name, page.Name );
                Assert.AreEqual( obj.IsSystem, page.IsSystem );
            }