Пример #1
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");
        }
Пример #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");
		}