public void LocationPostTest(IDictionary testData) { #region Arrange var currentEntity = new LocationDataObject(); var include = ""; var token = ""; currentEntity.IsNew = Convert.ToBoolean(testData["IsNew"].ToString()); if (!currentEntity.IsNew) { currentEntity.URI = testData["URI"].ToString().Trim() != null ? testData["URI"].ToString().Trim().ToString() : null; include = testData["Include"].ToString().Trim(); } currentEntity.Abstract = testData["Abstract"]?.ToString().Trim() != null ? testData["Abstract"]?.ToString().Trim().ToString() : null; currentEntity.Name = testData["Name"]?.ToString().Trim() != null ? testData["Name"]?.ToString().Trim().ToString() : null; var expected_result = ConvertToStatusCode(testData["Result"]); #endregion #region Act var json = JsonConvert.SerializeObject(currentEntity); var postUrl = APITestManager.doPostRequestBody(json, include); APIWebRequest request = new APIWebRequest(); var username = testData["Username"].ToString().Trim(); var password = testData["Password"].ToString().Trim(); token = request.getToken(APITestManager.getAuthenticateUrl(), username, password); using (var testResponse = request.ProcessAPIWebRequest(appUrl, APIWebRequest.TypeCall.Save, postUrl, token)) { var status_code = testResponse.StatusCode; var status_description = testResponse.Status; var response_body = testResponse.Body; #endregion #region Assert APITestManager.displayResponse(testResponse); Assert.AreEqual(expected_result, status_code); if (status_code == HttpStatusCode.OK) { // to be implemented } #endregion } }
private UsersDataObject fillUserDataObj(SqlCommand command) { SqlDataAdapter da = new SqlDataAdapter(command); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count == 0) return null; var user = new UsersDataObject(); DataRow userRow = ds.Tables[0].Rows[0]; user.Id = Int32.Parse(userRow["Id"].ToString()); user.ExternalID = userRow["ExternalID"].ToString(); user.Name = userRow["Name"].ToString(); user.DevicePassword = userRow["DevicePassword"].ToString(); user.Password = userRow["Password"].ToString(); user.ImageData = (byte[])(userRow["UserImage"] == DBNull.Value ? null : userRow["UserImage"]); user.IsAdministrator = userRow["IsAdministrator"] == DBNull.Value ? false : Convert.ToBoolean(userRow["IsAdministrator"].ToString()); user.IsDeviceAdministrator = userRow["IsDeviceAdministrator"] == DBNull.Value ? false : Convert.ToBoolean(userRow["IsDeviceAdministrator"].ToString()); user.UpdatedAt = userRow["UpdatedAt"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(userRow["UpdatedAt"]); user.IsActive = userRow["IsActive"] == DBNull.Value ? false : Convert.ToBoolean(userRow["IsActive"].ToString()); user.Fingers = new ObservableCollection<FingerDataObject>(); if (ds.Tables.Count > 1) { foreach (DataRow fingerRow in ds.Tables[1].Rows) { var finger = new FingerDataObject(); int fingerInd = Int32.Parse(fingerRow["FingerIndex"].ToString()); finger.FingerIndex = FingerDataObject.FingerCodeDescriptions[(FingerDataObject.FingerCode)fingerInd]; // fingerRow["FingerIndex"].ToString(); finger.Templates = new ObservableCollection<TemplateObject>(); foreach (DataRow templateRow in ds.Tables[2].Rows) { int templateFingerInd = Int32.Parse(templateRow["FingerIndex"].ToString()); if (templateFingerInd == fingerInd) { var template = new TemplateObject(); template.Id = templateRow["Id"] == DBNull.Value ? 0 : Int32.Parse(templateRow["Id"].ToString()); template.QualityScore = Int32.Parse(templateRow["QualityScore"].ToString()); template.Checksum = Int64.Parse(templateRow["Checksum"].ToString()); template.FingerIndex = templateFingerInd; template.UserID = Int32.Parse(templateRow["UserId"].ToString()); template.Data = (byte[])(templateRow["Data"] == DBNull.Value ? null : templateRow["Data"]); template.UpdatedAt = templateRow["UpdatedAt"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(userRow["UpdatedAt"]); finger.Templates.Add(template); } } user.Fingers.Add(finger); } user.FingersCount = user.Fingers.Count; } user.Cards = new ObservableCollection<CardDataObject>(); if (ds.Tables.Count > 3) { foreach (DataRow cardRow in ds.Tables[3].Rows) { var card = new CardDataObject(); card.Id = cardRow["Id"].ToString(); card.ExternalId = cardRow["ExternalId1"].ToString(); card.IsActive = cardRow["IsActive"] == DBNull.Value ? false : Convert.ToBoolean(cardRow["IsActive"].ToString()); card.IsBypass = cardRow["IsBypass"] == DBNull.Value ? false : Convert.ToBoolean(cardRow["IsBypass"].ToString()); card.BadgeNumber = cardRow["BadgeNumber"].ToString(); card.Priority = cardRow["Priority"] == DBNull.Value ? 0 : Int32.Parse(cardRow["Priority"].ToString()); card.FacilityCode = cardRow["FacilityCode"] == DBNull.Value ? 0 : Int64.Parse(cardRow["FacilityCode"].ToString()); card.PIN = cardRow["PIN"].ToString(); user.Cards.Add(card); } user.CardsCount = user.Cards.Count; } user.Locations = new ObservableCollection<LocationDataObject>(); if (ds.Tables.Count > 4) foreach (DataRow locationRow in ds.Tables[4].Rows) { var location = new LocationDataObject(); location.Id = locationRow["Id"].ToString(); location.Location = locationRow["Location"].ToString(); user.Locations.Add(location); } user.Properties = new ObservableCollection<PropertyDataObject>(); if (ds.Tables.Count > 5) foreach (DataRow propertyRow in ds.Tables[5].Rows) { var Property = new PropertyDataObject(); Property.ID = propertyRow["User_id"].ToString(); Property.Property = new KeyValuePair<string, string>(propertyRow["propertyName"].ToString(), propertyRow["propertyValue"].ToString()); user.Properties.Add(Property); } return user; }