Ejemplo n.º 1
0
    public WaitingRoomInfo(FWaitingRoom data)
    {
        city       = data.City;
        host       = data.Host;
        maxClients = data.ClientsMax;

        if (data.TeamsLength != 2)
        {
            Debug.LogError($"There are {data.TeamsLength} teams!");
            throw new Exception($"There are {data.TeamsLength} teams!");
        }

        teams = new Player[2][];
        for (int i = 0; i < 2; i++)
        {
            int size = data.Teams(i).Value.ClientsLength;
            teams[i] = new Player[size];
            for (int j = 0; j < size; j++)
            {
                FClient player = data.Teams(i).Value.Clients(j).Value;
                teams[i][j].id      = player.Id;
                teams[i][j].name    = player.Name;
                teams[i][j].Vehicle = GetVehicle(player.Vehicle.Value.VehicleType);
            }
        }
    }
Ejemplo n.º 2
0
        private async Task FilterTest2()
        {
            int studentSelected;
            int weekSelected;

            Uri uri = GetUriWithFilterAdded(new Uri(FBaseUri, "StudentMarks"),
                                            CreateMarksFilterByStudent(out studentSelected, out weekSelected));

            var response = await FClient.GetAsync(uri);

            await CheckSuccessStatusCode(response);

            var items = await response.Content.ReadAsAsync <StudentMarks[]>();

            foreach (var sm in items)
            {
                if (sm.Week != weekSelected)
                {
                    throw new Exception("Unexpected week!");
                }
                if (sm.StudentId != studentSelected)
                {
                    throw new Exception("Unexpected student Id!");
                }
            }
        }
