public void GetValues4A()
		{
			//This test is: RiverModel --> GWModel --> Trigger
			//Testing: Georeferenced links
			RiverModelLC riverModel = new RiverModelLC();
			GWModelLC    gWModel    = new GWModelLC();
			Trigger      trigger    = new Trigger();

			riverModel.Initialize(new Argument[0]);
			gWModel.Initialize(new Argument[0]);

			Link riverGWLink = new Link();
			riverGWLink.ID = "RiverGWLink";
			riverGWLink.SourceComponent = riverModel;
			riverGWLink.SourceElementSet = riverModel.GetOutputExchangeItem(6).ElementSet;
			riverGWLink.SourceQuantity   = riverModel.GetOutputExchangeItem(0).Quantity;
			riverGWLink.TargetComponent  = gWModel;
			riverGWLink.TargetElementSet = gWModel.GetInputExchangeItem(0).ElementSet;
			riverGWLink.TargetQuantity   = gWModel.GetInputExchangeItem(0).Quantity;

			int dataOperationIndex = -9;
			for (int i = 0; i < riverModel.GetOutputExchangeItem(6).DataOperationCount; i++)
			{
				if (riverModel.GetOutputExchangeItem(6).GetDataOperation(i).ID == "ElementMapper501")
				{
					dataOperationIndex = i;
				}
			}

			if (dataOperationIndex < 0)
			{
				throw new Exception("failed to find dataOperation");
			}
			
			riverGWLink.AddDataOperation(riverModel.GetOutputExchangeItem(6).GetDataOperation(dataOperationIndex));

			Link triggerLink = new Link();
			triggerLink.ID = "RiverGWLink";
			triggerLink.SourceComponent = gWModel;
			triggerLink.SourceElementSet = gWModel.GetOutputExchangeItem(0).ElementSet;
			triggerLink.SourceQuantity   = gWModel.GetOutputExchangeItem(0).Quantity;
			triggerLink.TargetComponent  = trigger;
			triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;
			triggerLink.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;

			riverModel.AddLink(riverGWLink);
			gWModel.AddLink(riverGWLink);
			gWModel.AddLink(triggerLink);
			trigger.AddLink(triggerLink);

			riverModel.Prepare();
			gWModel.Prepare();

			double firstTriggerGetValuesTime = riverModel.TimeHorizon.Start.ModifiedJulianDay;
			TimeStamp[] triggerTimes = new TimeStamp[2];
			triggerTimes[0] = new TimeStamp(firstTriggerGetValuesTime + 12.1);
			triggerTimes[1] = new TimeStamp(firstTriggerGetValuesTime + 16.7);
	
			trigger.Run(triggerTimes);

			double x0 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(0);
			Assert.AreEqual(0.0,x0);

			double x1 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(1);
			Assert.AreEqual(105.0/16.0,x1);

			double x2 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(2);
			Assert.AreEqual(7.5,x2);

			double x3 = ((IScalarSet)trigger.ResultsBuffer.GetValuesAt(0)).GetScalar(3);
			Assert.AreEqual(5.0+35.0/16.0,x3);

			riverModel.Finish();
			gWModel.Finish();

			riverModel.Dispose();
			gWModel.Dispose();

		}
		public void ClearState()
		{
			RiverModelLC riverModelLC = new RiverModelLC();
			Trigger trigger = new Trigger();

			riverModelLC.Initialize(new Argument[0]);

			Link triggerLink = new Link();
			triggerLink.ID = "TargetToTriggerLink";
			triggerLink.SourceComponent  = riverModelLC;
			triggerLink.SourceElementSet = riverModelLC.GetOutputExchangeItem(0).ElementSet; //last branch in the river
			triggerLink.SourceQuantity   = riverModelLC.GetOutputExchangeItem(0).Quantity;
			triggerLink.TargetComponent  = trigger;
			triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;  
			triggerLink.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;

			riverModelLC.AddLink(triggerLink);
			riverModelLC.Prepare();
			string stateID = riverModelLC.KeepCurrentState();
			Assert.AreEqual("state:1",stateID);
			Assert.AreEqual(1,riverModelLC._riverModelEngine._states.Count);
			riverModelLC.ClearState("state:1");
			Assert.AreEqual(0,riverModelLC._riverModelEngine._states.Count);
		}
		public void XEvent()
		{
			// Event Test
			// Testing : 1) That all events are actually thrown during calculations
			
			TestEngineLC  sourceModel = new TestEngineLC();
			TestEngineLC  targetModel = new TestEngineLC();
			Trigger trigger           = new Trigger();

			sourceModel.Initialize(new Argument[0]);
			targetModel.Initialize(new Argument[0]);
			trigger.Initialize(new Argument[0]);

			Link link = new Link();
			link.ID = "SourceToTargetLink";
			link.SourceComponent  = sourceModel;
			link.SourceElementSet = sourceModel.GetOutputExchangeItem(0).ElementSet; //last branch in the river
			link.SourceQuantity   = sourceModel.GetOutputExchangeItem(0).Quantity;
			link.TargetComponent  = targetModel;
			link.TargetElementSet = targetModel.GetInputExchangeItem(0).ElementSet;  //first node in the river
			link.TargetQuantity   = targetModel.GetInputExchangeItem(0).Quantity;

			Link triggerLink = new Link();
			triggerLink.ID = "TargetToTriggerLink";
			triggerLink.SourceComponent  = targetModel;
			triggerLink.SourceElementSet = targetModel.GetOutputExchangeItem(0).ElementSet; //last branch in the river
			triggerLink.SourceQuantity   = targetModel.GetOutputExchangeItem(0).Quantity;
			triggerLink.TargetComponent  = trigger;
			triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;  
			triggerLink.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;

			sourceModel.AddLink(link);
			targetModel.AddLink(link);

			targetModel.AddLink(triggerLink);
			trigger.AddLink(triggerLink);

			EventListener eventListener = new EventListener();
			eventListener._isSilent = true;

			for (int i = 0; i < eventListener.GetAcceptedEventTypeCount(); i++)
			{
				for (int n = 0; n < sourceModel.GetPublishedEventTypeCount(); n++)
				{
					if (eventListener.GetAcceptedEventType(i) == sourceModel.GetPublishedEventType(n))
					{
						sourceModel.Subscribe(eventListener, eventListener.GetAcceptedEventType(i));
					}
				}

				for (int n = 0; n < targetModel.GetPublishedEventTypeCount(); n++)
				{
					if (eventListener.GetAcceptedEventType(i) == targetModel.GetPublishedEventType(n))
					{
						targetModel.Subscribe(eventListener, eventListener.GetAcceptedEventType(i));
					}
				}
			}

			sourceModel.Prepare();
			targetModel.Prepare();
			trigger.Prepare();

			trigger.Run(new TimeStamp(sourceModel.TimeHorizon.Start.ModifiedJulianDay + 10));

			Assert.AreEqual(true , eventListener._dataChanged);   
			Assert.AreEqual(false, eventListener._globalProgress);
//			Assert.AreEqual(true , eventListener._informative);   //TODO This test was out commented, because it fails, further investigation needed
			Assert.AreEqual(false, eventListener._other);
			Assert.AreEqual(true, eventListener._sourceAfterGetValuesCall);
			Assert.AreEqual(true, eventListener._sourceBeforeGetValuesReturn);
			Assert.AreEqual(true, eventListener._targetAfterGetValuesReturn);
			Assert.AreEqual(true, eventListener._targetBeforeGetValuesCall);
			Assert.AreEqual(false, eventListener._timeStepProgres);
			Assert.AreEqual(false, eventListener._valueOutOfRange);
			Assert.AreEqual(false, eventListener._warning);
		}
		public void EarliestInputTime()
		{
			TestEngineLC testEngineLC = new TestEngineLC();
			Trigger trigger = new Trigger();

			testEngineLC.Initialize(new Argument[0]);

			Link triggerLink = new Link();
			triggerLink.ID = "TargetToTriggerLink";
			triggerLink.SourceComponent  = testEngineLC;
			triggerLink.SourceElementSet = testEngineLC.GetOutputExchangeItem(0).ElementSet; //last branch in the river
			triggerLink.SourceQuantity   = testEngineLC.GetOutputExchangeItem(0).Quantity;
			triggerLink.TargetComponent  = trigger;
			triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet;  
			triggerLink.TargetQuantity   = trigger.GetInputExchangeItem(0).Quantity;

			testEngineLC.AddLink(triggerLink);
			testEngineLC.Prepare();
			Assert.AreEqual(testEngineLC.TimeHorizon.Start,testEngineLC.EarliestInputTime);

		}