private static void GetTwoUsers(AccountUnitOfWork unit, [CallerMemberName] string caller = null) { var result = unit.RegisterUserAsync(new TelimenaUser(caller + "*****@*****.**", caller + "Jim Beam"), "P@ssword", TelimenaRoles.Developer).GetAwaiter() .GetResult(); if (!result.Item1.Succeeded) { var msg = result.Item1.Errors?.FirstOrDefault(); if (msg != null && !msg.Contains("is already taken.")) { Assert.Fail($"Failed to register user. Error: {result.Item1.Errors?.FirstOrDefault()}"); } } unit.Complete(); result = unit.RegisterUserAsync(new TelimenaUser(caller + "*****@*****.**", caller + "Jack Daniels"), "P@ssword", TelimenaRoles.Developer).GetAwaiter() .GetResult(); if (!result.Item1.Succeeded) { var msg = result.Item1.Errors?.FirstOrDefault(); if (msg != null && !msg.Contains("is already taken.")) { Assert.Fail($"Failed to register user. Error: {result.Item1.Errors?.FirstOrDefault()}"); } } unit.Complete(); }
private static void GetTwoUsers(AccountUnitOfWork unit, [CallerMemberName] string caller = null) { unit.RegisterUserAsync(new TelimenaUser(caller + "*****@*****.**", caller + "_Jim Beam"), "P@ssword", TelimenaRoles.Developer).GetAwaiter() .GetResult(); unit.Complete(); unit.RegisterUserAsync(new TelimenaUser(caller + "*****@*****.**", caller + "_Jack Daniels"), "P@ssword", TelimenaRoles.Developer).GetAwaiter() .GetResult(); unit.Complete(); }
public void TestSetUserAsMainForSecondDeveloper() { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(this.Context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, this.Context); GetTwoUsers(unit); TelimenaUser jim = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); TelimenaUser jack = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); DeveloperTeam jackDev = unit.DeveloperRepository.FirstOrDefault(x => x.MainUser.Id == jack.Id); DeveloperTeam jimDev = unit.DeveloperRepository.FirstOrDefault(x => x.MainUser.Id == jim.Id); Assert.AreEqual(jackDev.Id, jack.GetDeveloperAccountsLedByUser().Single().Id); Assert.AreEqual(jimDev.Id, jim.GetDeveloperAccountsLedByUser().Single().Id); jimDev.SetMainUser(jack); unit.Complete(); Assert.IsNotNull(jimDev.AssociatedUsers.Single(x => x.Id == jim.Id)); Assert.IsNotNull(jimDev.AssociatedUsers.Single(x => x.Id == jack.Id)); Assert.AreEqual(1, jim.AssociatedDeveloperAccounts.Count()); Assert.AreEqual(jack, jimDev.MainUser); Assert.AreEqual(0, jim.GetDeveloperAccountsLedByUser().Count()); Assert.AreEqual(2, jack.GetDeveloperAccountsLedByUser().Count()); Assert.IsNotNull(jack.GetDeveloperAccountsLedByUser().Single(x => x.Id == jackDev.Id)); Assert.IsNotNull(jack.GetDeveloperAccountsLedByUser().Single(x => x.Id == jimDev.Id)); }
public void TestAddSecondUserToDeveloperTwice() { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(this.Context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, this.Context); GetTwoUsers(unit); TelimenaUser jim = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); TelimenaUser jack = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); DeveloperTeam jackDev = unit.DeveloperRepository.FirstOrDefault(x => x.MainUser.Id == jack.Id); jackDev.AssociateUser(jim); unit.Complete(); jackDev.AssociateUser(jim); unit.Complete(); Assert.AreEqual(2, jackDev.AssociatedUsers.Count); }
public static async Task <TelimenaUser> CreateTelimenaUser(TelimenaPortalContext context, string email, string displayName = null, [CallerMemberName] string caller = "") { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, context); TelimenaUser user = new TelimenaUser(caller + "_" + email, caller + "_" + (displayName ?? email.ToUpper())); await unit.RegisterUserAsync(user, "P@ssword", TelimenaRoles.Developer).ConfigureAwait(false); unit.Complete(); return(user); }
public void TestRemoveDeveloper() { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(this.Context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, this.Context); GetTwoUsers(unit); TelimenaUser jack = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); TelimenaUser jim = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); DeveloperTeam jackDev = unit.DeveloperRepository.FirstOrDefault(x => x.MainUser.Id == jack.Id); jackDev.AssociateUser(jim); unit.DeveloperRepository.Remove(jackDev); unit.Complete(); Assert.IsNotNull(this.Context.Users.Single(x => x.Id == jack.Id)); Assert.IsNotNull(this.Context.Users.Single(x => x.Id == jim.Id)); Assert.IsNull(unit.DeveloperRepository.SingleOrDefault(x => x.Id == jackDev.Id)); }
public static async Task <TelimenaUser> CreateTelimenaUser(TelimenaPortalContext context, string email, string displayName = null, [CallerMemberName] string caller = "") { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, context); TelimenaUser user = new TelimenaUser(caller + "" + email, caller + "" + (displayName ?? email.ToUpper())); var result = await unit.RegisterUserAsync(user, "P@ssword", TelimenaRoles.Developer).ConfigureAwait(false); if (!result.Item1.Succeeded) { var msg = result.Item1.Errors?.FirstOrDefault(); if (msg != null && !msg.Contains("is already taken.")) { Assert.Fail($"Failed to register user {user.UserName}. Error: {result.Item1.Errors?.FirstOrDefault()}"); } } unit.Complete(); return(user); }
public void TestRemoveUser() { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(this.Context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, this.Context); GetTwoUsers(unit); TelimenaUser jack = unit.UserManager.FindByNameAsync(Helpers.GetName("*****@*****.**")).GetAwaiter().GetResult(); DeveloperTeam jackDev = unit.DeveloperRepository.FirstOrDefault(x => x.MainUser.Id == jack.Id); var jackDevId = jackDev.Id; Assert.AreEqual(jackDevId, jack.AssociatedDeveloperAccounts.Single().Id); unit.UserManager.DeleteAsync(jack).GetAwaiter().GetResult(); unit.Complete(); Assert.IsNull(unit.UserManager.FindByNameAsync(jack.UserName).GetAwaiter().GetResult()); jackDev = unit.DeveloperRepository.FirstOrDefault(x => x.Id == jackDevId); Assert.IsNull(jackDev.MainUser); Assert.AreEqual(Helpers.GetName("*****@*****.**"), jackDev.MainEmail); }