Exemplo n.º 1
0
        public void Field_ParseContent()
        {
            var fieldData = new Dictionary<string, string>();
            fieldData.Add("Byte", "256");
            fieldData.Add("Single", Double.MaxValue.ToString(System.Globalization.CultureInfo.InvariantCulture));
            var content = Content.CreateNewAndParse("FieldOnHandlerTest", _testRoot, "asdf", fieldData);
            Assert.IsFalse(content.IsValid);

            var sb = new StringBuilder();
            foreach (var fieldName in content.Fields.Keys)
                //if(content.Fields[fieldName].ValidationResult != null)
                sb.Append(fieldName).Append(": ").AppendLine(content.Fields[fieldName].GetValidationMessage());

            Assert.IsTrue(content.Fields["Byte"].GetValidationMessage() != "Successful");
            Assert.IsTrue(content.Fields["Single"].GetValidationMessage() != "Successful");

            var contentAcc = new ContentAccessor(content);
            contentAcc.SaveFields();
        }
Exemplo n.º 2
0
        public void FieldOnHandler_NumberOnInt32()
        {
            int originalValue;
            int currentValue;
            Int32 handlerValue;
            string fieldName = "Int32";
            int defaultValue = 0;
            int testValue = 123;
            int testIntValue = 123;
            Int32 defaultHandlerValue = 0;
            Int32 testHandlerValue = 123;

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;

            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#1");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#2");
            handlerValue = handler.Int32;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#3");

            content[fieldName] = testValue;
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#4");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#5");
            contentAcc.SaveFields();
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#6");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#7");
            handlerValue = handler.Int32;
            Assert.IsTrue(handlerValue == testHandlerValue, "#8");

            content[fieldName] = defaultValue;
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#9");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#10");
            contentAcc.SaveFields();
            originalValue = (int)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#11");
            currentValue = (int)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#12");
            handlerValue = handler.Int32;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#13");
        }
Exemplo n.º 3
0
        private ContentAccessor VersionTest(string contentTypeName)
        {
            VersionNumber originalValue;
            VersionNumber currentValue;
            string handlerValue;
            string fieldName = "VersionNumber";
            VersionNumber defaultValue = null;
            VersionNumber testValue = new VersionNumber(5, 6, VersionStatus.Draft);
            string defaultHandlerValue = (string)PropertyType.GetDefaultValue(DataType.String);
            string testHandlerValue = testValue.ToString();

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (VersionNumber)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (VersionNumber)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (string)content.ContentHandler[fieldName];
            //Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "####13: Storage2: Expected: [null], current: [empty]");

            return contentAcc;
        }
