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); } } }
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!"); } } }
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); }
protected override async Task TestGetItem() { Uri uri = new Uri(FBaseUri, "StudentTimesInOut/123"); var response = await FClient.GetAsync(uri); await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed); }
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) }
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); }
protected override async Task TestGetAll() { Uri uri = new Uri(FBaseUri, "StudentExceptions"); var response = await FClient.GetAsync(uri); await CheckStatusCodeIs(response, HttpStatusCode.BadRequest); }
protected override async Task TestDelete() { Uri uri = new Uri(FBaseUri, "StudentTimesInOut/123"); var response = await FClient.DeleteAsync(uri.ToString()); await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }
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>()); }
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); } }
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); } }
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); } }
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>()); }
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); } }
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); } }
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(); }
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); } }
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); } }
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); } }
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); } }
/// <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); }
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!"); } }
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); } }