/// <summary> /// If the request parameters other than @InCaller & @InCallerversion are null, returns a list of entries, otherwise returns a list of one entry. /// </summary> /// <param name="request"></param> /// <returns></returns> public static ApplicationsGetReplyDC ApplicationsGet(ApplicationsGetRequestDC request) { var reply = new ApplicationsGetReplyDC(); var status = new StatusReplyDC(); ApplicationGetBase app = null; var list = new List<ApplicationGetBase>(); Database db = null; DbCommand cmd = null; int retValue = 0; string outErrorString = string.Empty; try { db = DatabaseFactory.CreateDatabase(); cmd = db.GetStoredProcCommand(StoredProcNames.ApplicationGet); db.AddParameter(cmd, "@inCaller", DbType.String, ParameterDirection.Input, null, DataRowVersion.Default, request.Incaller); db.AddParameter(cmd, "@inCallerVersion", DbType.String, ParameterDirection.Input, null, DataRowVersion.Default, request.IncallerVersion); db.AddParameter(cmd, "@InId", DbType.Int32, ParameterDirection.Input, null, DataRowVersion.Default, request.InId); db.AddParameter(cmd, "@InName", DbType.String, ParameterDirection.Input, null, DataRowVersion.Default, request.InName); db.AddParameter(cmd, "@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue, null, DataRowVersion.Default, 0); db.AddOutParameter(cmd, "@outErrorString", DbType.String, 300); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { app = new ApplicationGetBase(); app.Guid = (Guid)reader["GUID"]; app.Description = Convert.ToString(reader["Description"]) ?? string.Empty; app.Id = Convert.ToInt32(reader["Id"]); app.Name = Convert.ToString(reader["Name"]); list.Add(app); } reply.List = list; } retValue = Convert.ToInt32(cmd.Parameters["@ReturnValue"].Value); outErrorString = Convert.ToString(cmd.Parameters["@outErrorString"].Value); if (retValue != 0) { status.ErrorMessage = Convert.ToString(cmd.Parameters["@outErrorString"].Value); status.Errorcode = retValue; Logging.Log(retValue, EventLogEntryType.Error, SprocValues.APPLICATIONS_GET_CALL_ERROR_MSG, outErrorString); } } catch (Exception ex) { status = Logging.Log(SprocValues.GENERIC_CATCH_ID, EventLogEntryType.Error, SprocValues.APPLICATIONS_GET_CALL_ERROR_MSG, ex); } reply.StatusReply = status; return reply; }
/// <summary> /// Verify GET FROM ltblApplications Table for Invalid IDs /// </summary> /// <param name="id">id of row to do a get on</param> private void GetApplicationForInvalidIDAndValidate(int id) { bool isFaultException = false; getRequest = new ApplicationsGetRequestDC(); getReply = null; //Populate the request data getRequest.Incaller = IN_CALLER; getRequest.IncallerVersion = IN_CALLER_VERSION; getRequest.InId = id; try { getReply = devBranchProxy.ApplicationsGet(getRequest); } // Task 20943. Add fault exception validation. //catch (FaultException<www.microsoft.com.practices.EnterpriseLibrary._2007._01.wcf.validation.ValidationFault> exc) //{ // if (id < 0) // { // Assert.IsNotNull(exc.Detail.Details); // Assert.AreEqual(1, exc.Detail.Details.Count); // Assert.IsNotNull(exc.Detail.Details[0].Message); // Assert.AreEqual(CWF.Constants.SprocValues.INVALID_PARMETER_VALUE_INID_MSG, exc.Detail.Details[0].Message); // isFaultException = true; // } // else // { // Assert.Fail("Failed to get data from ltblApplications: {0}", exc.Message); // } //} catch (FaultException e) { Assert.Fail("Failed to get data from ltblApplications: {0}", e.Message); } catch (Exception ex) { Assert.Fail("Failed to get data from ltblApplication: {0}", ex.Message); } if (!isFaultException) { int errorConstant = GetErrorConstantInvalidID(id); Assert.IsNotNull(getReply, "getReply is null"); Assert.IsNotNull(getReply.StatusReply, "getReply.Status is null"); Assert.AreEqual(errorConstant, getReply.StatusReply.Errorcode, "Returned the wrong status error code. InId: {0}", id); Assert.IsNotNull(getReply.List); Assert.AreEqual(0, getReply.List.Count, "Get returned the wrong number of entries. InId: {0}. It should not have returned 0 and instead returned {1}", id, getReply.List.Count); } }
/// <summary> /// Verify GET FROM ltblApplications Table for invalid names /// </summary> /// <param name="name">name from row to do a get on</param> /// <returns>returns the id of this row</returns> private void VerifyGetApplicationForInvalidName(string name) { getRequest = new ApplicationsGetRequestDC(); getReply = null; //Populate the request data getRequest.Incaller = IN_CALLER; getRequest.IncallerVersion = IN_CALLER_VERSION; getRequest.InName = name; try { getReply = devBranchProxy.ApplicationsGet(getRequest); } catch (FaultException e) { Assert.Fail("Failed to get data from ltblApplications: {0}", e.Message); } catch (Exception ex) { Assert.Fail("Failed to get data from ltblApplication: {0}", ex.Message); } Assert.IsNotNull(getReply, "getReply is null"); Assert.IsNotNull(getReply.StatusReply, "getReply.StatusReply is null"); Assert.AreEqual(SprocValues.GET_INVALID_NAME, getReply.StatusReply.Errorcode, "Status reply error code is not {0}. Instead it is {1}.", SprocValues.GET_INVALID_NAME, getReply.StatusReply.Errorcode); }
/// <summary> /// Verify GET FROM ltblApplications Table for a valid name /// </summary> /// <param name="name">name from row to do a get on</param> /// <returns>returns the id of this row</returns> private int GetApplicationForValidNameAndValidateForMaxID(string name) { getRequest = new ApplicationsGetRequestDC(); getReply = null; //Populate the request data getRequest.Incaller = IN_CALLER; getRequest.IncallerVersion = IN_CALLER_VERSION; getRequest.InName = name; try { getReply = devBranchProxy.ApplicationsGet(getRequest); } catch (FaultException e) { Assert.Fail("Failed to get data from ltblApplications: {0}", e.Message); } catch (Exception ex) { Assert.Fail("Failed to get data from ltblApplication: {0}", ex.Message); } Assert.IsNotNull(getReply, "getReply is null"); Assert.IsNotNull(getReply.StatusReply, "getReply.StatusReply is null"); Assert.AreEqual(0, getReply.StatusReply.Errorcode, "Status reply error code is not 0. Instead it is {0}.", getReply.StatusReply.Errorcode); Assert.IsNotNull(getReply.List, "getReply.List is null"); Assert.AreNotEqual(0, getReply.List.Count, "Get returned the wrong number of entries. InName: {0}. It should have returned {1} but instead returned 0.", name, getReply.List.Count); int index = getReply.List.Count - 1; int id = getReply.List[index].Id; return id; }
/// <summary> /// Verify GET FROM ltblApplications Table for Valid IDs /// </summary> /// <param name="id">id of row to do a get on</param> private void GetApplicationForValidIDAndValidate(int id) { getRequest = new ApplicationsGetRequestDC(); getReply = null; //Populate the request data getRequest.Incaller = IN_CALLER; getRequest.IncallerVersion = IN_CALLER_VERSION; getRequest.InId = id; try { getReply = devBranchProxy.ApplicationsGet(getRequest); } catch (FaultException e) { Assert.Fail("Failed to get data from ltblApplications: {0}", e.Message); } catch (Exception ex) { Assert.Fail("Failed to get data from ltblApplication: {0}", ex.Message); } Assert.IsNotNull(getReply, "getReply is null"); Assert.IsNotNull(getReply.StatusReply, "getReply.StatusReply is null"); Assert.AreEqual(0, getReply.StatusReply.Errorcode, "Status reply error code is not 0. Instead it is {0}.", getReply.StatusReply.Errorcode); Assert.IsNotNull(getReply.List, "getReply.List is null"); Assert.AreEqual(1, getReply.List.Count, "Get returned the wrong number of entries. InId: {0}. It should have returned 1 but instead returned {1}.", id, getReply.List.Count); //Assert.AreEqual(getRequest.InId, getReply.List[0].Id, "Get returned wrong data. Expected id: {0}. Actual: {1}", getRequest.InId, getReply.List[0].Id); }
/// <summary> /// Verify GET FROM ltblApplications Table for softDeleted IDs /// </summary> /// <param name="softDeletedID">id of row to do a get on</param> private void GetApplicationForSoftDeletedIDs(int softDeletedID) { getRequest = new ApplicationsGetRequestDC(); getReply = null; //Populate the request data getRequest.Incaller = IN_CALLER; getRequest.IncallerVersion = IN_CALLER_VERSION; getRequest.InId = softDeletedID; try { getReply = devBranchProxy.ApplicationsGet(getRequest); } catch (FaultException e) { Assert.Fail("Failed to get data from ltblApplications: {0}", e.Message); } catch (Exception ex) { Assert.Fail("Failed to get data from ltblApplication: {0}", ex.Message); } int errorConstant = GetErrorConstantSoftDeletedID(); Assert.IsNotNull(getReply, "getReply is null"); Assert.IsNotNull(getReply.List); Assert.AreEqual(0, getReply.List.Count, "Get returned the wrong number of entries. InId: {0}. It should have returned 0.", softDeletedID); Assert.IsNotNull(getReply.StatusReply, "getReply.Status is null"); Assert.AreEqual(errorConstant, getReply.StatusReply.Errorcode, "Returned the wrong status error code. InId: {0}. Expected {1}. Actual {2}", softDeletedID, errorConstant, getReply.StatusReply.Errorcode); }
/// <summary> /// Verify GET FROM ltblApplications Table for Null InCaller /// </summary> /// <param name="id">id of row to do a get on</param> private void GetApplicationForNullInCallerAndValidate(int id) { bool isFaultException = false; getRequest = new ApplicationsGetRequestDC(); getReply = null; //Populate the request data getRequest.InId = id; try { getReply = devBranchProxy.ApplicationsGet(getRequest); } // Task 20943. Add fault exception validation. //catch (FaultException<www.microsoft.com.practices.EnterpriseLibrary._2007._01.wcf.validation.ValidationFault> exc) //{ // Assert.IsNotNull(exc.Detail.Details); // Assert.AreEqual(2, exc.Detail.Details.Count); // Assert.IsNotNull(exc.Detail.Details[0].Message); // Assert.AreEqual(exc.Detail.Details[0].Message, INCALLER_IS_NULL_FAULT_EXCEPTION_MESSAGE); // Assert.IsNotNull(exc.Detail.Details[1].Message); // Assert.AreEqual(exc.Detail.Details[1].Message, INCALLERVERSION_IS_NULL_FAULT_EXCEPTION_MESSAGE); // isFaultException = true; //} catch (FaultException e) { Assert.Fail("Failed to get data from ltblApplications: {0}", e.Message); } catch (Exception ex) { Assert.Fail("Failed to get data from ltblApplication: {0}", ex.Message); } if (isFaultException) { Assert.IsNull(getReply); Assert.IsTrue(isFaultException); } }