Skip to content

Instantly share code, notes, and snippets.

@tysonstewart
Created October 5, 2012 18:35
Show Gist options
  • Save tysonstewart/3841573 to your computer and use it in GitHub Desktop.
Save tysonstewart/3841573 to your computer and use it in GitHub Desktop.
Example of a custom data source for Visual Studio Webtests
using System;
using System.Data;
using System.Data.SqlClient;
namespace Hudl.WebApp.Tests.TestsCore.DataSources
{
public class AnnotationsDataSource : ModifiableQueueBasedDataSource<long>
{
private readonly long _userId;
public AnnotationsDataSource(long userId)
{
_userId = userId;
HasBeenModified = false;
}
protected override void LoadItems()
{
const string annotationDataQuery = @"SELECT [AnnotationId]
FROM [AnnotationData]
WHERE [UserId] = @UserId";
var sqlCommand = new SqlCommand(annotationDataQuery);
sqlCommand.Parameters.Add("@UserId", SqlDbType.BigInt).Value = _userId;
UsingDataReader(sqlCommand, EnqueueAnnotationData);
}
private void EnqueueAnnotationData(SqlDataReader sqlDataReader)
{
var annotationId = Convert.ToInt64(sqlDataReader["AnnotationId"]);
DataItems.Enqueue(annotationId);
}
public override string ToString()
{
var value = String.Format("AnnotationsDataSource: Is loaded: {0}, {1} items, User {2}, Has been modified: {3}", IsLoaded, DataItems.Count, _userId, HasBeenModified);
return value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment