public void execute()
        {
            var target     = new Target();
            var method     = ReflectionHelper.GetMethod <Target>(x => x.Go(null, 0, 0));
            var invocation = new MethodInvocation(method, target);

            var values = new StepValues(method.Name);

            values.Store("name", "Jeremy");
            values.Store("age", 41);
            values.Store("percentAwake", 50.1);

            invocation.Invoke(values).ToArray();

            target.Name.ShouldBe("Jeremy");
            target.Age.ShouldBe(41);
            target.PercentAwake.ShouldBe(50.1);
        }
        public void invoke_with_return_value()
        {
            var target = new Target();
            var method = ReflectionHelper.GetMethod <Target>(x => x.Fullname(null, null, null));

            var values = new StepValues(method.Name);

            values.Store("first", "Jeremy");
            values.Store("middle", "Daniel");
            values.Store("last", "Miller");
            values.Store("returnValue", "foo");

            var invocation = new MethodInvocation(method, target);

            invocation.Compile(target, CellHandling.Basic());

            invocation.Invoke(values).Single().actual.ShouldBe("Jeremy Daniel Miller");
        }
        public void execute()
        {
            var grammar = ActionMethodGrammar.Create(x => x.Go(null, 0, 0), theTarget);

            grammar.Compile(new Fixture(), CellHandling.Basic()).ShouldBeOfType <Sentence>();

            var values = new StepValues("id");

            values.Store("name", "Jeremy");
            values.Store("age", 41);
            values.Store("percentAwake", 50.1);

            ShouldBeTestExtensions.ShouldBe(grammar.Execute(values, SpecContext.Basic()).Any(), false);

            theTarget.Name.ShouldBe("Jeremy");
            theTarget.Age.ShouldBe(41);
            theTarget.PercentAwake.ShouldBe(50.1);
        }
Esempio n. 4
0
        public override IEnumerable <CellResult> Execute(StepValues values, ISpecContext context)
        {
            var element = _config.Finder(SearchContext);

            StoryTellerAssert.Fail(element == null, "Could not find an element w/ description: " + _config.Description);

            try
            {
                return(execute(element, values));
            }
            catch (Exception ex)
            {
                // TODO: Use exception metadata with and add a custom exception formatter to show exception metadata
                //       See: https://github.com/storyteller/Storyteller/issues/400
                // ex.Data.Add("Gesture Description", _config.Description);
                throw new Exception("Gesture failed. [Description: {0}]".ToFormat(_config.Description), ex);
            }
        }
Esempio n. 5
0
        public void matches_array_()
        {
            var cell    = new Cell(CellHandling.Basic(), "a", typeof(int[]));
            var values1 = new StepValues("foo");

            values1.Store(cell.Key, new[] { 1, 2, 3 });

            var values2 = new StepValues("foo");

            values2.Store(cell.Key, new[] { 1, 2, 3 });

            var values3 = new StepValues("foo");

            values3.Store(cell.Key, new[] { 1, 2, 4 });

            cell.Matches(values1, values2).ShouldBe(true);
            cell.Matches(values1, values3).ShouldBe(false);
        }
        public void execute_sad()
        {
            var grammar = ValueCheckMethod.For(new Target(), x => x.Fullname(null, null));
            var values  = new StepValues("1");

            values.Store("first", "Mat");
            values.Store("last", "Cauthon");
            values.Store("expected", "Rand Al'Thor");

            var context = SpecContext.ForTesting();
            var result  = grammar.Execute(values, context).Single();

            // The method is working correctly, but the
            // test data should result in a failure
            result.cell.ShouldBe("expected");
            result.actual.ShouldBe("Mat Cauthon");
            result.Status.ShouldBe(ResultStatus.failed);
        }
Esempio n. 7
0
        public void matches_simply()
        {
            var cell    = new Cell(CellHandling.Basic(), "a", typeof(int));
            var values1 = new StepValues("foo");

            values1.Store(cell.Key, 5);

            var values2 = new StepValues("foo");

            values2.Store(cell.Key, 5);

            var values3 = new StepValues("foo");

            values3.Store(cell.Key, 6);

            cell.Matches(values1, values2).ShouldBe(true);
            cell.Matches(values1, values3).ShouldBe(false);
        }
Esempio n. 8
0
        public void can_invoke_a_method_returning_task()
        {
            var target = new Target();
            var method = ReflectionHelper.GetMethod <Target>(x => x.GoOutputAsync(null));

            var values = new StepValues(method.Name);

            values.Store("name", "Bill");

            var invocation = MethodInvocation.For(method, target);

            invocation.Compile(target, CellHandling.Basic());

            invocation.IsAsync().ShouldBeTrue();

            invocation.InvokeAsync(values).Wait();

            target.Name.ShouldBe("Bill");
        }
