public async Task <Session> Login(UserModel user) { // Create Server endpoint Uri functionUri = new Uri(Server.BaseUri + Server.LoginEndpoint); // Create a json object for session JsonSession jsonSession = new JsonSession(user); // Serialize object to json string json = JsonConvert.SerializeObject(jsonSession); // Do post HttpResponseMessage response = await PostAsync(functionUri, json); string content = await response.Content.ReadAsStringAsync(); JsonSession jsonDataBack = new JsonSession(); if (response.IsSuccessStatusCode) { // Deserialize response received from Server jsonDataBack = JsonConvert.DeserializeObject <JsonSession>(content); return(new Session(jsonDataBack)); } else { JsonError jsonError = JsonConvert.DeserializeObject <JsonError>(content); //throw new HttpException(jsonError.Code, jsonError.Status, jsonError.Message); } return(new Session(new JsonSession())); }
public void JsonSessionObjectToJsonTest() { TemplateJson tl = new JsonSession(); var json = tl.GetJson(new Session(40, "Johnathan", false)); Assert.AreEqual(correctJson, json); }
public void Start() { Task.Run(() => { while (!this.socketCancellation.IsCancellationRequested) { var acceptTcpClienTask = tcpListener.AcceptTcpClientAsync(); acceptTcpClienTask.Wait(this.socketCancellation.Token); Console.WriteLine("[Server] Client has connected"); var tcpClient = acceptTcpClienTask.Result; var session = new JsonSession(tcpClient.GetStream(), onMessage); try { session.Start(); } catch (Exception ex) { if (ex is OperationCanceledException) { Console.WriteLine("Timed out listening for message. Opening up for accepting a new one."); } else { Console.WriteLine("Unhandled exception " + ex.Message); } } } }); }
public void JsonSessionJsonToObjectTest() { TemplateJson tl = new JsonSession(); var o = tl.GetObject(correctJson) as Session; Assert.AreEqual("Johnathan", o.GetUsername()); Assert.AreEqual(false, o.GetAdmin()); Assert.AreEqual(40, o.GetSessionID()); }
public void JsonSessionObjectToJsonInvalidTest() { bool exception = false; TemplateJson tl = new JsonSession(); try { var json = tl.GetJson("I am the wrong object"); } catch (InvalidLoginObjectException) { exception = true; } Assert.IsTrue(exception); }
protected override void ThreadMethod() { try { var response = GetJsonResponse(new JsonLogin(), new HttpPostLogin(), information); var sessionJson = new JsonSession(); sessionKey = sessionJson.GetObject(response) as Session; ThreadComplete(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.StackTrace); sessionKey = null; ThreadComplete(false); } }
public void JsonSessionJsonToObjectInvalidTest() { bool exception = false; var incorrect = "{\"emails\":\"[email protected]\",\"password\":\"Password\"}"; TemplateJson tl = new JsonSession(); try { var o = tl.GetObject(incorrect) as Session; } catch (InvalidLoginJsonException) { exception = true; } Assert.IsTrue(exception); }
public void Session_ParseSessionValues() { var session = new JsonSession { CreatedAt = DateTime.UtcNow, Duration = TimeSpan.FromDays(1), Values = new Dictionary<string, string> { { "FirstName", "Schmulik" }, { "LastName", "Raskin" } } }; var serializer = new JsonSerializer(); var output = new StringWriter(); serializer.Serialize(new JsonTextWriter(output), session); Console.WriteLine(output.ToString()); var result = serializer.Deserialize<JsonSession>(new JsonTextReader(new StringReader(output.ToString()))); Assert.AreEqual(session.CreatedAt, result.CreatedAt); Assert.AreEqual(session.Duration, result.Duration); Assert.AreEqual(session.Values.Count, result.Values.Count); }
public Session(JsonSession session) { Id = session.Id; SessionKey = session.SessionKey; User = new UserModel(session.User); }
public static void Main(string[] args) { var helloIAm = new CP2013_WordOfMouth.DTO.AppointmentType(1, "Clean my teeth", 100); var jsonApointment = new JsonAppointmentAddType().GetJson(helloIAm); var test = PostRequests(new HttpPostAddAppointmentType(), jsonApointment); var Login = new Login("*****@*****.**", "Password"); var json = new JsonLogin().GetJson(Login); var something = PostRequests(new HttpPostLogin(), json); var newSession = new JsonSession().GetObject(something) as Session; var dentistser = GetRequests(new HttpGetAllDentist(), new JsonAllDentists(), "") as List <Dentist>; var allAvaliable = GetRequests(new HttpGetAllAvaliableTimes(), new JsonDentistTimeSlots(), ""); // foreach (var d in dentistser) // { var stuffed = PostRequests(new HttpGetBookingsForDentist(), 2.ToString()); var objectsAreGood = new JsonAppointments().GetObject(stuffed) as List <Appointment>; // } var dentistperson = new Dentist(0, "Dentist New", "*****@*****.**", "0412345678"); var jd = new JsonDentistEditAdd(); var json2 = jd.GetJson(dentistperson); var stuff = PostRequests(new HttpPostAddDentist(), json2); dentistser = GetRequests(new HttpGetAllDentist(), new JsonAllDentists(), "") as List <Dentist>; var i = dentistser.Count - 1; dentistperson = new Dentist(i, "Dentist New", "*****@*****.**", "0412345678"); jd = new JsonDentistEditAdd(); json2 = jd.GetJson(dentistperson); stuff = PostRequests(new HttpPostEditDentist(), json2); GetRequests(new HttpGetDentist(), new JsonDentist(), 1.ToString()); GetRequests(new HttpGetAppointments(), new JsonAppointments(), newSession.GetSessionID().ToString()); var timeSlots = GetRequests(new HttpGetDentistTimeSlots(), new JsonDentistTimeSlots(), 2.ToString()); var apps = GetRequests(new HttpGetAllAppointmentTypes(), new JsonAllAppointmentTypes(), ""); var deleteAppointment = new HttpPostDeleteAppointment(); deleteAppointment.SendRequest(1.ToString()); var response = deleteAppointment.GetResponse(); //var Login = new Login("*****@*****.**", "Password"); //var json = new JsonLogin().GetJson(Login); PostRequests(new HttpPostDeleteDentist(), 37.ToString()); #region OLDMAIN var login = new OldLogin("*****@*****.**", "Password"); var session = rr.Login(login); var dentists = rr.GetAllDentists(); var dentist = rr.GetDentist(dentists[0].id); // var timeSlots = rr.GetAllTimeSlots(); Console.WriteLine(timeSlots); rr.GetTimeSlotsForDentist(dentists[0].id); Console.WriteLine(dentists); fileHandler = new MOCKFileHandler(); var key = GetStringFromOutput(MENU); while (key != "q") { switch (key) { case "1": UserUI(); break; case "2": AdminUI(); break; default: Console.WriteLine("unknown error"); break; } key = GetStringFromOutput(MENU); } #endregion }
public void Setup() { session = new JsonSession(); }