public void Bendy_CanSetAndGetLazyProperty()
        {
            // Arrange
            var bendyObject  = new BendyObject();
            var delegateTest = 0;

            // Act
            bendyObject.AddLazy("MyProperty", () => "this is my value");
            bendyObject.AddLazy("FirstDelegate", () =>
            {
                delegateTest = 1;
                return("value 1");
            });
            bendyObject.AddLazy("SecondDelegate", () =>
            {
                delegateTest = 2;
                return("value 2");
            });
            dynamic bendyDynamic = bendyObject.AsDynamic();

            // Assert
            Assert.AreEqual("this is my value", bendyDynamic.MyProperty);
            Assert.AreEqual("value 2", bendyDynamic.SecondDelegate);
            Assert.AreEqual("value 1", bendyDynamic.FirstDelegate);
            Assert.AreEqual(1, delegateTest);
        }
        public void ContentEditorControllerTests_Sort_Invalidated()
        {
            //Arrange

            var parentEntity = CreateEntityRevision(new RegexPropertyEditor());
            var subEntity1 = CreateEntityRevision(new RegexPropertyEditor());
            var subEntity2 = CreateEntityRevision(new RegexPropertyEditor());
            var subEntity3 = CreateEntityRevision(new RegexPropertyEditor());
            //setup the relations
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter<IContentStore>())
            {
                writer.Repositories.AddRelation(parentEntity.Item, subEntity1.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(parentEntity.Item, subEntity2.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(parentEntity.Item, subEntity3.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Complete();
            }

            //var controller = new ContentEditorController(GetBackOfficeRequestContext());
            var controller = new SortController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>(), GetBackOfficeRequestContext());

            //Act

            //a model not containing any of the id's or sort indexes
            var result = controller.SortForm(new SortModel());
            var model = new BendyObject(result.Data);

            //Assert

            dynamic check = model.AsDynamic();

            Assert.AreEqual("ValidationError", check.failureType);
            Assert.AreEqual("false", check.success);
        }
Beispiel #3
0
        public void Dictionary_Items_As_Properties()
        {
            var d = new Dictionary <string, string>
            {
                { "item1", "value1" },
                { "item2", "value2" },
                { "item3", "value3" },
            };
            var bendyDictionary   = new BendyObject(d);
            var dynamicDictionary = bendyDictionary.AsDynamic();

            Assert.IsNotNull(dynamicDictionary as IEnumerable);
            Assert.IsNotNull(dynamicDictionary as IEnumerable);
            Assert.AreEqual(d.Count, Enumerable.Count(dynamicDictionary));
            for (var i = 0; i < Enumerable.Count(dynamicDictionary); i++)
            {
                //first ensure that the key is a property of the Bendy object
                var keyVal = d.ElementAt(i);
                Assert.That(dynamicDictionary[keyVal.Key] == keyVal.Value);

                //next ensure that the value can be retreived from the enumerable item
                var item = Enumerable.ElementAt(dynamicDictionary, i);
                Assert.That(item.Value == keyVal.Value);
            }
        }
Beispiel #4
0
        public void Bendy_Can_Iterate_Itself_If_Enumerable()
        {
            var list = new List <string>
            {
                "item 1",
                "item 2",
                "item 3"
            };
            var bendyList   = new BendyObject(list);
            var dynamicList = bendyList.AsDynamic();

            Assert.IsNotNull(dynamicList as IEnumerable);
            Assert.AreEqual(list.Count, Enumerable.Count(dynamicList));
            for (var i = 0; i < Enumerable.Count(dynamicList); i++)
            {
                var item = Enumerable.ElementAt(dynamicList, i);
                Assert.That(list[i] == item);
            }
        }
        public void ContentEditorControllerTests_Sort_Invalidated()
        {
            //Arrange

            var parentEntity = CreateEntityRevision(new RegexPropertyEditor());
            var subEntity1   = CreateEntityRevision(new RegexPropertyEditor());
            var subEntity2   = CreateEntityRevision(new RegexPropertyEditor());
            var subEntity3   = CreateEntityRevision(new RegexPropertyEditor());

            //setup the relations
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter <IContentStore>())
            {
                writer.Repositories.AddRelation(parentEntity.Item, subEntity1.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(parentEntity.Item, subEntity2.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Repositories.AddRelation(parentEntity.Item, subEntity3.Item, FixedRelationTypes.DefaultRelationType, 0);
                writer.Complete();
            }

            //var controller = new ContentEditorController(GetBackOfficeRequestContext());
            var controller = new SortController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>(), GetBackOfficeRequestContext());

            //Act

            //a model not containing any of the id's or sort indexes
            var result = controller.SortForm(new SortModel());
            var model  = new BendyObject(result.Data);

            //Assert

            dynamic check = model.AsDynamic();

            Assert.AreEqual("ValidationError", check.failureType);
            Assert.AreEqual("false", check.success);
        }
 public PartialViewMacroModel(Content page, BendyObject macroParams)
 {
     CurrentPage = page;
     MacroParameters = macroParams.AsDynamic();
 }
 public InsertMediaModel(HiveId mediaId, string mediaFilePath, BendyObject mediaParameters)
 {
     MediaId = mediaId;
     MediaParameters = mediaParameters.AsDynamic();
     MediaFilePath = mediaFilePath;
 }
 public PartialViewMacroModel(Content page, BendyObject macroParams)
 {
     CurrentPage     = page;
     MacroParameters = macroParams.AsDynamic();
 }
 public InsertMediaModel(HiveId mediaId, string mediaFilePath, BendyObject mediaParameters)
 {
     MediaId         = mediaId;
     MediaParameters = mediaParameters.AsDynamic();
     MediaFilePath   = mediaFilePath;
 }