Exemplo n.º 4
0
        private ContentAccessor DatetimeTest(string contentTypeName)
        {
            DateTime originalValue;
            DateTime currentValue;
            DateTime handlerValue;
            string fieldName = "DateTime";
            DateTime defaultValue = DateTime.MinValue;
            DateTime testValue = DateTime.Parse("2008-06-04 12:34:56");
            DateTime defaultHandlerValue = defaultValue;
            DateTime testHandlerValue = testValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            handlerValue = (DateTime)content.ContentHandler[fieldName];
            Assert.IsTrue(ItIsDateTimeDefault(originalValue), contentTypeName + "####1: Storage2: DateTime default value");
            Assert.IsTrue(ItIsDateTimeDefault(currentValue), contentTypeName + "#2");
            Assert.IsTrue(ItIsDateTimeDefault(handlerValue), contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            Assert.IsTrue(ItIsDateTimeDefault(originalValue), contentTypeName + "#4");
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            handlerValue = (DateTime)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (DateTime)content.Fields[fieldName].OriginalValue;
            currentValue = (DateTime)content[fieldName];
            handlerValue = (DateTime)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 5
0
        private ContentAccessor NumberTest(string contentTypeName)
        {
            decimal originalValue;
            decimal currentValue;
            decimal handlerValue;
            string fieldName = "Number";
            decimal defaultValue = 0m;
            decimal testValue = 123m;
            decimal defaultHandlerValue = defaultValue;
            decimal testHandlerValue = testValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (decimal)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (decimal)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (decimal)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 6
0
        private ContentAccessor HyperLinkTest(string contentTypeName)
        {
            string fieldName = "HyperLink";
            HyperLinkField.HyperlinkData originalValue;
            HyperLinkField.HyperlinkData currentValue;
            HyperLinkField.HyperlinkData defaultValue = new HyperLinkField.HyperlinkData();
            HyperLinkField.HyperlinkData testValue = new HyperLinkField.HyperlinkData("testHref", "testText", "testTitle", "testTarget");
            string handlerValue;
            string defaultHandlerValue = (string)PropertyType.GetDefaultValue(DataType.String);
            string testHandlerValue = "<a href=\"testHref\" target=\"testTarget\" title=\"testTitle\">testText</a>";

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue.Href == defaultValue.Href, contentTypeName + "#1a");
            Assert.IsTrue(originalValue.Text == defaultValue.Text, contentTypeName + "#1b");
            Assert.IsTrue(originalValue.Title == defaultValue.Title, contentTypeName + "#1c");
            Assert.IsTrue(originalValue.Target == defaultValue.Target, contentTypeName + "#1d");
            Assert.IsTrue(currentValue.Href == defaultValue.Href, contentTypeName + "#2a");
            Assert.IsTrue(currentValue.Text == defaultValue.Text, contentTypeName + "#2b");
            Assert.IsTrue(currentValue.Title == defaultValue.Title, contentTypeName + "#2c");
            Assert.IsTrue(currentValue.Target == defaultValue.Target, contentTypeName + "#2d");
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            Assert.IsTrue(originalValue.Href == defaultValue.Href, contentTypeName + "#4a");
            Assert.IsTrue(originalValue.Text == defaultValue.Text, contentTypeName + "#4b");
            Assert.IsTrue(originalValue.Title == defaultValue.Title, contentTypeName + "#4c");
            Assert.IsTrue(originalValue.Target == defaultValue.Target, contentTypeName + "#4d");
            Assert.IsTrue(currentValue.Href == testValue.Href, contentTypeName + "#5a");
            Assert.IsTrue(currentValue.Text == testValue.Text, contentTypeName + "#5b");
            Assert.IsTrue(currentValue.Title == testValue.Title, contentTypeName + "#5c");
            Assert.IsTrue(currentValue.Target == testValue.Target, contentTypeName + "#5d");

            contentAcc.SaveFields();
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            Assert.IsTrue(originalValue.Href == testValue.Href, contentTypeName + "#6a");
            Assert.IsTrue(originalValue.Text == testValue.Text, contentTypeName + "#6b");
            Assert.IsTrue(originalValue.Title == testValue.Title, contentTypeName + "#6c");
            Assert.IsTrue(originalValue.Target == testValue.Target, contentTypeName + "#6d");
            Assert.IsTrue(currentValue.Href == testValue.Href, contentTypeName + "#7a");
            Assert.IsTrue(currentValue.Text == testValue.Text, contentTypeName + "#7b");
            Assert.IsTrue(currentValue.Title == testValue.Title, contentTypeName + "#7c");
            Assert.IsTrue(currentValue.Target == testValue.Target, contentTypeName + "#7d");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            Assert.IsTrue(originalValue.Href == testValue.Href, contentTypeName + "#9a");
            Assert.IsTrue(originalValue.Text == testValue.Text, contentTypeName + "#9b");
            Assert.IsTrue(originalValue.Title == testValue.Title, contentTypeName + "#9c");//renameok
            Assert.IsTrue(originalValue.Target == testValue.Target, contentTypeName + "#9d");
            Assert.IsTrue(currentValue.Href == defaultValue.Href, contentTypeName + "#10a");
            Assert.IsTrue(currentValue.Text == defaultValue.Text, contentTypeName + "#10b");
            Assert.IsTrue(currentValue.Title == defaultValue.Title, contentTypeName + "#10c");//renameok
            Assert.IsTrue(currentValue.Target == defaultValue.Target, contentTypeName + "#10d");

            contentAcc.SaveFields();
            originalValue = (HyperLinkField.HyperlinkData)content.Fields[fieldName].OriginalValue;
            currentValue = (HyperLinkField.HyperlinkData)content[fieldName];
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(originalValue.Href == defaultValue.Href, contentTypeName + "#11a");
            Assert.IsTrue(originalValue.Text == defaultValue.Text, contentTypeName + "#11b");
            Assert.IsTrue(originalValue.Title == defaultValue.Title, contentTypeName + "#11c"); //renameok
            Assert.IsTrue(originalValue.Target == defaultValue.Target, contentTypeName + "#11d");
            Assert.IsTrue(currentValue.Href == defaultValue.Href, contentTypeName + "#12a");
            Assert.IsTrue(currentValue.Text == defaultValue.Text, contentTypeName + "#12b");
            Assert.IsTrue(currentValue.Title == defaultValue.Title, contentTypeName + "#12c");//renameok
            Assert.IsTrue(currentValue.Target == defaultValue.Target, contentTypeName + "#12d");
            Assert.IsTrue(handlerValue == "<a></a>", contentTypeName + "#13");

            return contentAcc;

        }
Exemplo n.º 7
0
        private ContentAccessor BooleanTest(string contentTypeName)
        {
            bool originalValue;
            bool currentValue;
            int handlerValue;
            string fieldName = "Boolean";
            bool defaultValue = false;
            bool testValue = true;
            int defaultHandlerValue = 0;
            int testHandlerValue = 1;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (int)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (int)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (bool)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (bool)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (int)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 8
0
        private ContentAccessor WhoAndWhenTest(string contentTypeName)
        {
            WhoAndWhenField.WhoAndWhenData originalValue;
            WhoAndWhenField.WhoAndWhenData currrenValue;
            //WhoAndWhenField.WhoAndWhenData defultValue;
            //WhoAndWhenField.WhoAndWhenData testValue;
            User originalUserValue;
            User currentUserValue;
            NodeList<Node> handlerUserValue;
            DateTime originalDateValue;
            DateTime currentDateValue;
            DateTime handlerDateValue;
            string fieldName = "WhoAndWhen";
            string userPropertyName = "Who";
            string datePropertyName = "When";
            User defaultUserValue = null;
            User testUserValue = User.Administrator;
            DateTime defaultDateValue = DateTime.MinValue;
            DateTime testDateValue = new DateTime(2001, 4, 17);
            DateTime defaultHandlerDateValue = defaultDateValue;
            DateTime testHandlerDateValue = testDateValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue.Who == defaultUserValue && ItIsDateTimeDefault(originalValue.When), contentTypeName + "####1 Storage2: DateTime default value");
            //Assert.IsTrue(originalValue.Who == defaultUserValue && ((TimeSpan)(DateTime.Now - originalValue.When)).TotalMinutes < 1, contentTypeName + "####1 Storage2: DateTime default value");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            Assert.IsTrue(currrenValue.Who == defaultUserValue && ItIsDateTimeDefault(currrenValue.When), contentTypeName + "#2");
            handlerUserValue = (NodeList<Node>)content.ContentHandler[userPropertyName];
            handlerDateValue = (DateTime)content.ContentHandler[datePropertyName];
            Assert.IsTrue(handlerUserValue.Count == 0 && ItIsDateTimeDefault(handlerDateValue), contentTypeName + "#3");

            content[fieldName] = new WhoAndWhenField.WhoAndWhenData(testUserValue, testDateValue);
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue == defaultUserValue && ItIsDateTimeDefault(originalDateValue), contentTypeName + "#1");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == testUserValue && currentDateValue == testDateValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue.Id == testUserValue.Id && originalDateValue == testDateValue, contentTypeName + "#6");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == testUserValue && currentDateValue == testDateValue, contentTypeName + "#7");
            handlerUserValue = (NodeList<Node>)content.ContentHandler[userPropertyName];
            handlerDateValue = (DateTime)content.ContentHandler[datePropertyName];
            Assert.IsTrue(handlerUserValue[0].Id == User.Administrator.Id && handlerDateValue == testDateValue, contentTypeName + "#8");

            WhoAndWhenField.WhoAndWhenData defaultValue = new WhoAndWhenField.WhoAndWhenData();
            defaultValue.Who = defaultUserValue;
            defaultValue.When = DateTime.Now;
            content[fieldName] = defaultValue;
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue.Id == testUserValue.Id && originalDateValue == testDateValue, contentTypeName + "#9");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == defaultUserValue && ItIsDateTimeDefault(currentDateValue), contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (WhoAndWhenField.WhoAndWhenData)content.Fields[fieldName].OriginalValue;
            originalUserValue = originalValue.Who;
            originalDateValue = originalValue.When;
            Assert.IsTrue(originalUserValue == defaultUserValue && ItIsDateTimeDefault(originalDateValue), contentTypeName + "#11");
            currrenValue = (WhoAndWhenField.WhoAndWhenData)content[fieldName];
            currentUserValue = currrenValue.Who;
            currentDateValue = currrenValue.When;
            Assert.IsTrue(currentUserValue == defaultUserValue && ItIsDateTimeDefault(currentDateValue), contentTypeName + "#12");
            handlerUserValue = (NodeList<Node>)content.ContentHandler[userPropertyName];
            handlerDateValue = (DateTime)content.ContentHandler[datePropertyName];
            Assert.IsTrue(handlerUserValue.Count == 0, contentTypeName + "#13");
            Assert.IsTrue(ItIsDateTimeDefault(handlerDateValue), contentTypeName + "#14");

            return contentAcc;
        }
