Created
October 5, 2012 18:35
-
-
Save tysonstewart/3841573 to your computer and use it in GitHub Desktop.
Example of a custom data source for Visual Studio Webtests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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