Hi everyone this is my first post here so please be gentle.
I was recently granted the honor of my company to start getting to know the inner workings of NAV and now BC14 on-prem in order to be a better orderer for our dynamics partner. Being a C#-developer I soon became interested in getting to know how to code in C/AL and how to make configurations with out having to involve hour partner in every little small change we need to make.
We now have a need to calculate the price for our orders without actually creating a sales order. The creation of sales orders are handled by our accounting department at a later time, we would like to get an estimate price before that is done. In order to not create duplicate code that calculates the cost for our order and make maintaining this logic more of a nightmare than it already is, I would like to refactor the code into separate functions that can be called separately.
The current flow looks something like "Clickbutton to create sales order" -> CreateFilterForReport -> validate selection(ReportObject) -> more validation(CodeUnit) -> split order into calculatable parts(Same CodeUnit) -> calculate price and create salesorder intertwined(Same CodeUnit). And every step invokes the next, it's not like the are invoked one at a time. No the steps call upon each other to achive this.
I have no idea if it is considered good practice to build flows like this but I do know that this is fairly business critical, so I am not too keen on going to town tweaking this. Of course there are no unittests what so ever, so that is were I would like to start.
So to get to my question: Is it possible to mock calls to tables such as sales header and sales order line, so I can start refactoring this mess and still be certain things are executed in the way it is supposed to?
From what I have heard it is possible to set a variable in C/AL to be temporary and that the records written during the execution to be stored only in tempdb, but wouldn't that require me to somehow change the codeunits variable setting from non-temp to temp during the run of the unittest?