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 RegisterTest() { TelimenaUserManager manager = new TelimenaUserManager(new UserStore <TelimenaUser>(this.Context)); AccountUnitOfWork unit = new AccountUnitOfWork(null, manager, this.Context); AccountController sut = new AccountController(unit, new Mock <ILog>().Object); RegisterViewModel model = new RegisterViewModel { Name = "Jim Beam" , ConfirmPassword = "******" , Password = "******" , Email = "*****@*****.**" , Role = TelimenaRoles.Developer }; ViewResult result = sut.Register(model).GetAwaiter().GetResult() as ViewResult; Assert.AreEqual("WaitForActivationInfo", result.ViewName); TelimenaUser user = unit.UserManager.FindByNameAsync(model.Email).GetAwaiter().GetResult(); Assert.AreEqual("Jim Beam", user.DisplayName); Assert.IsTrue(user.RegisteredDate.Date == DateTime.UtcNow.Date); //Assert.IsFalse(user.IsActivated); Assert.IsTrue(unit.UserManager.IsInRoleAsync(user.Id, TelimenaRoles.Developer).GetAwaiter().GetResult()); Assert.IsTrue(unit.UserManager.IsInRoleAsync(user.Id, TelimenaRoles.Viewer).GetAwaiter().GetResult()); DeveloperTeam developerTeam = unit.DeveloperRepository.SingleOrDefault(x => x.MainUser.Id == user.Id); Assert.AreEqual(user.DisplayName, developerTeam.MainUser.DisplayName); Assert.AreEqual(user.Email, developerTeam.MainEmail); Assert.AreEqual(developerTeam, user.GetDeveloperAccountsLedByUser().Single()); }
public async Task <RegisterProgramResponse> Register(RegisterProgramRequest request) { try { if (!ApiRequestsValidator.IsRequestValid(request, out List <string> errors)) { return(new RegisterProgramResponse(new BadRequestException(string.Join(", ", errors)))); } if (await this.Work.Programs.GetByTelemetryKey(request.TelemetryKey).ConfigureAwait(false) != null) { return(new RegisterProgramResponse(new BadRequestException($"Use different telemetry key"))); } TelimenaUser user = await this.Work.Users.FirstOrDefaultAsync(x => x.UserName == this.User.Identity.Name).ConfigureAwait(false); if (user == null) { return(new RegisterProgramResponse(new BadRequestException($"Cannot find user [{this.User.Identity.Name}]"))); } DeveloperTeam developerTeam = user.GetDeveloperAccountsLedByUser().FirstOrDefault(); if (developerTeam == null) { return(new RegisterProgramResponse(new BadRequestException($"Cannot find developer account associated with user [{user.UserName}]"))); } Program program = new Program(request.Name, request.TelemetryKey) { Description = request.Description }; ProgramAssembly primaryAss = new ProgramAssembly() { Name = Path.GetFileNameWithoutExtension(request.PrimaryAssemblyFileName), Extension = Path.GetExtension(request.PrimaryAssemblyFileName) }; await this.Work.RegisterProgram(developerTeam, program, primaryAss).ConfigureAwait(false); program = await this.Work.Programs.GetByTelemetryKey(request.TelemetryKey).ConfigureAwait(false); var url = this.Url?.Link("Default", new { Controller = "ProgramManagement", Action = "Index", telemetryKey = program.TelemetryKey }); return(new RegisterProgramResponse(program.TelemetryKey, program.DeveloperTeam.PublicId, url)); } catch (Exception ex) { return(new RegisterProgramResponse(ex)); } }