Exemplo n.º 1
0
        public Person Next(Person receiver)
        {
            // shuffle the people in play
            _shuffler.Shuffle(_inPlay);

            // grab the first person that's not in the off limits list and
            // is not the receiver to be the gift giver this time.
            var person = _inPlay
                .Where(x => !_offLimits.Contains(x, new PersonComparer()))
                .First(x => x.Name != receiver.Name);

            if (_offLimits.Select(x => x.Name).Contains(person.Name))
                throw new InvalidOperationException(string.Format("{0} is in the offlimits list!", person.Name));

            // that chosen person is no longer in play as a gifter
            // for awhile, so add them to the "off limits" queue
            _inPlay.Remove(person);
            _offLimits.Enqueue(person);

            // if the number of people that are off limits is more than
            // allowed, pop them off the queue and put them back in play
            // to be shuffled and entered back into the mix.
            if (_offLimits.Count > _maxNotInPlay)
            {
                var backInTheGame = _offLimits.Dequeue();
                _inPlay.Add(backInTheGame);
            }

            return person;
        }
Exemplo n.º 2
0
        public Gift(Person receiver, Person gifter)
        {
            if (receiver == gifter)
                throw new ArgumentException("receiver and gifter cannot be the same person");

            Receiver = receiver;
            Gifter = gifter;
        }
Exemplo n.º 3
0
        public void Save(Person[] people)
        {
            var lines = from person in people
                        let line = string.Format("{0},{1}/{2}", person.Name, person.Birthday.Month, person.Birthday.Day)
                        select line;

            File.WriteAllLines(_fileName, lines);
        }
Exemplo n.º 4
0
        public void Add(Person person)
        {
            _offLimitsPeople.Enqueue(person);

            // if the number of people that are off limits is more than
            // allowed, pop someone off the queue and put them back in play
            if (_offLimitsPeople.Count > _maxOffLimits)
            {
                _offLimitsPeople.Dequeue();
            }
        }
 public void SendPerson(Person person)
 {
     var path = "person.xml";
     Serializator.Serialize(person, path);
     var bytes = File.ReadAllBytes(path);
     _client.Send(bytes);
     File.Delete(path);
 }
 public WaitViewModel(Person person)
 {
     Message = string.Format("{0} {1}, тестирование скоро начнется", person.FirstName, person.ThirdName);
 }
Exemplo n.º 7
0
 public bool IsPersonInList(Person other)
 {
     return _offLimitsPeople.Any(
         person => other.ToString().Equals(person.ToString()));
 }
Exemplo n.º 8
0
        public OffLimitsSource(Person[] offLimitsPeople, int totalPersonCount)
        {
            _offLimitsPeople = new Queue<Person>(offLimitsPeople ?? new Person[0]);

            _maxOffLimits = (int) (totalPersonCount/1.25m);
        }
		public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithPropertiesIsCorrect()
		{
			// Arrange
			var person = new Person("Vanya", "Ivanov");
			const string updateCode = "person.LastName = person.LastName.substr(0, 5) + 'ff';";

			const string input1 = "person.FirstName";
			const string targetOutput1 = "Vanya";

			const string input2 = "person.LastName";
			const string targetOutput2 = "Ivanoff";

			// Act
			string output1;
			string output2;

			using (var jsEngine = CreateJsEngine())
			{
				jsEngine.EmbedHostObject("person", person);
				jsEngine.Execute(updateCode);

				output1 = jsEngine.Evaluate<string>(input1);
				output2 = jsEngine.Evaluate<string>(input2);
			}

			// Assert
			Assert.AreEqual(targetOutput1, output1);
			Assert.AreEqual(targetOutput2, output2);
		}
Exemplo n.º 10
0
 public PersonSource(Person[] people)
 {
     _people = people;
 }