TORONTO -- A man who went on a stabbing rampage at a Toronto office while being fired told officers arresting him that his victims deserved the attack, his trial heard this week.

But Chuang Li's lawyer plans to argue the 49-year-old was not criminally responsible for his actions.

Li is charged with three counts of attempted murder, four counts of aggravated assault and four counts of assault with a weapon.

Four people were taken to hospital, two of them with life-threatening injuries, after Li started stabbing people while he was in the process of being fired from the human resources company Ceridian Dayforce Corporation last April.

Li's lawyer, John Rosen, said he plans to argue his client should be found not criminally responsible.

An agreed statement of facts submitted at Li's trial revealed details of the attack, including what Li said as he was being led away.

"As he was being escorted to the police car, Mr. Li stated, 'They deserve it. They deserve it. You know, I don't care. They deserve it,"' it said.

Li, who was born in China and immigrated to Canada in 2001, became a Canadian citizen in 2005 and does not have a previous criminal record.

He had difficulties maintaining stable employment after arriving in Canada and was employed by 12 different companies between 2006 and 2012, the statement of facts said, noting that Li was hired by Ceridian as a software developer in June 2012.

Under questioning from a Crown-retained forensic psychiatrist, Li said he has, since a young age, "lost his temper on occasion and then later felt bad about it," the document said.

"Mr. Li told Dr. McMaster that sometimes he gets so angry that he does not think about the results," it said.

Li's wife first noticed her husband beginning to act strangely in 2009, saying "very funny things" about the people he worked with and sometime in 2011, began talking about an "organization" that was trying to "set him up," the document said.

Li's family doctor diagnosed him with depression in October 2011 and prescribed anti-depressants which Li did not take, court heard.

Li told the forensic psychiatrist he began carrying a saw with him in November 2012 because he felt unsafe in his neighbourhood, the statement of facts said.

In February 2013, Li also began carrying a large knife to work in his shoulder bag, saying he didn't feel safe at the office, and in June that year, he bought a pocket knife, which he also took to work, the statement of facts said.

Li then bought another knife in March 2014, which he kept in the trunk of his car and told his wife he though their house was bugged, court heard.

Ceridian decided to end Li's employment on April 9, 2014, and he was called into the office of human resources manager Rajsri De, where vice president of development, James Konandreas, began reviewing Li's performance issues.

Li began to yell "shut up" and hurl expletives, tried to grab a stapler and a nameplate from De's desk and then pulled out his pocket knife, court heard.

"Mr. Li began to stab at both Mr. Konandreas and Ms. De with the knife," the statement of facts said. "He stabbed and slashed Mr. Konandreas several times before Mr. Konandreas and Ms. De managed to escape from the office."

Li chased De, who was cornered in a hallway, slashing her face and hands, and stabbing her in the stomach, the document said. He then went after Konandreas, at which point another manager, Scott Berenthal tried to intervene, receiving a stab wound on the left side of his head.

Bryan Humphries, whose office was beside De's, saw the commotion and kicked Li, who then charged at him, stabbing him in the arm, before chasing Konandreas once more.

"After Mr. Konandreas collapsed, Mr. Li stood over top of him and continued to stab him. Mr. Konandreas attempted to use his arms and legs to protect himself. Mr. Konandreas pleaded for Mr. Li to stop ... Mr. Li continued to slash and stab at Mr. Konandreas," the statement of facts said.

Employees in a board room then tried to intervene, with one of them eventually convincing Li, in Mandarin, to surrender the knife, court heard.