public void ShouldInitializeEmailsProperty() { var wrapper = new PersonWrapper(_person); Assert.IsNotNull(wrapper.Emails); CheckIfModelEmailsCollectionIsInSync(wrapper); }
public void ReactiveObject_ForMultipleLevelNestedReactiveProperties_ComputesCorrectly() { var person = new Person { Id = 0, Age = 30, Name = "John Doe", Type = "VIP" }; var personWrapper = new PersonWrapper { Person = person, AdditionalRisk = 10 }; var personWrapperWrapper = new PersonWrapperWrapper { PersonWrapper = personWrapper }; var invoice = new Insurance { Cost = R.Of(() => personWrapperWrapper.PersonWrapper.Person.Type == "VIP" ? personWrapper.Person.Age * 10 : personWrapper.Person.Age * 30 + personWrapper.AdditionalRisk) }; Assert.AreEqual(person.Age * 10, invoice.Cost); person.Age.Set(35); Assert.AreEqual(person.Age * 10, invoice.Cost); person.Type.Set("Regular"); Assert.AreEqual(personWrapper.Person.Age * 30 + personWrapper.AdditionalRisk, invoice.Cost); }
public void ShouldBeInSyncAfterClearingEmails() { var wrapper = new PersonWrapper(_person); wrapper.Emails.Clear(); CheckIfModelEmailsCollectionIsInSync(wrapper); }
public void ShouldInitializeAddressProperty() { var wrapper = new PersonWrapper(_person); Assert.IsNotNull(wrapper.Address); Assert.AreEqual(_person.Address, wrapper.Address.Model); }
private void InitializePerson(Person person) { Person = new PersonWrapper(person); Person.PropertyChanged += (s, e) => { if (!HasChanges) { HasChanges = _personRepository.HasChanges(); } if (e.PropertyName == nameof(Person.HasErrors)) { ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged(); } if (e.PropertyName == nameof(Person.FirstName) || e.PropertyName == nameof(Person.LastName)) { SetTitle(); } }; ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged(); if (Person.Id == 0) { Person.FirstName = ""; Person.LastName = ""; } SetTitle(); }
public void TestPersonWrapperHouseholdDayPatternParticipationPriority() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonWrapper wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.CHILD_UNDER_5); Assert.Equal(1, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.CHILD_AGE_5_THROUGH_15); Assert.Equal(2, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.DRIVING_AGE_STUDENT); Assert.Equal(7, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.FULL_TIME_WORKER); Assert.Equal(5, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.NON_WORKING_ADULT); Assert.Equal(3, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.PART_TIME_WORKER); Assert.Equal(4, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.RETIRED_ADULT); Assert.Equal(6, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.UNIVERSITY_STUDENT); Assert.Equal(8, wrapper.HouseholdDayPatternParticipationPriority); wrapper = TestHelper.GetPersonWrapper(personType: 99); Assert.Equal(9, wrapper.HouseholdDayPatternParticipationPriority); }
public static PersonWrapper GetPersonWrapper(int age = 35, int personType = Constants.PersonType.FULL_TIME_WORKER, int gender = 1, int workerType = 0, int studentType = 0, List <IPerson> persons = null, HouseholdWrapper household = null, int income = 25000, int sequence = 0) { if (persons == null) { persons = new List <IPerson> { new Person() { Age = age, PersonType = personType, Gender = gender, WorkerType = workerType, StudentType = studentType, Sequence = sequence, } }; } if (household == null) { household = GetHouseholdWrapper(persons, income: income); } household.Init(); PersonWrapper wrapper = new PersonWrapper(persons[0], household); return(wrapper); }
public void ShouldSetValueOfTheUnderlyingProperty() { var wrapper = new PersonWrapper(_person); wrapper.Name = "John Memon"; Assert.AreEqual("John Memon", _person.Name); }
public static void SignalShutdown() { if (ThreadQueue == null) { return; } ThreadQueue.Shutdown(); HouseholdWrapper.Close(); PersonWrapper.Close(); HouseholdDayWrapper.Close(); PersonDayWrapper.Close(); TourWrapper.Close(); TripWrapper.Close(); if (!string.IsNullOrEmpty(Global.Configuration.OutputJointTourPath)) { JointTourWrapper.Close(); } if (!string.IsNullOrEmpty(Global.Configuration.OutputFullHalfTourPath)) { FullHalfTourWrapper.Close(); } if (!string.IsNullOrEmpty(Global.Configuration.OutputPartialHalfTourPath)) { PartialHalfTourWrapper.Close(); } }
// Id alapján kap egy Person-t public async Task LoadAsync(int?personId) { // Ha az id-ban van elem, akkor lekérjük a detail nézetbe az embert, ha nincs, akkor tudjuk hogy új ember lett hozzáadva var person = personId.HasValue ? await _personRepository.GetByIdAsync(personId.Value) : CreateNewPerson(); Person = new PersonWrapper(person); Person.PropertyChanged += (s, e) => { if (!HasChanges) { // Ha a property változik és a HasChanges még nincs beállítva, akkor állítsuk igazra HasChanges = _personRepository.HasChanges(); } if (e.PropertyName == nameof(Person.HasErrors)) { ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged(); } }; ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged(); if (Person.Id == 0) { // Ennek hatására ha hozzáadunk egy új embert, akkor is bekapcsol a validáció, enélkül lehetne üres mezővel hozzáadni és az entity framework hibát dobna Person.FirstName = ""; } }
public void Save() { Model = _personRepository.InsertOrUpdate(Model.Model); _mediator.Send(new UpdateMessage <PersonWrapper> { Model = Model }); Load(Model.Id); }
public void ShouldBeInSyncAfterRemovingEmail() { var wrapper = new PersonWrapper(_person); var emailToRemove = wrapper.Emails.Single(ew => ew.Model == _email); wrapper.Emails.Remove(emailToRemove); CheckIfModelEmailsCollectionIsInSync(wrapper); }
public void ShouldBeInSyncAfterAddingEmail() { _person.Emails.Remove(_email); var wrapper = new PersonWrapper(_person); wrapper.Emails.Add(new EmailWrapper(_email)); CheckIfModelEmailsCollectionIsInSync(wrapper); }
public void ShouldStoreOriginalValue() { var wrapper = new PersonWrapper(_person); Assert.AreEqual("Tarique Memon", wrapper.NameOriginalValue); wrapper.Name = "Nik"; Assert.AreEqual("Tarique Memon", wrapper.NameOriginalValue); }
public void Load(Guid id) { Model = _personRepository.GetById(id) ?? new PersonDetailModel() { BirthDate = DateTime.Now, ActedInFilms = new List <ActedInFilmDetailModel>(), DirectedFilms = new List <DirectedFilmDetailModel>() }; }
public void Run(PersonWrapper person, int sampleSize) { if (person == null) { throw new ArgumentNullException("person"); } person.ResetRandom(0); if (Global.Configuration.IsInEstimationMode) { if (!_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { return; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(person.Id); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { if (person.UsualWorkParcel == null) { return; } bool choseHome = person.UsualWorkParcelId == person.Household.ResidenceParcelId; // JLB 20120329 added these two lines IParcelWrapper chosenParcel = choseHome ? null : person.UsualWorkParcel; //RunModel(choiceProbabilityCalculator, person, sampleSize, person.UsualWorkParcel); RunModel(choiceProbabilityCalculator, person, sampleSize, chosenParcel, choseHome); // JLB 20120329 replaced above line // when chosenParcel is null: // DestinationSampler doesn't try to assign one of the sampled destinations as chosen // choseHome is NOT null, and RunModel sets the oddball location as chosen choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, person, sampleSize); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(person.Household.RandomUtility); ParcelWrapper choice = (ParcelWrapper)chosenAlternative.Choice; person.UsualWorkParcelId = choice.Id; person.UsualWorkParcel = choice; person.UsualWorkZoneKey = ChoiceModelFactory.ZoneKeys[choice.ZoneId]; SkimValue skimValue = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, person.Household.ResidenceParcel, choice); person.AutoTimeToUsualWork = skimValue.Variable; person.AutoDistanceToUsualWork = skimValue.BlendVariable; person.SetWorkParcelPredictions(); } }
public void ShouldSetIsChangedOfPersonWrapper() { var wrapper = new PersonWrapper(_person); wrapper.Address.StreetName = "XYZ"; Assert.IsTrue(wrapper.IsChanged); wrapper.Address.StreetName = "ChemCentre, Perth"; Assert.IsFalse(wrapper.IsChanged); }
public void TestTourWrapper2() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonWrapper person = TestHelper.GetPersonWrapper(); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); CondensedParcel originParcel = new CondensedParcel(); CondensedParcel destinationParcel = new CondensedParcel(); int destinationDepartureTime = 1; int destinationPurpose = Constants.Purpose.BUSINESS; int destinationArrivalTime = 3; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; Tour subtour = new Tour(); TourWrapper tour = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); TourWrapper wrapper = new TourWrapper(subtour, tour); Assert.Equal(tour, wrapper.ParentTour); Assert.Equal(1261, wrapper.DestinationDepartureTime); Assert.Equal(1261, wrapper.DestinationArrivalTime); Assert.Equal(0, wrapper.DestinationPurpose); Assert.Equal(null, wrapper.DestinationParcel); Assert.Equal(null, wrapper.OriginParcel); Assert.Equal(person, wrapper.Person); Assert.Equal(personDay, wrapper.PersonDay); Assert.Equal(0, wrapper.DestinationAddressType); Assert.Equal(null, wrapper.DestinationArrivalBigPeriod); Assert.Equal(false, wrapper.DestinationModeAndTimeHaveBeenSimulated); Assert.Equal(0, wrapper.DestinationParcelId); Assert.Equal(0, wrapper.DestinationZoneKey); Assert.Equal(0, wrapper.EarliestOriginDepartureTime); Assert.Equal(0, wrapper.FullHalfTour1Sequence); Assert.Equal(0, wrapper.FullHalfTour2Sequence); Assert.Equal(null, wrapper.GetHalfTour(Constants.TourDirection.DESTINATION_TO_ORIGIN)); Assert.Equal(null, wrapper.GetHalfTour(Constants.TourDirection.ORIGIN_TO_DESTINATION)); Assert.Equal(false, wrapper.HalfTour1HasBeenSimulated); Assert.Equal(0, wrapper.HalfTour1Trips); Assert.Equal(false, wrapper.HalfTour2HasBeenSimulated); Assert.Equal(0, wrapper.HalfTour2Trips); // Assert.Equal(false, wrapper.HasSubtours); Assert.Equal(0, wrapper.IndicatedTravelTimeFromDestination); Assert.Equal(0, wrapper.IndicatedTravelTimeToDestination); Assert.Equal(false, wrapper.IsHomeBasedTour); Assert.Equal(false, wrapper.IsMissingData); Assert.Equal(false, wrapper.IsParkAndRideMode); }
//MBADD runnested public ChoiceProbabilityCalculator.Alternative RunNested(PersonWrapper person, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars, double transitDiscountFraction, int purpose) { if (person == null) { throw new ArgumentNullException("person"); } TourWrapper tour = (TourWrapper)_creator.CreateWrapper(person, null, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, purpose); return(RunNested(tour, destinationParcel, householdCars, transitDiscountFraction)); }
public override void LoadInDesignMode() { base.LoadInDesignMode(); Model = new PersonWrapper(new PersonDetailModel() { FirstName = "Janko", LastName = "Lehotský", BirthDate = new DateTime(1980, 12, 5), FotoUrl = "https://www.pngitem.com/pimgs/m/40-406527_cartoon-glass-of-water-png-glass-of-water.png" }); }
public void TestPersonWrapperTransitFareDiscountFraction() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; Global.Configuration.PathImpedance_TransitUseFareDiscountFractions = false; List <IPerson> persons = new List <IPerson>() { new Person() { Age = 4, TransitPassOwnership = 1, PersonType = Constants.PersonType.CHILD_UNDER_5, } }; HouseholdWrapper household = TestHelper.GetHouseholdWrapper(persons); household.Init(); PersonWrapper wrapper = new PersonWrapper(persons[0], household) { }; Assert.Equal(0, wrapper.TransitFareDiscountFraction); Global.Configuration.PathImpedance_TransitUseFareDiscountFractions = true; Global.Configuration.IncludeTransitPassOwnershipModel = true; Assert.Equal(1, wrapper.TransitFareDiscountFraction); Global.Configuration.IncludeTransitPassOwnershipModel = false; Global.Configuration.Policy_UniversalTransitFareDiscountFraction = .1; Assert.Equal(.1, wrapper.TransitFareDiscountFraction); Global.Configuration.PathImpedance_TransitFareDiscountFractionChildUnder5 = .2; Global.Configuration.Policy_UniversalTransitFareDiscountFraction = 0; Assert.Equal(.2, wrapper.TransitFareDiscountFraction); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.CHILD_AGE_5_THROUGH_15); Global.Configuration.PathImpedance_TransitFareDiscountFractionChild5To15 = .3; Assert.Equal(.3, wrapper.TransitFareDiscountFraction); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.DRIVING_AGE_STUDENT); Global.Configuration.PathImpedance_TransitFareDiscountFractionHighSchoolStudent = .4; Assert.Equal(.4, wrapper.TransitFareDiscountFraction); wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.UNIVERSITY_STUDENT); Global.Configuration.PathImpedance_TransitFareDiscountFractionUniverityStudent = .5; Assert.Equal(.5, wrapper.TransitFareDiscountFraction); wrapper = TestHelper.GetPersonWrapper(age: 65); Global.Configuration.PathImpedance_TransitFareDiscountFractionAge65Up = .6; Assert.Equal(.6, wrapper.TransitFareDiscountFraction); wrapper = TestHelper.GetPersonWrapper(age: 64); Assert.Equal(0, wrapper.TransitFareDiscountFraction); }
private void btnDeleteAgent_Click(object sender, RoutedEventArgs e) { try { if (lstAgents.SelectedIndex != -1) { PersonWrapper.DeletePerson(((Person)lstAgents.SelectedItem).Id); } } catch (Exception ex) { MessageBox.Show($"Personen kunne slettes.\n\n{ex.Message}"); } }
public IEnumerable <VoipCallWrapper> GetCalls(string callType, ApiDateTime from, ApiDateTime to, Guid?agent, int?client, int?contactID) { var voipDao = DaoFactory.VoipDao; var filter = new VoipCallFilter { Type = callType, FromDate = from != null ? from.UtcTime : (DateTime?)null, ToDate = to != null?to.UtcTime.AddDays(1).AddMilliseconds(-1) : (DateTime?)null, Agent = agent, Client = client, ContactID = contactID, SortBy = _context.SortBy, SortOrder = !_context.SortDescending, SearchText = _context.FilterValue, Offset = _context.StartIndex, Max = _context.Count, }; _context.SetDataPaginated(); _context.SetDataFiltered(); _context.SetDataSorted(); _context.TotalCount = voipDao.GetCallsCount(filter); var defaultSmallPhoto = ContactPhotoManager.GetSmallSizePhoto(-1, false); var calls = voipDao.GetCalls(filter).Select( r => { ContactWrapper contact; if (r.ContactId != 0) { contact = r.ContactIsCompany ? (ContactWrapper) new CompanyWrapper(r.ContactId) { DisplayName = r.ContactTitle } : new PersonWrapper(r.ContactId) { DisplayName = r.ContactTitle }; contact.SmallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(contact.ID, contact.IsCompany); } else { contact = new PersonWrapper(-1) { SmallFotoUrl = defaultSmallPhoto }; } return(new VoipCallWrapper(r, contact)); }).ToList(); return(calls); }
public void ShouldThrowArgumentNullExceptionIfModelIsNull() { try { var wrapper = new PersonWrapper(null); } catch (ArgumentNullException ex) { Assert.AreEqual("model", ex.ParamName); throw; } }
public void TestTourWrapperTimeCoefficient() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonWrapper person = TestHelper.GetPersonWrapper(); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); CondensedParcel originParcel = new CondensedParcel(); CondensedParcel destinationParcel = new CondensedParcel(); int destinationDepartureTime = 1; int destinationPurpose = Constants.Purpose.SCHOOL; int destinationArrivalTime = 3; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Work = .76; Global.Configuration.Coefficients_MeanTimeCoefficient_Work = .46; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; TourWrapper wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(.45, wrapper.TimeCoefficient); destinationPurpose = Constants.Purpose.WORK; wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(.46, wrapper.TimeCoefficient); Global.Configuration.UseRandomVotDistribution = true; wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(.46, wrapper.TimeCoefficient); //This constructor suppresses randomVOT person = TestHelper.GetPersonWrapper(); personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); destinationPurpose = Constants.Purpose.BUSINESS; Tour tour = new Tour(); wrapper = new TourWrapper(tour, personDay, destinationPurpose, false); Assert.Equal(-.001, wrapper.TimeCoefficient); //This constructor does not suppress randomVOT Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Work = .8; Global.Configuration.Coefficients_MeanTimeCoefficient_Work = -.03; person = TestHelper.GetPersonWrapper(); personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); destinationPurpose = Constants.Purpose.WORK; tour = new Tour(); wrapper = new TourWrapper(tour, personDay, destinationPurpose, false); Assert.Equal(-.0303002, Math.Round(wrapper.TimeCoefficient, 7)); //This constructor does not suppress randomVOT }
public void ShouldSetIsChangedOfPersonWrapper() { var wrapper = new PersonWrapper(_person); var emailToModify = wrapper.Emails.First(); emailToModify.EmailAddress = "*****@*****.**"; Assert.IsTrue(wrapper.IsChanged); emailToModify.EmailAddress = "*****@*****.**"; Assert.IsFalse(wrapper.IsChanged); }
public void ShouldRejectChanges() { var wrapper = new PersonWrapper(_person); wrapper.Address.StreetName = "XYZ"; Assert.AreEqual("ChemCentre, Perth", wrapper.Address.StreetNameOriginalValue); wrapper.RejectChanges(); Assert.IsFalse(wrapper.IsChanged); Assert.AreEqual("ChemCentre, Perth", wrapper.Address.StreetName); Assert.AreEqual("ChemCentre, Perth", wrapper.Address.StreetNameOriginalValue); }
public void ShouldThrowArgumentExceptionIfEmailsCollectionIsNull() { try { _person.Emails = null; var wrapper = new PersonWrapper(_person); } catch (ArgumentNullException ex) { Assert.AreEqual("Emails cannot be null", ex.ParamName); throw; } }
public static PersonDayWrapper GetPersonDayWrapper(PersonWrapper personWrapper = null, int income = 0) { List <IPerson> persons = new List <IPerson> { new Person() }; HouseholdWrapper householdWrapper = TestHelper.GetHouseholdWrapper(persons, income: income); HouseholdDayWrapper householdDay = TestHelper.GetHouseholdDayWrapper(householdWrapper: householdWrapper); if (personWrapper == null) { personWrapper = GetPersonWrapper(household: householdWrapper); } return(new PersonDayWrapper(new PersonDay(), personWrapper, householdDay)); }
public void ShouldRaisePropertyChangedEventForIsChanged() { var fired = false; var wrapper = new PersonWrapper(_person); wrapper.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(wrapper.IsChanged)) { fired = true; } }; wrapper.Name = "John Memon"; Assert.IsTrue(fired); }