public void Remove() { PeopleBase db = new PeopleBase(); FieldInfo fieldValue = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(Person[])); FieldInfo currentIndexInfo = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); Person[] people = new Person[] { new Person("Lola", 343434), new Person("John", 3434) }; fieldValue.SetValue(db, people); currentIndexInfo.SetValue(db, people.Length); var dbArray = (Person[])fieldValue.GetValue(db); db.Remove(); var otherArray = people.Take(people.Length - 1).Concat(new Person[dbArray.Length - people.Length + 1]).ToArray(); int currentIndex = (int)currentIndexInfo.GetValue(db); Assert.That(currentIndex, Is.EqualTo(people.Length - 1)); Assert.That(dbArray, Is.EquivalentTo(otherArray)); }
static PeopleService() { var ppl = new PeopleBase { FirstName = "Frank", LastName = "Baumgartner", Id = 666 }; ppl.Phones.Add(new PeopleBase.Types.PhoneNumber { Number = "0800 555 666 777", Type = PeopleBase.Types.PhoneType.Mobile }); DefaultCouch = new CoachRes { PeopleBase = ppl, CoachTimeReachableFrom = Timestamp.FromDateTime(DateTime.Now.ToUniversalTime()), CoachTimeReachableTo = Timestamp.FromDateTime(DateTime.Now.AddHours(3).ToUniversalTime()) }; ppl = new PeopleBase { FirstName = "Tim", LastName = "Walter", Id = 42 }; ppl.Phones.Add(new PeopleBase.Types.PhoneNumber { Number = "+49 134 4534234", Type = PeopleBase.Types.PhoneType.Mobile }); DefaultCustomer = new CustomerRes { PeopleBase = ppl }; }
public void TestEmtpyDataBase() { PeopleBase db = new PeopleBase(); Assert.That(() => db.FindByUsername("sds"), Throws.InvalidOperationException); Assert.That(() => db.FindById(12), Throws.InvalidOperationException); }
public void TestConstructor() { Person[] people = new Person[] { new Person("Lola", 343434), new Person("John", 3434) }; PeopleBase db = new PeopleBase(); FieldInfo fieldValue = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(Person[])); fieldValue.SetValue(db, people); var value = (Person[])fieldValue.GetValue(db); var initialValue = people.Concat(new Person[value.Length - people.Length]); Assert.That(value, Is.EquivalentTo(initialValue)); }
public void TestAddMethod() { PeopleBase db = new PeopleBase(); var value = new Person("A", 2); db.Add(value); FieldInfo fieldInfo = typeof(PeopleBase).GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == typeof(Person[])); FieldInfo currentIndexInfo = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); Person firstValue = ((Person[])fieldInfo.GetValue(db)).First(); int currentIndex = (int)currentIndexInfo.GetValue(db); Assert.That(firstValue, Is.EqualTo(value)); Assert.That(currentIndex, Is.EqualTo(1)); }
public void InvalidAddIndex() { PeopleBase db = new PeopleBase(); FieldInfo fieldValue = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(Person[])); FieldInfo currentIndexInfo = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); Person[] people = new Person[16]; fieldValue.SetValue(db, people); currentIndexInfo.SetValue(db, people.Length); Assert.That(() => db.Add(new Person("1", 23)), Throws.InvalidOperationException); }
public void TestFindById() { PeopleBase db = new PeopleBase(); FieldInfo fieldValue = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(Person[])); Person[] people = new Person[] { new Person("Lola", 343434), new Person("John", 3434) }; fieldValue.SetValue(db, people); FieldInfo currentIndexInfo = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); currentIndexInfo.SetValue(db, people.Length); Assert.That(() => db.FindById(343434).Name, Is.EqualTo("Lola")); }
public void TestByUsernameInvalid() { PeopleBase db = new PeopleBase(); FieldInfo fieldValue = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(p => p.FieldType == typeof(Person[])); Person[] people = new Person[] { new Person("Lola", 343434), new Person("John", 3434) }; fieldValue.SetValue(db, people); FieldInfo currentIndexInfo = typeof(PeopleBase) .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(p => p.FieldType == (typeof(int))); currentIndexInfo.SetValue(db, people.Length); Assert.That(() => db.FindByUsername(null), Throws.ArgumentException); Assert.That(() => db.FindByUsername("Ken"), Throws.InvalidOperationException); }
public override async Task <AcceptJobRes> AcceptJobReq(DefaultReq request, ServerCallContext context) { var j = await _dbContext.Blitzjobs.FindAsync(request.Id).ConfigureAwait(false); if (j == null) { return new AcceptJobRes { Success = false } } ; else { j.Status = Shared.Entities.Status.Accepted; await _dbContext.SaveChangesAsync().ConfigureAwait(false); await _httpClient.GetAsync("http://tk3/refresh"); var ppl = new PeopleBase { Id = j.Customer?.CustomerID ?? 1, LastName = j.Customer?.LastName ?? "Ries", FirstName = j.Customer?.FirstName ?? "Adam" }; ppl.Phones.Add(new PeopleBase.Types.PhoneNumber { Number = "+49 134 4534234", Type = PeopleBase.Types.PhoneType.Mobile }); return(new AcceptJobRes { Success = true, Customer = new CustomerRes { PeopleBase = ppl }, Coach = PeopleService.DefaultCouch }); } }
public void TestInvalidFetch() { PeopleBase db = new PeopleBase(); Assert.That(() => db.Fetch(), Throws.InvalidOperationException); }
public void InvalidRemove() { PeopleBase db = new PeopleBase(); Assert.That(() => db.Remove(), Throws.InvalidOperationException); }