상속: FieldControl, INamingContainer, ITemplateFieldControl
예제 #1
0
		public void Content_UsingFieldControls_ReadWriteWithConversion()
		{
			Node automobileNode = LoadOrCreateAutomobile(@"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='Automobile' parentType='GenericContent' handler='SenseNet.ContentRepository.Tests.ContentHandlers.AutomobileHandler' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
	<Fields>
		<Field name='Manufacturer' type='ShortText'>
			<Configuration>
				<Compulsory>true</Compulsory>
				<MaxLength>100</MaxLength>
				<Format>TitleCase</Format>
			</Configuration>
		</Field>
		<Field name='Driver' type='ShortText'>
			<Configuration>
				<Compulsory>true</Compulsory>
				<MaxLength>100</MaxLength>
			</Configuration>
		</Field>
		<Field name='BodyColor' type='Color'>
			<Bind property='BodyColor' />
		</Field>
	</Fields>
</ContentType>
", "Automobile12", "Trabant", "Netudki");
			SNC.Content automobileContent = SNC.Content.Create(automobileNode);

			automobileContent["BodyColor"] = Color.Red;
			automobileContent.Save();
			automobileContent = SNC.Content.Load(automobileContent.ContentHandler.Id);

			ColorEditorControl colorControl = new ColorEditorControl();
			ColorControlAccessor colorControlAcc = new ColorControlAccessor(colorControl);
			colorControl.FieldName = "BodyColor";
			colorControlAcc.ConnectToField(automobileContent.Fields["BodyColor"]);
			ShortText manuControl = new ShortText();
			ShortTextAccessor manuControlAcc = new ShortTextAccessor(manuControl);
			manuControl.FieldName = "Manufacturer";
			manuControlAcc.ConnectToField(automobileContent.Fields["Manufacturer"]);
			ShortText driverControl = new ShortText();
			ShortTextAccessor driverControlAcc = new ShortTextAccessor(driverControl);
			driverControl.FieldName = "Driver";
			driverControlAcc.ConnectToField(automobileContent.Fields["Driver"]);

			string colorString = colorControl.textBox1.Text;
			Color color = colorControl.textBox1.BackColor;
			string manu = manuControlAcc.Text;
			string driver = driverControlAcc.Text;
			
			Assert.IsTrue(colorString == "#FF0000", "#1");
			Assert.IsTrue(color == ColorField.ColorFromString(ColorField.ColorToString(Color.Red)), "#2");
			Assert.IsTrue(manu == "Trabant", "#2");
			Assert.IsTrue(driver == "Netudki", "#2");
			//-- Ha nincs hiba: sikeres
		}
예제 #2
0
		public void Content_UsingFieldControls_ReadComplexProperties()
		{
			Node automobileNode = CreateNewAutomobileAndSave(@"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='Automobile' parentType='GenericContent' handler='SenseNet.ContentRepository.Tests.ContentHandlers.AutomobileHandler' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
	<Fields>
		<Field name='Modified' type='WhoAndWhen'>
			<Bind property='ModifiedBy' />
			<Bind property='ModificationDate' />
		</Field>
		<Field name='Manufacturer' type='ShortText'>
			<Configuration>
				<Compulsory>true</Compulsory>
				<MaxLength>100</MaxLength>
				<Format>TitleCase</Format>
			</Configuration>
		</Field>
		<Field name='Driver' type='ShortText'>
			<Configuration>
				<Compulsory>true</Compulsory>
				<MaxLength>100</MaxLength>
			</Configuration>
		</Field>
	</Fields>
</ContentType>
", "Automobile12", "Trabant", "Netudki");
			SNC.Content automobileContent = SNC.Content.Create(automobileNode);

			WhoAndWhen whoAndWhenControl = new WhoAndWhen();
			WhoAndWhenAccessor whoAndWhenAcc = new WhoAndWhenAccessor(whoAndWhenControl);
			whoAndWhenControl.FieldName = "Modified";
			whoAndWhenAcc.ConnectToField(automobileContent.Fields["Modified"]);
			//automobileContent.Fields["Modified"].ConnectToView(whoAndWhenControl);
			ShortText manuControl = new ShortText();
			ShortTextAccessor manuControlAcc = new ShortTextAccessor(manuControl);
			manuControl.FieldName = "Manufacturer";
			manuControlAcc.ConnectToField(automobileContent.Fields["Manufacturer"]);
			//automobileContent.Fields["Manufacturer"].ConnectToView(manuControl);
			ShortText driverControl = new ShortText();
			ShortTextAccessor driverControlAcc = new ShortTextAccessor(driverControl);
			driverControl.FieldName = "Driver";
			driverControlAcc.ConnectToField(automobileContent.Fields["Driver"]);
			//automobileContent.Fields["Driver"].ConnectToView(driverControl);

			string who = whoAndWhenControl.label1.Text;
			string when = whoAndWhenControl.label2.Text;
			string manu = manuControlAcc.Text;
			string driver = driverControlAcc.Text;

			Assert.IsFalse(String.IsNullOrEmpty(who), "#1");
			Assert.IsFalse(String.IsNullOrEmpty(when), "#2");
			Assert.IsFalse(String.IsNullOrEmpty(manu), "#3");
			Assert.IsFalse(String.IsNullOrEmpty(driver), "#4");
		}
예제 #3
0
        public void XssProtection()
        {
            string data, dataDefault, dataRaw, dataText, dataHtml;

            var hackValue = "aa <b>bb</b><script>alert('XSS alert')</script>";

            var content = Content.CreateNew("Car", _testRoot, null);
            content["Make"] = hackValue;
            content["Description"] = hackValue;

            var makeControl = new ShortText();
            makeControl.SetData(hackValue);
            makeControl.Field = content.Fields["Make"];
            //data = makeControl.GetData().ToString();
            data = makeControl.Data.ToString();
            dataDefault = makeControl.GetOutputData(OutputMethod.Default);
            dataRaw = makeControl.GetOutputData(OutputMethod.Raw);
            dataText = makeControl.GetOutputData(OutputMethod.Text);
            dataHtml = makeControl.GetOutputData(OutputMethod.Html);
            Assert.IsTrue(data == dataDefault, "Shorttext's raw output is not raw");
            Assert.IsTrue(dataDefault == dataText, "Shorttext's default output is not TEXT");

            var descControl = new LongText();
            descControl.Field = content.Fields["Description"];
            descControl.SetData(hackValue);
            //data = descControl.GetData().ToString();
            data = descControl.Data.ToString();
            dataDefault = descControl.GetOutputData(OutputMethod.Default);
            dataRaw = descControl.GetOutputData(OutputMethod.Raw);
            dataText = descControl.GetOutputData(OutputMethod.Text);
            dataHtml = descControl.GetOutputData(OutputMethod.Html);
            Assert.IsTrue(data == dataDefault, "LongText's raw output is not raw");
            Assert.IsTrue(dataDefault == dataText, "LongText's default output is not TEXT");

            var richControl = new RichText();
            richControl.Field = content.Fields["Description"];
            richControl.SetData(hackValue);
            //data = richControl.GetData().ToString();
            data = richControl.Data.ToString();
            dataDefault = richControl.GetOutputData(OutputMethod.Default);
            dataRaw = richControl.GetOutputData(OutputMethod.Raw);
            dataText = richControl.GetOutputData(OutputMethod.Text);
            dataHtml = richControl.GetOutputData(OutputMethod.Html);
            Assert.IsTrue(data == dataDefault, "RichText's raw output is not raw");
            Assert.IsTrue(dataDefault == dataHtml, "RichText's default output is not HTML");
        }
예제 #4
0
		public void Content_FieldControl()
		{
			Node automobileNode = LoadOrCreateAutomobileAndSave(AutomobileHandler.ExtendedCTD, "Automobile12", "Honda", "Gyeby");
			SNC.Content automobileContent = SNC.Content.Create(automobileNode);
			Field manuField = automobileContent.Fields["Manufacturer"];
			Field drivField = automobileContent.Fields["Driver"];

			ShortText shortText = new ShortText();
			ShortTextAccessor shortTextAcc = new ShortTextAccessor(shortText);
			ShortText shortTextEditor = new ShortText();
			ShortTextAccessor shortTextEditorAcc = new ShortTextAccessor(shortTextEditor);

			//-- contentview szimulacio: RegisterFieldControl
			shortTextAcc.ConnectToField(manuField);
			shortTextEditorAcc.ConnectToField(drivField);

			Assert.IsTrue(shortTextAcc.Text == (string)automobileContent["Manufacturer"], "#01");
			Assert.IsTrue(shortTextEditorAcc.InputTextBox.Text == (string)automobileContent["Driver"], "#02");

			shortTextEditorAcc.InputTextBox.Text = "Netudki";

			//-- contentview szimulacio: PostData
			drivField.SetData(shortTextEditor.GetData());

			// automobileContent.IsValid?

			string result = (string)automobileContent["Driver"];
			Assert.IsTrue(result == "Netudki", "#03");
		}
예제 #5
0
		public void DefaultValue_Scripted_ShortText()
		{
			ContentType carType = ContentType.GetByName("Car");
			string defaultValue = "The answer to life the universe and everything plus one = [Script:jScript]WhatIsTheAnswerToLifeTheUniverseAndEverything() + 1;[/Script].";
			string evaluatedValue = "The answer to life the universe and everything plus one = 43.";
			string userInput = "-- UserInput --";
			string fieldName = null;
			string fieldValue = null;

			//==== search a testable ShortText field
			foreach (var fieldSetting in carType.FieldSettings)
			{
				ShortTextFieldSetting shortTextSetting = fieldSetting as ShortTextFieldSetting;
				if (shortTextSetting == null)
					continue;
				fieldName = shortTextSetting.Name;
				var baseSettingAccessor = new PrivateObject(shortTextSetting, new PrivateType(typeof(FieldSetting)));
				baseSettingAccessor.SetField("_defaultValue", BindingFlags.NonPublic | BindingFlags.Instance, defaultValue);
				break;
			}
			if (fieldName == null)
				Assert.Inconclusive("Car ContentType do not have any ShortText field.");

			//==== create a new Content
			var newContent = Content.CreateNew("Car", _testRoot, "Car1");
			var editedField = newContent.Fields[fieldName];

			//==== simulating contentview:
			//-- create control RegisterFieldControl, SetData, Post default value
			ShortText shortTextControl = new ShortText();
			ShortTextAccessor shortTextControlAcc = new ShortTextAccessor(shortTextControl);
			//-- RegisterFieldControl, SetData, Post default value
			shortTextControlAcc.ConnectToField(editedField);
			shortTextControlAcc.SetDataInternal();
			//-- Post default value
			editedField.SetData(shortTextControl.GetData());

			//==== Check default value
			fieldValue = (string)newContent[fieldName];
			Assert.IsTrue(fieldValue == evaluatedValue, "#1");

			//-- simulating userinput: overwrite default value
			shortTextControlAcc.InputTextBox.Text = userInput;

			//-- simulating contentview: PostData
			editedField.SetData(shortTextControl.GetData());

			//==== Check user input
			fieldValue = (string)newContent[fieldName];
			Assert.IsTrue(fieldValue == userInput, "#2");

		}