Esempio n. 9
0
        protected override IEnumerable <CellResult> execute(IWebElement element, StepValues values)
        {
            var handler       = ElementHandlers.FindHandler(element);
            var expectedValue = values.Get(Cell.Key);

            var matchingHandler = handler as IMatchingHandler ?? new BasicMatchingHandler(handler);

            if (matchingHandler.MatchesData(element, expectedValue))
            {
                return(new [] { new CellResult(Cell.Key, ResultStatus.success) });
            }
            else
            {
                return(new [] { new CellResult(Cell.Key, ResultStatus.failed)
                                {
                                    actual = handler.GetData(SearchContext, element)
                                } });
            }
        }
Esempio n. 10
0
        public void apply_ordering()
        {
            var values = new StepValues[]
            {
                new StepValues(Guid.NewGuid().ToString()),
                new StepValues(Guid.NewGuid().ToString()),
                new StepValues(Guid.NewGuid().ToString()),
                new StepValues(Guid.NewGuid().ToString()),
                new StepValues(Guid.NewGuid().ToString()),
                new StepValues(Guid.NewGuid().ToString())
            };

            values.ApplyOrdering();

            for (var i = 0; i < values.Length; i++)
            {
                values[i].Order.ShouldBe(i + 1);
            }
        }
Esempio n. 11
0
        public override IEnumerable <CellResult> Execute(StepValues values, ISpecContext context)
        {
            var actual = default(T);
            var token  = _fixture.JObject.SelectToken(_path);

            if (token != null)
            {
                if (typeof(T).IsSimple())
                {
                    actual = _cellHandling.Conversions.Convert(typeof(T), token.ToString()).As <T>();
                }
                else
                {
                    actual = token.ToObject <T>(JsonSerializer.Create(_fixture.JsonSerializerSettings));
                }
            }

            yield return(_cell.Check(values, actual));
        }
Esempio n. 12
0
        public void use_default_builder_when_column_is_inactive()
        {
            var cell = Cell.For <string>("foo");

            cell.As <ICellExpression>().UseDefaultIfNotExplicitlyExpressed(s => "Column " + s.Order);

            var values = new StepValues(Guid.NewGuid().ToString())
            {
                Order = 5
            };

            var section = new Section("container");

            section.ActiveCells.Add("foo", false);
            section.IsCellActive(cell).ShouldBeFalse();


            cell.CsvValue(section, values)
            .ShouldBe("Column 5");
        }
Esempio n. 13
0
        public void use_a_runtime_converter_with_a_value()
        {
            var conversions = new Conversions();

            conversions.RegisterRuntimeConversion <ColorConverter>();

            var cellHandling = new CellHandling(new EquivalenceChecker(), conversions);

            var cell = new Cell(cellHandling, "color", typeof(Color));

            var values = new StepValues("foo");

            cell.ConvertValues(new Step("foo").With("color", "Red"), values);

            var delayed = values.DelayedConversions.Single();

            delayed.Key.ShouldBe("color");
            delayed.Raw.ShouldBe("Red");
            delayed.Converter.ShouldBeOfType <ColorConverter>();
        }
Esempio n. 14
0
        public async Task invoke_with_return_value_with_async_invocation()
        {
            var target = new Target();
            var method = ReflectionHelper.GetMethod <Target>(x => x.FullnameAsync(null, null, null));

            var values = new StepValues(method.Name);

            values.Store("first", "Jeremy");
            values.Store("middle", "Daniel");
            values.Store("last", "Miller");
            values.Store("returnValue", "foo");

            var invocation = new AsyncMethodInvocationWithReturn <string>(method, target);

            invocation.Compile(target, CellHandling.Basic());

            var results = await invocation.InvokeAsync(values);

            results.Single().actual.ShouldBe("Jeremy Daniel Miller");
        }