Exemplo n.º 9
0
        public void FieldOnHandler_Ref_Query()
        {
            string fieldName = "Query";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];

            List<Node> refs;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(User.Administrator);
            field.SetData(refs);
            contentAcc.SaveFields();
            Assert.IsFalse(field.IsValid, "#1");

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(ContentTypeManager.Current.GetContentTypeByName("Car"));
            field.SetData(refs);
            contentAcc.SaveFields();
            Assert.IsTrue(field.IsValid, "#2");
        }
Exemplo n.º 10
0
        private ContentAccessor LongTextTest(string contentTypeName)
        {
            string originalValue;
            string currentValue;
            string handlerValue;
            string fieldName = "LongText";
            string defaultValue = (string)PropertyType.GetDefaultValue(DataType.Text);
            string testValue = "TestValue";
            string defaultHandlerValue = defaultValue;
            string testHandlerValue = testValue;

            Content content = Content.CreateNew(contentTypeName, Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);

            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#1");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#2");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#3");

            content[fieldName] = testValue;
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#4");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#5");
            contentAcc.SaveFields();
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#6");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == testValue, contentTypeName + "#7");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == testHandlerValue, contentTypeName + "#8");

            content[fieldName] = defaultValue;
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testValue, contentTypeName + "#9");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#10");
            contentAcc.SaveFields();
            originalValue = (string)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, contentTypeName + "#11");
            currentValue = (string)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, contentTypeName + "#12");
            handlerValue = (string)content.ContentHandler[fieldName];
            Assert.IsTrue(handlerValue == defaultHandlerValue, contentTypeName + "#13");

            return contentAcc;
        }
