It seems to me like the main problem here is simply to create a method that generates a random date.
One way to do this and retain a certain level of control over which dates you get, is to just generate random numbers for date, month and year. For year, you could do:
Random r = new Random();
int randomYear = r.Next(1990, 2015); // random year between 1990 and 2014
int randomMonthNr = r.Next(1,13);
int maxDayNr = DateTime.DaysInMonth(randomYear, randomMonthNr);
int randomDayNr = r.Next(1, (maxDayNr + 1));
Do something similar for date and month, and just use that in:
var randomDate = new DateTime(randomYear, randomMonthNr, randomDayNr);
(Note: Generate the month first, then find out the number of days in the resulting month, and use that as the upper limit when generating a number for the date, so you get a max of 28 or 29 for February, etc).
Once the date(s) are created, you can simply compare them using <=
and >=
(with or without the =
). If you need to compare them within the context of the service, just send a DateTime
as a parameter to the service, and compare it there.
Update: Connecting to the service
Open the folder under your Visual Studio project for the client. Right click the service reference, and select View in Object Browser
. There, you should see a hierarchy of the types and namespaces from your service. Look for a type called something like YourServiceNameClient
. This will be an automatically generated type that you can use to connect to your service (Client
will just be appended to the type that the service reference has identified).
Use it like:
var yourServiceReference = new YourServiceNameClient();
var yourGeneratedDate = yourServiceReference.GetNewRandomDate();
This obviously assumes GetNewRandomDate()
is a method you have exposed in your service. Hope this is helpful...