Esempio n. 15
0
        private void SetTimeprofile([NotNull] CalcProfile calcProfile, [NotNull] TimeStep startidx,
                                    [NotNull] CalcLoadType loadType,
                                    [NotNull] string affordanceName, [NotNull] string activatingPersonName, StrGuid locationGuid)
        {
            CalcDeviceLoad cdl = null;

            foreach (var calcDeviceLoad in _loads)
            {
                if (calcDeviceLoad.LoadType == loadType)
                {
                    cdl = calcDeviceLoad;
                }
            }

            if (cdl == null)
            {
                throw new LPGException("It was tried to activate the loadtype " + loadType.Name +
                                       " even though that one is not set for the device " + Name);
            }

            /*   var factor = cdl.Value * multiplier;
             * if (calcProfile.ProfileType == ProfileType.Absolute)
             * {
             *     factor = 1 * multiplier;
             * }*/
            if (_calcRepo.Odap == null && !Config.IsInUnitTesting)
            {
                throw new LPGException("ODAP was null. Please report");
            }

            //   var totalDuration = calcProfile.GetNewLengthAfterCompressExpand(timefactor);
            //OefcKey key = new OefcKey(_calcDeviceDto.HouseholdKey, OefcDeviceType.Transportation, Guid, "-1", cdl.LoadType.Guid, "Transportation");
            var key = _keysByLocGuidAndLoadtype[locationGuid][cdl.LoadType];
            var rvp = RandomValueProfile.MakeStepValues(calcProfile.StepValues.Count, _calcRepo.NormalRandom, 0);
            var sv  = StepValues.MakeStepValues(calcProfile, 1, rvp, cdl);

            _calcRepo.Odap.AddNewStateMachine(startidx, cdl.LoadType.ConvertToDto(), affordanceName, activatingPersonName,
                                              key, _calcDeviceDto, sv);
            //SetBusy(startidx, totalDuration, loadType, activateDespiteBeingBusy);
            // return totalDuration + startidx;
        }
        public void MarkExtra(StepValues values)
        {
            var extra = new Dictionary <string, string>();

            values.RawData.Each(pair =>
            {
                if (pair.Value == null)
                {
                    extra.Add(pair.Key, "NULL");
                }
                else if (pair.Value == string.Empty)
                {
                    extra.Add(pair.Key, "BLANK");
                }
                else
                {
                    extra.Add(pair.Key, Cell.ToStringDisplay(pair.Value));
                }
            });

            _extras.Add(extra);
        }
Esempio n. 17
0
 public void CreatePlan(ExecutionPlan plan, StepValues values, FixtureLibrary library, bool inTable = false)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 18
0
        public void DriveAndCharge([NotNull] TimeStep currentTimeStep)
        {
            AdjustCurrentsiteByTimestep(currentTimeStep);
            LastChargingPower = 0;
            //first the undefined state
            // geräte, die nicht geladen werden müssen, haben eine negative range.
            //geräte im vehicle depot / in transit müssen nicht geladen werden.

            if (_fullRangeInMeters < 0)
            {
                DisconnectCar();
                _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry(
                                                                             Name, Guid, currentTimeStep, TransportationDeviceState.Undefined,
                                                                             CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name,
                                                                             _lastUsingPerson, _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0));
                return;
            }

            //currently driving
            if (currentTimeStep >= _activationStartTimestep && currentTimeStep < _activationStopTimestep)
            {
                DisconnectCar();

                if (_currentSite != null)
                {
                    throw new LPGException("transportation device was assigned to a site, even though it is driving");
                }

                double distancePerTimestep = AverageSpeedInMPerS *
                                             _calcRepo.CalcParameters.InternalStepsize.TotalSeconds;
                _availableRangeInMeters -= distancePerTimestep;
                if (_availableRangeInMeters <= 0)
                {
                    _availableRangeInMeters = 0;
                }
                _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry(
                                                                             Name, Guid, currentTimeStep, TransportationDeviceState.Driving,
                                                                             CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters,
                                                                             _currentSite?.Name,
                                                                             _lastUsingPerson, _dsc.MakeDateStringFromTimeStep(currentTimeStep), distancePerTimestep));
                return;
            }

            //car is fully charged
            if (_availableRangeInMeters >= _fullRangeInMeters)
            {
                _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry(
                                                                             Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndFullyCharged,
                                                                             CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name,
                                                                             null
                                                                             , _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0));
                DisconnectCar();
                //TODO: different disconnect strategies
                return;
            }

            if (_currentSite != null)
            {
                //needs charging && is at charging station
                var chargingStations =
                    _currentSite.ChargingDevices.Where(x =>
                                                       x.CarChargingLoadType == _chargingCalcLoadType1 &&
                                                       x.DeviceCategory == Category).ToList();
                if (chargingStations.Count > 0)
                {
                    if (chargingStations.All(x => !x.IsAvailable) && _lastChargingStation == null)
                    {
                        _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry(
                                                                                     Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndWaitingForCharging,
                                                                                     CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite.Name,
                                                                                     null, _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0));
                        DisconnectCar();
                        return;
                    }

                    //use the first one that is available
                    //TODO: recycle the last one used
                    var chargingStation = _lastChargingStation;
                    if (_lastChargingStation == null)
                    {
                        chargingStation = chargingStations.First(x => x.IsAvailable);
                        ConnectCar(chargingStation);
                    }

                    if (_currentSite == null)
                    {
                        throw new LPGException("Current site was null while trying to charge.");
                    }

                    if (chargingStation == null)
                    {
                        throw new LPGException("Charging station for charging was null");
                    }

                    _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry(
                                                                                 Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndCharging,
                                                                                 CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite.Name,
                                                                                 null, _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0));
                    double maxChargingPower = Math.Min(_maxChargingPower, chargingStation.MaxChargingPower);

                    List <double> chargingProfile = new List <double> {
                        maxChargingPower
                    };

                    var cp = new CalcProfile("Profile for " + _currentSite.Name + " - Charging - " + Name,
                                             System.Guid.NewGuid().ToStrGuid(),
                                             chargingProfile, ProfileType.Absolute,
                                             "Synthetic Charging for " + Name + " @ " + _currentSite.Name);
                    var dstLoadType = chargingStation.GridChargingLoadType;
                    var key         = _keysByLocGuidAndLoadtype[_currentSite.Guid][dstLoadType];
                    //OefcKey key = new OefcKey(_householdKey, OefcDeviceType.Charging, Guid, _currentSite.Guid, dstLoadType.Guid, "Transportation");
                    //if (dstLoadType == null) {
                    //    throw new Exception("???");
                    //}
                    CalcDeviceLoad cdl = new CalcDeviceLoad("", 1, dstLoadType, 0, 0);
                    //if (cp.DataSource != "Synthetic") {
                    //throw new LPGException("wrong data source");
                    //}
                    var rsv = RandomValueProfile.MakeStepValues(cp.StepValues.Count, _calcRepo.NormalRandom, cdl.PowerStandardDeviation);
                    var sv  = StepValues.MakeStepValues(cp, 1, rsv, cdl);
                    _calcRepo.Odap.AddNewStateMachine(currentTimeStep,
                                                      dstLoadType.ConvertToDto(),
                                                      "Charging for " + Name + " @ " + _currentSite,
                                                      "(autonomous)", key, _calcDeviceDto, sv);
                    double gainedDistance = maxChargingPower * _energyToDistanceFactor *
                                            _calcRepo.CalcParameters.InternalStepsize.TotalSeconds;
                    _availableRangeInMeters += gainedDistance;
                    LastChargingPower        = maxChargingPower;
                    if (_availableRangeInMeters > _fullRangeInMeters)
                    {
                        //TODO: do this properly: reduce the max charging power
                        _availableRangeInMeters = _fullRangeInMeters;
                    }

                    return;
                }
            }

            DisconnectCar();
            _calcRepo.OnlineLoggingData.AddTransportationDeviceState(new TransportationDeviceStateEntry(
                                                                         Name, Guid, currentTimeStep, TransportationDeviceState.ParkingAndNoChargingAvailableHere,
                                                                         CurrentSoc, _calcDeviceDto.HouseholdKey, _availableRangeInMeters, _currentSite?.Name, null
                                                                         , _dsc.MakeDateStringFromTimeStep(currentTimeStep), 0));
        }
