public void TestPackageandDeliveryFail() { var packagerepo = new PackageDelivery(testContextmock.Object); string result = packagerepo.PackageDeliver("Accessory", 10); Assert.AreNotEqual("400", result); }
/// <summary> /// Inserts a new Package to the database and returns the Id. /// </summary> public int InsertIntoPackage(PackageDelivery package, Guid requestId) { LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.DataLayer.SqlManager: incoming InsertIntoPackage with RequestId: {0}", requestId)); //Save Message to database. var sqlCommand = GetSqlCommandAsStoredProcedure("InsertIntoPackage"); var returnId = 0; try { using (sqlCommand) { sqlCommand.Parameters.Add(GetSqlParameter(System.Data.SqlDbType.NVarChar, "Sender", package.Sender)); sqlCommand.Parameters.Add(GetSqlParameter(System.Data.SqlDbType.NVarChar, "Recipient", package.Recipient)); sqlCommand.Parameters.Add(GetSqlParameter(System.Data.SqlDbType.DateTime, "CreatedDate", package.CreatedDate)); sqlCommand.Parameters.Add(GetSqlParameter(System.Data.SqlDbType.NVarChar, "MessageStatus", package.PackageStatus.ToString())); sqlCommand.Parameters.Add(GetSqlParameter(System.Data.SqlDbType.UniqueIdentifier, "RequestId", requestId)); sqlCommand.Parameters.Add(GetOutputSqlParameter(SqlDbType.Int, "Id", 0)); sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); returnId = int.Parse(sqlCommand.Parameters["Id"].Value.ToString()); if (returnId == 0) { throw new ArgumentException("SE.GOV.MM.Integration.Package.DataLayer.SqlManager: Something went wrong saving a new post in the database, no new Id was returned.."); } } } catch (Exception e) { var errorMessage = string.Format("SE.GOV.MM.Integration.Package.DataLayer.SqlManager: Error saving Message to database. Recipient: {0}, RequestId: {1}", package.Recipient, requestId); LogManager.Log(new Log.Log() { EventId = EventId.SqlDatabaseExceptionWriting, Exception = e, Level = Level.Error, Message = errorMessage }); throw e; } finally { if (sqlCommand.Connection.State != System.Data.ConnectionState.Closed) { sqlCommand.Connection.Close(); } } LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.DataLayer.SqlManager: leaving InsertIntoPackage with RequestId: {0}", requestId)); return(returnId); }
/// <summary> /// Creates and saves a PackageDelivery in database. /// </summary> public int SavePackage(string recipient, string sender, PackageStatus status, Guid requestId) { LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Handler.PackageHandler: incoming SavePackage with RequestId: {0}", requestId)); var package = new PackageDelivery() { Recipient = recipient, CreatedDate = DateTime.Now, Sender = sender, PackageStatus = status }; var id = _sqlManager.InsertIntoPackage(package, requestId); LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.Package.BusinessLayer.Handler.PackageHandler: leaving SavePackage with RequestId: {0}", requestId)); return(id); }