Exemplo n.º 11
0
        public void FieldOnHandler_Ref_MultipleNull()
        {
            string fieldName = "MultipleNull";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];

            Node node0 = User.Administrator;
            Node node1 = Repository.Root;
            Node node2 = ContentTypeManager.Current.GetContentTypeByName("GenericContent");
            bool[] flags = new bool[12];

            var refs = new List<Node>();
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: empty
            flags[0] = field.IsValid;
            flags[1] = content.IsValid;
            flags[2] = handler.GeneralReference.ToList().Count == 0;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(node0);
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: node0
            flags[3] = field.IsValid;
            flags[4] = content.IsValid;
            flags[5] = handler.GeneralReference.ToList().Count == 1;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(node0);
            refs.Add(node1);
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: node0, node1
            flags[6] = field.IsValid;
            flags[7] = content.IsValid;
            flags[8] = handler.GeneralReference.ToList().Count == 2;

            handler.GeneralReference = new Node[0];
            refs = new List<Node>();
            refs.Add(node0);
            refs.Add(node1);
            refs.Add(node2);
            field.SetData(refs);
            contentAcc.SaveFields();	//-- content: node0, node1, node2
            flags[9] = field.IsValid;
            flags[10] = content.IsValid;
            flags[11] = handler.GeneralReference.ToList().Count == 3;

            string error = "";
            for (int i = 0; i < flags.Length; i++)
                if (!flags[i])
                    error = String.Concat(error, "#", i, " ");

            Assert.IsTrue(error.Length == 0, "False flags: " + error);
        }
