Skip to content

Commit

Permalink
try all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
f2calv committed Sep 27, 2024
1 parent 81b1122 commit 8e05b44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
37 changes: 18 additions & 19 deletions src/CasCap.Apis.GooglePhotos.Tests/Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ public async Task LoginTest()

async Task<bool> DoLogin()
{
//if (IsCI())
//{
// var accessToken = Environment.GetEnvironmentVariable("GOOGLE_PHOTOS_ACCESS_TOKEN");
// if (string.IsNullOrWhiteSpace(accessToken)) throw new ArgumentNullException(nameof(accessToken));
// _googlePhotosSvc.SetAuth("Bearer", accessToken);
// return true;
//}
//else
return await _googlePhotosSvc.LoginAsync();
if (IsCI())
{
//
var accessToken = Environment.GetEnvironmentVariable("GOOGLE_PHOTOS_ACCESS_TOKEN");
if (string.IsNullOrWhiteSpace(accessToken)) throw new ArgumentNullException(nameof(accessToken));
_googlePhotosSvc.SetAuth("Bearer", accessToken);
return true;
}
else
return await _googlePhotosSvc.LoginAsync();
}

[Fact]
Expand All @@ -44,14 +45,13 @@ static bool IsCI() => Environment.GetEnvironmentVariable("TF_BUILD") is not null

static string GetRandomAlbumName() => $"{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}";

/*
[SkipIfCIBuildTheory, Trait("Type", nameof(GooglePhotosService))]
[InlineData(GooglePhotosUploadMethod.Simple)]
[InlineData(GooglePhotosUploadMethod.ResumableSingle)]
[InlineData(GooglePhotosUploadMethod.ResumableMultipart)]
public async Task UploadMediaTests(GooglePhotosUploadMethod uploadMethod)
{
var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

var paths = Directory.GetFiles(_testFolder);
Expand All @@ -71,7 +71,7 @@ public async Task UploadMediaTests(GooglePhotosUploadMethod uploadMethod)
[InlineData("test1.jpg", "Урок-английского-10.jpg")]
public async Task UploadSingleTests(string file1, string file2)
{
var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

//upload single media item
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task UploadSingleTests(string file1, string file2)
[SkipIfCIBuildFact]
public async Task UploadMultipleTests()
{
var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

//upload multiple media items
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task UploadMultipleTests()
//retrieve all media items in each album
var albumMediaItems = await _googlePhotosSvc.GetMediaItemsByAlbumAsync(alb.id).ToListAsync();
Assert.NotNull(albumMediaItems);
Assert.True(albumMediaItems.Count == alb.mediaItemsCount);
Assert.True(albumMediaItems.Count.ToString() == alb.mediaItemsCount);
var i = 1;
foreach (var mediaItem in albumMediaItems)
{
Expand Down Expand Up @@ -178,7 +178,7 @@ public async Task UploadMultipleTests()
[SkipIfCIBuildFact]
public async Task FilteringTests()
{
var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

contentFilter contentFilter = null;
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task FilteringTests()
[SkipIfCIBuildFact]
public async Task EnrichmentsTests()
{
var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

var path = $"{_testFolder}test7.jpg";
Expand Down Expand Up @@ -279,7 +279,7 @@ public async Task EnrichmentsTests()
[SkipIfCIBuildFact]
public async Task SharingTests()
{
var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

//get or create new album
Expand Down Expand Up @@ -354,7 +354,7 @@ public async Task DownloadBytesTests(int pageSize, int maxPageCount)
{
var expectedCount = Directory.GetFiles(_testFolder).Length;

var loginResult = await _googlePhotosSvc.LoginAsync();
var loginResult = await DoLogin();
Assert.True(loginResult);

var mediaItems = await _googlePhotosSvc.GetMediaItemsAsync(pageSize, maxPageCount).ToListAsync();
Expand All @@ -365,5 +365,4 @@ public async Task DownloadBytesTests(int pageSize, int maxPageCount)
var bytes = await _googlePhotosSvc.DownloadBytes(mediaItems[0]);
Assert.NotNull(bytes);
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ public async Task<bool> LoginAsync(GooglePhotosOptions options, CancellationToke

public async Task<bool> LoginAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("FileDataStoreFullPathDefault={path}", _options.FileDataStoreFullPathDefault);
_logger.LogInformation("FileDataStoreFullPathOverride={path}", _options.FileDataStoreFullPathOverride);
Console.WriteLine($"FileDataStoreFullPathDefault={_options.FileDataStoreFullPathDefault}");
Console.WriteLine($"FileDataStoreFullPathOverride={_options.FileDataStoreFullPathOverride}");

if (string.IsNullOrWhiteSpace(_options.User)) throw new ArgumentNullException(nameof(_options.User), $"{nameof(GooglePhotosOptions)}.{nameof(_options.User)} cannot be null!");
if (string.IsNullOrWhiteSpace(_options.ClientId)) throw new ArgumentNullException(nameof(_options.ClientId), $"{nameof(GooglePhotosOptions)}.{nameof(_options.ClientId)} cannot be null!");
if (string.IsNullOrWhiteSpace(_options.ClientSecret)) throw new ArgumentNullException(nameof(_options.ClientSecret), $"{nameof(GooglePhotosOptions)}.{nameof(_options.ClientSecret)} cannot be null!");
Expand Down Expand Up @@ -179,7 +174,7 @@ string[] GetScopes()//todo: make extension method to convert any enum to string[
}

/// <summary>
/// Hack to allow us to set the auth header when running integration tests from CI.
/// Workaround to allow setting the auth header when running integration tests from CI.
/// </summary>
/// <param name="tokenType"></param>
/// <param name="accessToken"></param>
Expand Down

0 comments on commit 8e05b44

Please sign in to comment.