Пример #1
0
        public async void A_widget_is_instantiated_from_json_and_type_info_strings()
        {
            // Given a widget in the area blog sidebar1
            var widgetId = await _svc.CreateWidgetAsync(MY_WIDGET_FOLDER);

            await _svc.AddWidgetToAreaAsync(widgetId, WidgetService.BlogSidebar1.Id, 0);

            // When the meta record is retrieved
            var widgetMeta = await _metaRepo.GetAsync(widgetId);

            // I'm able to get the widget folder
            var widget = (Widget)JsonConvert.DeserializeObject(widgetMeta.Value, typeof(Widget));

            Assert.Equal(MY_WIDGET_FOLDER, widget.Folder);

            // Given a json string that represent an instance of MyWidget
            string json = @"{""age"":10,""title"":""Tags"",""id"":0, ""folder"":""MyWidget""}";
            // And the widget type I got from above
            var type = await _svc.GetManifestTypeByFolderAsync(widget.Folder);

            // When I deserialize it
            var myWidget = (MyWidget)JsonConvert.DeserializeObject(json, type);

            // Then we get the actual instance
            Assert.Equal(10, myWidget.Age);
        }