Is there a design pattern for validation? - c#-4.0

Is there any adequate design pattern that should be used in order to do number of validations?
For example, let's say that I have an application containing a toolbar with icons, each representing a picture on my file system. I am dragging an icon on a document. Validations during the drag and drop operation could be:
check if the file exists in file system
check if the user has access rights to drag the icon
check that the document is open in order to drop the picture on it
and so on...
I thought of using the Chain of Responsibility or Decorator patterns.
Thanks!

Actually, what you're after, or rather what I'd suggest, is Continuation Passing Style. It's not so much a design pattern as a way of writing code where validation would be defined as a pipeline of methods that an object would go through. This pipeline would use an accumulator to collect all the validation problems encountered by the code.

Related

Saving textbox value from a test execution in Ranorex

I am automating Sharepoint list testing, filling up some field with values,
and like to save data I supplied to the field after.
Is there a way to automate saving the field value in a excel or csv?
In order to keep it simple, I would create two recordings and write to a text file (csv).
The first one would get the text values from the desired fields and return them in bound variables using Ranorex GetValue action.
The second recording would write the content of the bound variables to a text file, separating fields with ',' (or any other character that is suitable for the kind of data that is present in the fields) in a user code function.
If you have no idea how to write to a file in .NET, take a look at System.IO.File.AppendAllLines or similar functions.
You could also combine the 2 recordings in one, but then, re-useability would be limited the scope of the SharePoint page you are testing.
Do not forget that since Ranorex is using the .NET framework, you have access to all the functions provided by the framework in user code. With Ranorex, the usual question is not ask if something is possible. The real question is "how can it be done" and is the solution simple enough for testers to be able to use it!
Hope this helps!

UML Activity Diagram for android project

I have created the below diagram and I wanted to know if the diagram that I have done is correct.
The below diagram is based on an android application. When the application loads the user is given 3 button to select add, update and help. On click on add button the user is given an option to add a new user or add a new item. When he select either of the options he enters the required data once the data is entered the system check if all the values are entered correctly and then finally saved. The same process is applied for update.
Your diagram misses an entry point. Though it's rather obvious that the top action is the start, only the entry point is the one indicating the beginning.
You can omit most of the diamonds and directly transfer via a guard from actions. So your conditions should be guards and written as [Yes] or [No]. The top most action (and quite some others) is(/are) indeed what should be written inside (or aside) the diamond below.
An excerpt for an update could look like this:
Finally Values added does not look like an action but rather as state. It should be omitted. Alternatively use differently named end flows.
So far for the formal points. But as #eyp said: it's a good one and one can understand what you tried to express. The above is just for the picky teachers.
It's a good one but it lacks some detail in the diamonds. You should write besides the diamon the question before choosing the next setp to do.
For example in the diamond after Check update value you may write is valid? or another question that clarifies more the business logic.

Can I use parameters with Twist concepts?

The Twist documentation for extracting concepts shows how multiple steps can be grouped into one step that contains those steps. For instance, the following eight fixtures
1. Start at the Maintain product catalog page.
2. The page title should be “Joe’s musical —Maintain Product Catalog.”
3. Click the Add New Instrument button.
4. The page title should be “Joe’s musical—Add New Musical Instrument.”
5. Enter text “Guitar” into the Instrument field.
6. Select “Slide” from the Type selection list.
7. Select “Dobro” from the Brand selection list.
8. Click the Save button.
Can be condensed into one concept:
1. Add a New Musical Instrument “Guitar” of type “Slide” and brand “Dobro”
However, the tutorial doesn't say if it's possible to use this concept with other parameters (perhaps with "Drum" instead of "Guitar"). However, it does clearly say that parameters in the concept name should be surrounded by quotes, but they also should match the parameter name, so it's not clear if it's possible.
So can I use parameters with Twist concepts?
Yes! The documentation is really crummy about making this clear, but it is absolutely possible.
If you extracted a concept in the way that they described in the tutorial you referenced and others, then the fixture Add a New Musical Instrument “Guitar” of type “Slide” and brand “Dobro” actually contains three parameters named Guitar, Slide, and Dobro. What makes this so confusing is in each scenario you can change the value of each parameter to whatever you like (perhaps "Drum", "Snare", "Yamaha"), but under the hood, the variables are still called by their original names (thus Guitar=Drum, etc.) and these original names will appear as default values whenever you add the concept to a scenario.
To eliminate confusion, I recommend changing these default names. In this case, it might be Add a New Musical Instrument “Instrument” of type “Type” and brand “Brand”. Bizarrely, you can't rename the parameters via "Rephrase the Open Concept" because you run into a catch-22 situation. You can't change the name of the concept because it doesn't match the usage in the fixture. And you can't rename the fixtures because the parameters are bound to the concept name. So I recommend just opening it up in the text editor and making the change there.
So bottom line, the examples make it seem like you can't use parameters because the parameters wind up being named after whatever value you inputted. I recommend changing the default parameter names, but you have to do it in the text editor because Twist won't let you.

ADF: Show/hide options in af:navigationPane

