コード例 #1
0
        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));
        }
コード例 #2
0
        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
            };
        }
コード例 #3
0
        public void TestEmtpyDataBase()

        {
            PeopleBase db = new PeopleBase();

            Assert.That(() => db.FindByUsername("sds"), Throws.InvalidOperationException);
            Assert.That(() => db.FindById(12), Throws.InvalidOperationException);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: JobsService.cs プロジェクト: maxreb/teenkom
        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
                });
            }
        }
コード例 #10
0
        public void TestInvalidFetch()
        {
            PeopleBase db = new PeopleBase();

            Assert.That(() => db.Fetch(), Throws.InvalidOperationException);
        }
コード例 #11
0
        public void InvalidRemove()
        {
            PeopleBase db = new PeopleBase();

            Assert.That(() => db.Remove(), Throws.InvalidOperationException);
        }