Exemplo n.º 12
0
        public void FieldOnHandler_GeneralReference()
        {
            string fieldName = "GeneralReference";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];
            var nodeList = handler.GeneralReference.ToList();

            Assert.IsTrue(nodeList.Count == 0, "#1");

            var nodes = new List<Node>(new Node[] { User.Administrator });
            content[fieldName] = nodes;
            nodes.Add(Repository.Root);
            content[fieldName] = nodes;
            contentAcc.SaveFields();
            nodes.Add(ContentTypeManager.Current.GetContentTypeByName("GenericContent"));

            var values = handler.GeneralReference.ToList();

            Assert.IsTrue(values.Count == 2, "#2");
            Assert.IsTrue(values[0].Id == User.Administrator.Id, "#3");
            Assert.IsTrue(values[1].Id == Repository.Root.Id, "#4");
        }
Exemplo n.º 13
0
        public void FieldOnHandler_UsersReference()
        {
            string fieldName = "UsersReference";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];
            var userList = handler.UsersReference.ToList();

            Assert.IsTrue(userList.Count == 0, "#1");
            var users = new User[] { User.Administrator, User.Visitor };
            content[fieldName] = users;
            contentAcc.SaveFields();
            userList = handler.UsersReference.ToList();

            Assert.IsTrue(userList.Count == 2, "#2");
            Assert.IsTrue(userList[0].Id == User.Administrator.Id, "#3");
            Assert.IsTrue(userList[1].Id == User.Visitor.Id, "#4");
        }
Exemplo n.º 14
0
        public void FieldOnHandler_UserReference()
        {
            string fieldName = "UserReference";

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;
            ReferenceField field = (ReferenceField)content.Fields[fieldName];

            Assert.IsNull(handler.UserReference, "#1");
            content[fieldName] = User.Administrator;
            contentAcc.SaveFields();
            Assert.IsTrue(handler.UserReference.Id == User.Administrator.Id, "#2");
        }
Exemplo n.º 15
0
        public void FieldOnHandler_NumberOnUInt64()
        {
            decimal originalValue;
            decimal currentValue;
            UInt64 handlerValue;
            string fieldName = "UInt64";
            decimal defaultValue = 0;
            decimal testValue = 123.456m;
            decimal testIntValue = 123m;
            UInt64 defaultHandlerValue = 0;
            UInt64 testHandlerValue = 123;

            Content content = Content.CreateNew("FieldOnHandlerTest", Repository.Root, "FieldTest");
            ContentAccessor contentAcc = new ContentAccessor(content);
            FieldTestHandler handler = (FieldTestHandler)content.ContentHandler;

            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#1");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#2");
            handlerValue = handler.UInt64;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#3");

            content[fieldName] = testValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#4");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#5");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#6");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == testValue, "#7");
            handlerValue = handler.UInt64;
            Assert.IsTrue(handlerValue == testHandlerValue, "#8");

            content[fieldName] = defaultValue;
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == testIntValue, "#9");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#10");
            contentAcc.SaveFields();
            originalValue = (decimal)content.Fields[fieldName].OriginalValue;
            Assert.IsTrue(originalValue == defaultValue, "#11");
            currentValue = (decimal)content[fieldName];
            Assert.IsTrue(currentValue == defaultValue, "#12");
            handlerValue = handler.UInt64;
            Assert.IsTrue(handlerValue == defaultHandlerValue, "#13");
        }