I'm using JDeveloper 11.1.1.7.0
I have followed this tutorial http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_43/jdtut_11r2_43.html to create a basic and plain left-side menu in my application.
This tutorial shows more advance topics, but I have created a simple left-side menu, with a list.
I haved created an unbounded task flow, drag/drop a wildcard, then the views, then the control flows, ... It works perfect
In the JSF template, in the left-side, I have this code:
<af:navigationPane id="pt_np1" hint="list" value="#{supervision_menu}" var="supervisionInfo">
<f:facet name="nodeStamp">
<af:commandNavigationItem text="#{supervisionInfo.label}" id="pt_cni1"
destination="#{supervisionInfo.destination}"
action="#{supervisionInfo.doAction}"/>
</f:facet>
I need an advanced feature, and I want to show/hide some options, based on a parameter.
I need to execute a view object with this parameter, process the results, so I get the information to know which options could be shown or hidden.
So, my questions are:
How could I force to execute this check as the first step of this flow?
In generated menu.xml and in af:commandNavigationItem, there are visible attribute. Where should I place the condition?
Any help would be very appreciated. Thanks
Not exactly sure what you mean by this:
I need to execute a view object with this parameter.
Assuming you mean "execute a QUERY against the VO", then if you used a ViewCriteria to create the where clause fragment that gets ANDed to the VO where clause, then you can use ExecWithParams (here,here, here) and drag this method onto the task flow as part of the navigation to the View. Then this will execute prior to entry to the view. Or use you can use Invoke on there Executables of the Binding layer - drag to top of list of executables, but this is no longer the recommended way, being replaced with the previous method.
if you are not using ViewCriteria (why not?) then one suggestion is to expose a method on the AM containing the VO, and pass the parms to this method and have it call the VO, but this is basically what ExecWithParms does. This method, once exposed, could be utilized in the same fashion as I mentioned above. If you can describe more precisely what you are trying to do I can try to be of more help.
As I told to Joe, the final solution requires to change the approach.
I have made an unbounded task flow, then created a menu, then adding ADF Security and finally shown/hidden options, in function of user roles/permissions.
I hope it helps. Thank you

How should I implement `OnLoad` event handler when creating an activity using a contact?

I've created my own solution with a custom entity of type activity. I'd like to show a message whenever a new instance of it is created using an existing contact but not allow the user to create one, if only attempting to do that without going via contact.
Basically, my aim is that it won't be impossible to just create that activity (the form will be hidden directly at any attempt except for one way only). The user will have to go to contacts (or leads etc.) and in there add and create an instance of the custom activity entity. That way, I can assure that the field "regarding" will be filled out already.
I'm guessing that I need to detect somehow that the opening of the form is a creation attempt. How can I do that?
Also, as it is now, the user can't create a contact-less activity of the custom type because it doesn't appear on the menu with other activities. I must have disabled it somehow but I have no idea how. Anybody who has one?
You could do this a bunch of ways but the easiest would probably be to:
Make the regarding field read only.
Make the regarding field mandatory.
That way if a user opens a create new form they wont be able to set the regarding and because its mandatory they wont be able to save the record. When they open via an existing contact the regarding field will be mapped automatically. That said in this case just making it mandatory my be enough.
(As a side JavaScript can be used to identify the current form state, but I'm not sure how useful that is here).
In terms of where custom activities appear, by default mine show in a number of locations, for example:
CRM > Workplace > Activities > Ribbon > Other Activities > XXX.
CRM > Workplace > Activities > View Selector > XXX.
They don't show under the left hand navigation of the workplace because they are grouped under 'Activities'. I'm pretty sure these are all the default settings.
You can exercise greater control by editing the sitemap, where you can put pretty much anything, anywhere.
In addition to Mr Wood, I'd like to show you some code. It works as supposed to but I'm not sure if it's optimal.
var foo = function () {
var whatIsGoingOn = Xrm.Page.ui.getFormType();
if (whatIsGoingOn === 1)
alert("Let there be an entity!");
else
alert("Not a creation...");
}
The other states' (deletion, update etc.) numeric values are listed here.
Answering the second part of your question:
When you create a custom activity you can choose whether to have it appear in 'normal' Activity menus or not by checking the box at the top right of the entity form. This is a once-only choice as far as I know and can't be changed later.
For your setup, I would suggest NOT checking this box, so it does not appear in the activity menus to avoid users even being tempted to do it that way.
Instead, add an explicit relationship to the activity N:1 to Contact, and another N:1 to Lead. Use this relationship to add your activity to the left navigation of Contact and Lead forms, or add a grid for them (depends on how you want to use this and if you need to filter the view to something other than the default "Associated View").
When a user navigates to this section they will see if any previous activities of this type exist, and be able to add a new one. BUT this means that the child record is a child via this relationship, not using "regarding", so use a script on the form for the activity so that if Contact is filled in, it is copied to Regarding, and if Lead is filled in then that is copied. If neither, then use an alert or other means to warn the use that something is wrong (see comment earlier). If you want Regarding to be read-only but filled in by script, you will need to make sure to use the force the value to be saved:
Xrm.Page.getAttribute("regardingobjectid").setSubmitMode("always");
You must have the lookups for Contact and Lead on the form to be able to use them in your scripts, but you can make them not "visible by default" so they are there but not seen by the user (and taking up no space).

Resources