9using Microsoft.VisualStudio.TestTools.UnitTesting;
14using TestCategory =
NUnit.Framework.CategoryAttribute;
24 private const string TypeName =
"BaseResourceWithLargeDataTest";
26 #region Overrideable Protected Properties
38 if (
posted.data_file ==
null)
46 #endregion Overrideable Protected Properties
56 Assert.Inconclusive(
"RUN_OFFLINE = true");
61 "GET on the /data endpoint appears to have succeeded, " +
62 "but didn't match the data uploaded.");
78 [
TestMethod, TestCategory(TypeName), TestCategory(
"Post Valid")]
83 Assert.IsNotNull(
obj.data_file,
"Missing the data file for this resource.");
84 Assert.IsNotNull(
obj.data_file.ref_id,
"Missing a data file ref_id");
89 #region CreatedAndModified
99 Assert.IsNotNull(
posted.created,
"Expected a 'created' date to be assigned.");
100 Assert.IsNotNull(
posted.modified,
"Expected a 'modified' date to be assigned.");
102 "Expected the created and modified date to be equal on a newly posted resource.");
105 #endregion CreatedAndModified
138 Assert.Inconclusive(
"RUN_OFFLINE = true");
172 Assert.AreEqual(
POSTData, data.
Get(),
"Downloaded data did not match uploaded data.");
186 data.LargeStreamUpload(
191 Assert.AreEqual(
POSTData, data.
Get(),
"Downloaded data did not match uploaded data.");
194 #endregion Test Methods
virtual T PUT_WithChanges_Succeeds(Func< T, T > modifyTestResource)
POST a valid resource, then test doing a PUT on the resource after modifying it in some way,...
virtual T POST_ForPutTest(T validToPost, Action< T > putTest)
Used for all PUT tests and PUT helper methods. Similar to the base helper method BaseResourceTestSuit...
virtual T TestResource_Existing
The resource used for all unit tests that require a prepared and already posted resource....
virtual bool DELETE_Allowed
virtual T TestResource
The resource used for all unit tests that require a valid prepared but unPOSTed resource.
void TestResourceDeleteHelper(T toDelete, bool isDeleteAllowed)
virtual void Test_Resource_GET_Data()
Verify that posting the test resource along with it's data succeeds.
override void Test_Resource_POST_Valid()
Verify that posting the test resource along with it's data succeeds.
override void POST_ThenDoAction(T validToPost, Action< T > toExecute)
We need to override this universally used POST test helper method to ensure test data is uploaded as ...
virtual void Test_Resource_DELETE_Before_Uploading_Data()
Verify that the delete method is either supported or not supported before data has been uploaded....
override void Test_Resource_PUT_NoChanges()
virtual void Test_Resource_PUT_Data_EmptyString()
Verify that doing a PUT with empty data fails with a BadRequest.
override void Test_Resource_POST_CreatedAndModified()
Overridden because the base test doesn't account for the fact that a full POST (with data) involves m...
virtual void AdditionalValidResourceWithDataTests(T posted)
virtual void Test_Resource_Data_SegmentedUpload()
Verify that posting the test resource along with it's data succeeds using segmented uploads.
override void AdditionalValidResourceTests(T posted)
Deriving classes can optionally override this function to perform additional validation on every succ...
virtual bool DELETE_Allowed_BeforeData
virtual void Test_Resource_Data_LargeStreamUpload()
Verify that posting the test resource along with it's data succeeds using the LargeStreamUpload exten...
Exposes sample resource objects, with built-in methods for injecting dependencies.
static Parameters UploadParams
The LargeDataUpload parameters to use when uploading data for test fixtures.
static void MethodIsAllowed(Action request, string methodName, bool methodAllowed=true)
Wrap a request in a tryGet with some formatting for testing purposes.
static bool FileContentsAreEqual(string expected, string actual, StringComparison comparisonType=StringComparison.InvariantCulture)
Determines whether the two strings are equal, ignoring differences in line ending styles and trailing...
static Action< APIRequestException > ApiExceptionTest(HttpStatusCode expectedStatusCode)
Generate a function that will test a REST request exception in a standard way.
Retrieve settings from environment variables if they exist, or the project settings file otherwise.
static bool RUN_OFFLINE
Controls whether tests that normally require a connection to the server should be allowed to try to r...
Generic Unit test implementations that will test REST methods on arbitrary resources.
IRestResponse POST(int? timeout=null, bool throwOnError=true, IEnumerable< Parameter > requestParameters=null)
Performs an empty POST at this endpoint (executing the command). Throws an APIRequestException if the...
Describes an endpoint off of some types of resources from which an associated "large data file" can b...
CommandSubResource commit
The endpoint at which a large file upload is finalized with a POST.
void Patch(string data, long bytesOffset, int? timeout=null, IEnumerable< Parameter > requestParameters=null)
Performs a PATCH of part of this object's data at this endpoint.
void Post(long? totalSizeBytes, int? timeout=null)
Performs a POST that initiates a chunked large data upload.
Describes a collection of resources which can be listed.
T Get(IEnumerable< Parameter > parameters=null, int? timeout=null)
Performs a GET request a at this endpoint.
Large Data Upload Utilities.
static StatusResponse PollUntilDataProcessed(LargeDataSubResource dataEndpoint, Parameters parameters=null)
Polls the dataEndpoint until the state is no longer Processing.
static MemoryStream GetStringStream(string input)
Generate a byte stream from a string which can be used in the LargeStreamUpload methods.
Describes an APIResource class that adds a "/data" sub-resource, since this functionality is common t...
TaskStatus
The status of a data upload which may be in progress.