Ejemplo n.º 3
0
        protected override async Task TestPutAtRoot()
        {
            Uri uri      = new Uri(FBaseUri, "StudentLedger");
            var response = await FClient.PutAsJsonAsync(uri.ToString(), FLedgers[0]);

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 4
0
        protected override async Task TestGetItem()
        {
            Uri uri      = new Uri(FBaseUri, "StudentTimesInOut/123");
            var response = await FClient.GetAsync(uri);

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 5
0
        protected override async Task TestGetAll()
        {
            Uri uri      = new Uri(FBaseUri, "OLAStaging");
            var response = await FClient.GetAsync(uri);

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed); // not BadRequest since there is no way to use GET on root (there is no way to specify a filter for example)
        }
Ejemplo n.º 6
0
        protected override async Task TestDelete()
        {
            Uri uri      = new Uri(FBaseUri, string.Format("StudentMarks/{0}", FStudentMarks[0].GetId()));
            var response = await FClient.DeleteAsync(uri.ToString());

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 7
0
        protected override async Task TestGetAll()
        {
            Uri uri      = new Uri(FBaseUri, "StudentExceptions");
            var response = await FClient.GetAsync(uri);

            await CheckStatusCodeIs(response, HttpStatusCode.BadRequest);
        }
Ejemplo n.º 8
0
        protected override async Task TestDelete()
        {
            Uri uri = new Uri(FBaseUri, "StudentTimesInOut/123");

            var response = await FClient.DeleteAsync(uri.ToString());

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 9
0
        protected override async Task TestPost()
        {
            var reg      = FRegisters[0];
            Uri uri      = new Uri(FBaseUri, "Registers");
            var response = await FClient.PostAsJsonAsync(uri.ToString(), reg);

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 10
0
        protected override async Task TestGetNonExistingItem()
        {
            const string BAD_ID   = "12345678";
            Uri          uri      = new Uri(FBaseUri, string.Format("MarkDefinitions/{0}", BAD_ID));
            var          response = await FClient.GetAsync(uri);

            await CheckStatusCodeIs(response, HttpStatusCode.NotFound);
        }
Ejemplo n.º 11
0
        protected override async Task TestDeleteNonExistingItem()
        {
            const string BAD_ID   = "12345678";
            Uri          uri      = new Uri(FBaseUri, string.Format("StudentExceptions/{0}", BAD_ID));
            var          response = await FClient.DeleteAsync(uri.ToString());

            await CheckStatusCodeIs(response, HttpStatusCode.NotFound);
        }
Ejemplo n.º 12
0
        protected override async Task TestDeleteNonExistingItem()
        {
            const string BAD_ID   = "12345678";
            Uri          uri      = new Uri(FBaseUri, string.Format("RegisterSummaries/{0}", BAD_ID));
            var          response = await FClient.DeleteAsync(uri.ToString());

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 13
0
        protected override async Task TestPut()
        {
            Uri uri = new Uri(FBaseUri, "StudentTimesInOut/ABC");

            var t        = new SimpleStudentTimesPoco();
            var response = await FClient.PutAsJsonAsync(uri.ToString(), t);

            await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
        }
Ejemplo n.º 14
0
        protected async Task TestGetItemBadRegNumber()
        {
            // nb - here we supply an invalid reg number (week 74!)
            const string BAD_ID   = "12345674";
            Uri          uri      = new Uri(FBaseUri, string.Format("Registers/{0}", BAD_ID));
            var          response = await FClient.GetAsync(uri);

            await CheckStatusCodeIs(response, HttpStatusCode.InternalServerError);
        }
Ejemplo n.º 15
0
 protected override async Task TestDelete()
 {
     // remove the newly inserted defs...
     foreach (var md in FNewlyInsertedOLAMarks)
     {
         Uri uri      = new Uri(FBaseUri, string.Format("OLAStaging/{0}", md.GetId()));
         var response = await FClient.DeleteAsync(uri.ToString());
         await CheckStatusCodeIs(response, HttpStatusCode.NoContent);
     }
 }
Ejemplo n.º 16
0
        private async Task <MarkDefinition> GetItem(string defId)
        {
            Uri uri = new Uri(FBaseUri, string.Format("MarkDefinitions/{0}", defId));

            var response = await FClient.GetAsync(uri);

            await CheckSuccessStatusCode(response);

            return(await response.Content.ReadAsAsync <MarkDefinition>());
        }
Ejemplo n.º 17
0
 protected override async Task TestPut()
 {
     if (FStudentMarks.Count > 0)
     {
         var sm       = FStudentMarks[0];
         Uri uri      = new Uri(FBaseUri, string.Format("StudentMarks/{0}", sm.GetId()));
         var response = await FClient.PutAsJsonAsync(uri.ToString(), sm);
         await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
     }
 }
Ejemplo n.º 18
0
 protected override async Task TestDelete()
 {
     if (FRegisters.Count > 0)
     {
         var reg      = FRegisters[0];
         Uri uri      = new Uri(FBaseUri, string.Format("Registers/{0}", reg.GetId()));
         var response = await FClient.DeleteAsync(uri.ToString());
         await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
     }
 }
Ejemplo n.º 19
0
 protected override async Task TestDelete()
 {
     // remove the newly inserted exceptions...
     foreach (var e in FNewlyInsertedExceptions)
     {
         Uri uri      = new Uri(FBaseUri, string.Format("StudentExceptions/{0}", e.GetId()));
         var response = await FClient.DeleteAsync(uri.ToString());
         await CheckStatusCodeIs(response, HttpStatusCode.NoContent);
     }
 }
Ejemplo n.º 20
0
        private async Task <RegisterSummary> TestGetIndividualRegisterSummary(string id)
        {
            Uri uri = GetUriWithFilterAdded(new Uri(FBaseUri, string.Format("RegisterSummaries/{0}", id)), CreateRegisterSummariesFilterBasic());

            var response = await FClient.GetAsync(uri);

            await CheckSuccessStatusCode(response);

            return(await response.Content.ReadAsAsync <RegisterSummary>());
        }
Ejemplo n.º 21
0
        protected override async Task TestPostDuplicate()
        {
            if (FNewlyInsertedOLAMarks.Count > 0)
            {
                Uri uri = new Uri(FBaseUri, "OLAStaging");

                // try to add a defn that already exists...
                var md       = FNewlyInsertedOLAMarks[0];
                var response = await FClient.PostAsJsonAsync(uri.ToString(), md);
                await CheckStatusCodeIs(response, HttpStatusCode.InternalServerError);
            }
        }
Ejemplo n.º 22
0
        protected override async Task TestPutAtRoot()
        {
            if (FNewlyInsertedDefinitions.Count > 0)
            {
                var md = FNewlyInsertedDefinitions[0];
                md.Description = GetRandomString(50, true);

                Uri uri      = new Uri(FBaseUri, "MarkDefinitions");
                var response = await FClient.PutAsJsonAsync(uri.ToString(), md);
                await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
            }
        }
Ejemplo n.º 23
0
        protected override async Task TestGetNonExistingItem()
        {
            // nb - last 2 digits represent week number
            {
                const string BAD_ID   = "12345604";
                Uri          uri      = new Uri(FBaseUri, string.Format("Registers/{0}", BAD_ID));
                var          response = await FClient.GetAsync(uri);
                await CheckStatusCodeIs(response, HttpStatusCode.NotFound);
            }

            await TestGetItemBadRegNumber();
        }
Ejemplo n.º 24
0
        protected override async Task TestPutAtRoot()
        {
            if (FRegisters.Count > 0)
            {
                var reg = FRegisters[0];
                reg.Modified = true;

                Uri uri      = new Uri(FBaseUri, "Registers");
                var response = await FClient.PutAsJsonAsync(uri.ToString(), reg);
                await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
            }
        }
Ejemplo n.º 25
0
        protected override async Task TestPutAtRoot()
        {
            if (FNewlyInsertedOLAMarks.Count > 0)
            {
                var m = FNewlyInsertedOLAMarks[0];
                m.Session = FRandom.Next();

                Uri uri      = new Uri(FBaseUri, "OLAStaging");
                var response = await FClient.PutAsJsonAsync(uri.ToString(), m);
                await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
            }
        }
Ejemplo n.º 26
0
        protected override async Task TestPut()
        {
            if (FRegSummaries.Count > 0)
            {
                var summary = FRegSummaries[0];
                summary.StartDateTime = summary.StartDateTime.AddHours(-1);

                Uri uri      = new Uri(FBaseUri, string.Format("RegisterSummaries/{0}", summary.GetId()));
                var response = await FClient.PutAsJsonAsync(uri.ToString(), summary);
                await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
            }
        }
Ejemplo n.º 27
0
        protected override async Task TestPutAtRoot()
        {
            if (FNewlyInsertedExceptions.Count > 0)
            {
                var e = FNewlyInsertedExceptions[0];
                e.Comments = GetRandomString(50, true);
                e.Modified = true;

                Uri uri      = new Uri(FBaseUri, "StudentExceptions");
                var response = await FClient.PutAsJsonAsync(uri.ToString(), FNewlyInsertedExceptions[0]);
                await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="host">MongoDB 数据库连接主机地址</param>
        /// <param name="port">MongoDB 数据库连接端口号</param>
        /// <param name="timeout">MongoDB 数据库连接超时时间</param>
        /// <param name="dbName">MongoDB 数据库名称</param>
        /// <returns>MongoDatabase 实例对象</returns>
        public MongoDBHandler(string host, int port, int timeout, string dbName)
        {
            this.MongoConnectionHost    = host;
            this.MongoConnectionPort    = port;
            this.MongoConnectionTimeout = timeout;
            this.MongoDatabaseName      = dbName;
            MongoClientSettings mongoSetting = new MongoClientSettings();

            mongoSetting.ConnectTimeout = new TimeSpan(this.MongoConnectionTimeout * TimeSpan.TicksPerSecond);
            mongoSetting.Server         = new MongoServerAddress(this.MongoConnectionHost, this.MongoConnectionPort);
            this.FClient   = new MongoClient(mongoSetting);
            this.FDatabase = FClient.GetServer().GetDatabase(dbName);
        }
Ejemplo n.º 29
0
        protected override async Task TestGetItem()
        {
            IEnumerable <string> regIds = await GetRegisterIds();

            // store some registers for use in later test...
            FRegisters = new List <Register>();

            int numWithActivities    = 0;
            int numWithoutActivities = 0;

            foreach (var regId in regIds)
            {
                Uri uri = new Uri(FBaseUri, string.Format("Registers/{0}", regId));

                var response = await FClient.GetAsync(uri);
                await CheckSuccessStatusCode(response);

                var reg = await response.Content.ReadAsAsync <Register>();

                Trace.Assert(reg.GetId() == regId);

                // ensure that we get some registers with activities and some without...

                if (reg.ActivityId > 0)
                {
                    if (numWithActivities < MAX_REG_COUNT / 2)
                    {
                        ++numWithActivities;
                        FRegisters.Add(reg);
                    }
                }
                else
                {
                    if (numWithoutActivities < MAX_REG_COUNT / 2)
                    {
                        ++numWithoutActivities;
                        FRegisters.Add(reg);
                    }
                }

                if (numWithActivities + numWithoutActivities == MAX_REG_COUNT)
                {
                    break;
                }
            }

            if (FRegisters.Count == 0)
            {
                throw new Exception("Could not find any registers for test!");
            }
        }
Ejemplo n.º 30
0
        protected override async Task TestPost()
        {
            FNewlyInsertedExceptions = new List <ExceptionMark>();

            int numIters = FRandom.Next(4, 10);

            for (int i = 0; i < numIters; ++i)
            {
                int markId = GetMarkId();

                var em = new ExceptionMark
                {
                    ExceptionType     = AttExceptionType.CetExtendedAbsence,
                    MarkId            = markId,
                    Comments          = GetRandomString(FRandom.Next(1, 129), true),
                    StudentExceptions = new List <StudentException>(),
                    Modified          = true
                };

                em.StartDateTime = GetRandomStartDate();
                em.EndDateTime   = em.StartDateTime.AddDays(FRandom.Next(1, 60));

                int        numStudents  = FRandom.Next(1, 6);
                List <int> studentsUsed = new List <int>();
                for (int n = 0; n < numStudents; ++n)
                {
                    int studentId = GetRandomStudentId();
                    if (!studentsUsed.Contains(studentId))
                    {
                        em.StudentExceptions.Add(new StudentException
                        {
                            StudentId = studentId,
                            Modified  = true
                        });

                        studentsUsed.Add(studentId);
                    }
                }

                Uri uri      = new Uri(FBaseUri, "StudentExceptions");
                var response = await FClient.PostAsJsonAsync(uri.ToString(), em);
                await CheckStatusCodeIs(response, HttpStatusCode.Created);

                var se = await response.Content.ReadAsAsync <ExceptionMark>();

                se.CheckSameValues(em);

                FNewlyInsertedExceptions.Add(se);
            }
        }