Reputation: 1611
My DTO is declared like below
[MaxLength(maxFileSize, ErrorMessage = "Max Byte Array length is 40MB.")]
public byte[] DocumentFile { get; set; }
I need to write Unit Test method for File Size more than 40MB.
As the DocumentFile
property is declared as byte[] array type, I am unable to assign any value to DocumentFile
property.
Can anyone please suggest me how can I write unit test method for this scenario.
Upvotes: 0
Views: 1478
Reputation: 793
Something like
[TestMethod]
[ExpectedException(typeof(BlaBlaException), "Exceptiion string")]
public void DocumentFile_set_WhenDocumentFileSetOver40Mb_ShouldThrowExceptionBlaBla {
DocumentFile = new byte [45000000];
}
Upvotes: 1
Reputation: 8725
Neither compiler nor runtime have a problem with a 40MB+1 byte array:
namespace so42248850
{
class Program
{
class someClass
{
/* [attributes...] */
public byte[] DocumentFile;
}
static void Main(string[] args)
{
var oversized = new byte[41943041]; /* 40 MB plus the last straw */
try
{
var mock = new someClass
{
DocumentFile = oversized
};
}
catch(Exception e)
{
/* is this the expected exception > test passes/fails */
}
}
}
}
I would not recommend such an approach for a massively multi-user scenario in production, as it may cause quite some memory pressure, but for an automated test it should be ok.
Upvotes: 3