Esempio n. 19
0
 public void SetUp()
 {
     values         = new StepValues(Guid.NewGuid().ToString());
     context        = SpecContext.ForTesting();
     theLineGrammar = MockRepository.GenerateMock <ILineGrammar>();
 }
Esempio n. 20
0
 public LineStep(StepValues values, ILineGrammar grammar) : base(values)
 {
     _grammar = grammar;
 }
Esempio n. 21
0
 protected LineStepBase(StepValues values)
 {
     Values = values;
 }
 public LinePlanTester()
 {
     values         = new StepValues(Guid.NewGuid().ToString());
     context        = SpecContext.ForTesting();
     theLineGrammar = Substitute.For <ILineGrammar>();
 }
Esempio n. 23
0
        public Task <bool> InvokeTestAsync(StepValues values)
        {
            var parameters = Arguments.Select(values.Get).ToArray();

            return((Task <bool>)Method.Invoke(Target, parameters));
        }
Esempio n. 24
0
        public bool InvokeTest(StepValues values)
        {
            var parameters = Arguments.Select(values.Get).ToArray();

            return((bool)Method.Invoke(Target, parameters));
        }
Esempio n. 25
0
 public FactPlan(StepValues values, IFactGrammar grammar) : base(values)
 {
     _grammar = grammar;
 }
Esempio n. 26
0
 public Task<bool> PerformTestAsync(StepValues values, ISpecContext context)
 {
     throw new NotImplementedException();
 }
Esempio n. 27
0
 public bool PerformTest(StepValues values, ISpecContext context)
 {
     return _test(context);
 }
 public FactCheckPlan(StepValues values, FactCheckMethod grammar)
     : base(values)
 {
     _grammar = grammar;
 }
 public override IEnumerable <CellResult> Execute(StepValues values, ISpecContext context)
 {
     throw new NotSupportedException();
 }
Esempio n. 30
0
 public CellResult Execute(IDbCommand command, CommandRunner runner, StepValues values, ISpecContext context)
 {
     runner.Execute(command);
     return(null);
 }