Skip to content

Commit 3d6dec0

Browse files
committed
#110 Fixed UT related to AccountInformations (was only valid for credentials V1)
1 parent 9b45d64 commit 3d6dec0

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

MegaApiClient.Tests/Login.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using CG.Web.MegaApiClient.Tests.Context;
56
using Moq;
67
using Newtonsoft.Json;
@@ -71,27 +72,38 @@ public void Login_InvalidCredentials_Throws(string email, string password, ApiRe
7172
Assert.Equal(expectedErrorCode, exception.ApiResultCode);
7273
}
7374

74-
[Theory, MemberData(nameof(Credentials))]
75+
[Theory, MemberData(nameof(AllValidCredentials))]
7576
public void Login_ValidCredentials_Succeeds(string email, string password)
7677
{
7778
Assert.NotNull(this.context.Client.Login(email, password));
7879
Assert.True(this.context.Client.IsLoggedIn);
7980
}
8081

81-
public static IEnumerable<object[]> Credentials
82+
public static IEnumerable<object[]> CredentialsV1
8283
{
8384
get
8485
{
8586
Assert.NotEmpty(AuthenticatedTestContext.UsernameAccountV1);
86-
Assert.NotEmpty(AuthenticatedTestContext.UsernameAccountV2);
8787
Assert.NotEmpty(AuthenticatedTestContext.Password);
8888

8989
yield return new[] {AuthenticatedTestContext.UsernameAccountV1, AuthenticatedTestContext.Password };
90+
}
91+
}
92+
93+
public static IEnumerable<object[]> CredentialsV2
94+
{
95+
get
96+
{
97+
Assert.NotEmpty(AuthenticatedTestContext.UsernameAccountV2);
98+
Assert.NotEmpty(AuthenticatedTestContext.Password);
99+
90100
yield return new[] {AuthenticatedTestContext.UsernameAccountV2, AuthenticatedTestContext.Password };
91101
}
92102
}
93103

94-
[Theory, MemberData(nameof(Credentials))]
104+
public static IEnumerable<object[]> AllValidCredentials => CredentialsV1.Concat(CredentialsV2);
105+
106+
[Theory, MemberData(nameof(AllValidCredentials))]
95107
public void LoginTwice_ValidCredentials_Throws(string email, string password)
96108
{
97109
this.context.Client.Login(email, password);
@@ -116,7 +128,7 @@ public void LoginAnonymousTwice_Throws()
116128
Assert.Equal("Already logged in", exception.Message);
117129
}
118130

119-
[Theory, MemberData(nameof(Credentials))]
131+
[Theory, MemberData(nameof(AllValidCredentials))]
120132
public void LogoutAfterLogin_Succeeds(string email, string password)
121133
{
122134
this.context.Client.Login(email, password);
@@ -126,7 +138,7 @@ public void LogoutAfterLogin_Succeeds(string email, string password)
126138
Assert.False(this.context.Client.IsLoggedIn);
127139
}
128140

129-
[Theory, MemberData(nameof(Credentials))]
141+
[Theory, MemberData(nameof(AllValidCredentials))]
130142
public void LogoutTwiceAfterLogin_Throws(string email, string password)
131143
{
132144
this.context.Client.Login(email, password);
@@ -149,7 +161,7 @@ public void Login_NullAuthInfos_Throws()
149161
Assert.Throws<ArgumentNullException>("authInfos", () => this.context.Client.Login((MegaApiClient.AuthInfos)null));
150162
}
151163

152-
[Theory, MemberData(nameof(Credentials))]
164+
[Theory, MemberData(nameof(AllValidCredentials))]
153165
public void Login_DeserializedAuthInfos_Succeeds(string email, string password)
154166
{
155167
var authInfos = this.context.Client.GenerateAuthInfos(email, password);
@@ -214,8 +226,8 @@ public static IEnumerable<object[]> MethodsWithMandatoryLogin()
214226
yield return new object[] { (Action<IMegaApiClient>)(x => x.GetAccountInformation()) };
215227
}
216228

217-
[Theory, MemberData(nameof(Credentials))]
218-
public void GetAccountInformation_AuthenticatedUser_Succeeds(string email, string password)
229+
[Theory, MemberData(nameof(CredentialsV1))]
230+
public void GetAccountInformation_AuthenticatedUserV1_Succeeds(string email, string password)
219231
{
220232
this.context.Client.Login(email, password);
221233

@@ -230,6 +242,18 @@ public void GetAccountInformation_AuthenticatedUser_Succeeds(string email, strin
230242
Assert.Equal(1046530 + AuthenticatedTestContext.FileSize + AuthenticatedTestContext.SubFolderFileSize, accountInformation.UsedQuota); // 1046530 is from incoming shares
231243
}
232244

245+
[Theory, MemberData(nameof(CredentialsV2))]
246+
public void GetAccountInformation_AuthenticatedUserV2_Succeeds(string email, string password)
247+
{
248+
this.context.Client.Login(email, password);
249+
250+
IAccountInformation accountInformation = this.context.Client.GetAccountInformation();
251+
252+
Assert.NotNull(accountInformation);
253+
Assert.Equal(53687091200, accountInformation.TotalQuota);
254+
Assert.Equal(0, accountInformation.UsedQuota);
255+
}
256+
233257
[Fact]
234258
public void GetAccountInformation_AnonymousUser_Succeeds()
235259
{

0 commit comments

Comments
 (0)