Skip to content

Instantly share code, notes, and snippets.

@distributedlife
Last active December 28, 2015 04:49
Show Gist options
  • Select an option

  • Save distributedlife/7445603 to your computer and use it in GitHub Desktop.

Select an option

Save distributedlife/7445603 to your computer and use it in GitHub Desktop.
distributedlife.com blog posts
<services>
<service name="My.Service.Name">
<endpoint name="Endpoint One">
<operation name="GetAwesomePeople">
<aspect name="Input Validation" start="22/03/2010 - 2:02:17" finish="22/03/2010 - 2:02:23">
<case name="Name not supplied" start="22/03/2010 - 2:02:18" finish="22/03/2010 - 2:02:20" result="failed" />
<case name="Name is larger than db value" start="22/03/2010 - 2:02:20" finish="22/03/2010 - 2:02:20" result="passed" />
<case name="Name is one char" start="22/03/2010 - 2:02:20" finish="22/03/2010 - 2:02:21" result="passed" />
<case name="Awesome person does not exist" start="22/03/2010 - 2:02:21" finish="22/03/2010 - 2:02:22" result="failed" />
</aspect>
</operation>
</endpoint>
</service>
</services>
enum EnabledOptions FileIsEmpty (const char* const Filename)
{
const unsigned int SEEK_END = 2 ;
long FileHandle = 0 ;
enum EnabledOptions ReturnValue = Yes;
FileHandle = fopen (Filename, "rb" );
if (!FileHandle)
{
lr_error_message ("Failed to open the file \"%s\"", Filename) ;
return Yes;
}
fseek (FileHandle , 0 , SEEK_END);
if (ftell (FileHandle) != 0)
{
ReturnValue = No ;
}
fclose (FileHandle) ;
return ReturnValue ;
}
void ReadFileUTF8 (const char* const Filename, const char* TargetParameter)
{
const unsigned int SEEK_END = 2 ;
long FileHandle = 0 ;
long FileSizeInBytes = 0 ;
char * DataBuffer = 0;
int shifted = 0 ;
size_t result = 0;
long index = 0 ;
//Set our TargetParameter to Failed incase we don't make it
lr_set("FAILED", TargetParameter);
FileHandle = fopen (Filename, "rb" );
if (!FileHandle)
{
lr_error_message ("Failed to open the file \"%s\"", Filename) ;
return ;
}
//Get the file size. We use this to allocate our data buffer.
fseek (FileHandle , 0 , SEEK_END);
FileSizeInBytes = ftell (FileHandle);
rewind (FileHandle);
// allocate memory to contain the whole file
DataBuffer = (char*) malloc ((sizeof(char) * FileSizeInBytes) + 1) ;
if (!DataBuffer)
{
lr_error_message ("Could not allocate memory for buffer") ;
return ;
}
// copy the file into the DataBuffer:
result = fread (DataBuffer, sizeof(char), FileSizeInBytes, FileHandle) ;
if (result != FileSizeInBytes)
{
lr_error_message ("Could not copy file data into buffer") ;
if (DataBuffer)
{
free (DataBuffer) ;
}
}
//add null-terminating char
DataBuffer[FileSizeInBytes] = '\0' ;
//Skip BOM (if there is one)
if (DataBuffer[0] == '\xff' &amp;&amp; DataBuffer[1] == '\xfe')
{
DataBuffer++ ;
DataBuffer++ ;
shifted = 1 ;
}
lr_set (DataBuffer, TargetParameter);
//Move back to start of string before freeing memory
if (shifted == 1)
{
DataBuffer-- ;
DataBuffer-- ;
}
fclose (FileHandle) ;
free (DataBuffer) ;
}
ExecuteTestAsUser (MyServiceUser) ;
SetDefaultParameters () ;
CallService () ;
GrantSuperUserToUser (MyServiceUser);
enum UserScenarios
{
DoNotSetSecurity,
MyService1,
MyService2
}
char* usernames[] =
{
"User001",
"User002"
}
char* passwords[] =
{
"PASSWORD",
"PASSWORD"
}
if (OutstandingDefectExists (411, Functionality))
{
return 0 ;
}
enum EnabledOptions Defects[] =
{
/* 1*/ No,
/* 2*/ Yes,
/* 3*/ Yes,
/* 4*/ Yes,
...
}
EnableCheckForExceptions (No) ;
EnableCheckForAuditEvents (No) ;
EnableCheckForDataPersistence (No) ;
void EnableCheckForAuditEvents (enum EnabledOptions AuditValidationEnabled)
{
lr_save_int (AuditValidationEnabled, "__AuditValidationEnabled") ;
}
enum EnabledOptions AuditingEnabled (void)
{
if (StringsAreEqual (lr_get ("{__AuditValidationEnabled}"), "1"))
{
return Yes;
}
else
{
return No ;
}
}
void CheckAuditRecord (void)
{
if (!AuditingEnabled ())
{
return ;
}
}
{
//Non-repudiation (auditing)
{
ExpectAuditRecord () ;
}
}
//Execute the test
{
ExecuteTestAsUser (DemoServiceUser) ;
SetDefaultParameters () ;
CallService () ;
}
//Non-repudiation (auditing)
{
CheckAuditRecord () ;
ValidateAuditRecord (Success, "DemoServiceUser called operation Create User") ;
}
enum EnabledOptions FileExists (const char* const Filename)
{
long FileHandle = 0 ;
if (FileHandle = fopen (Filename, "r"))
{
fclose (FileHandle) ;
return Yes ;
}
return No ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment