コード例 #1
0
        public async Task <ActionResult> Myorder()
        {
            var userid = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            var customerlgn          = _context.Customers.SingleOrDefault(m => m.Email == userid.Email);
            List <MembershipView> li = new List <MembershipView>();
            var customerView         = new MembershipView
            {
                Movie           = new Movie(),
                Customer        = customerlgn,
                MembershipTypes = _context.MembershipType.ToList(),
            };

            if (Session["cart"] == null)
            {
                customerView.Movie.Name = "";
                li.Add(customerView);
                li.Remove(customerView);
                Session["cart"] = li;

                ViewBag.cart = li.Count();


                Session["count"] = 0;
            }

            return(View((List <MembershipView>)Session["cart"]));
        }
コード例 #2
0
 private async Task AddAuditEntry(MembershipView owner, TeamMember teamMember)
 {
     await _mediator.SendAsync(new CreateAuditCommand
     {
         EasAuditMessage = new EasAuditMessage
         {
             Category          = "DELETED",
             Description       = $"User {owner.Email} with role {owner.Role} has removed user {teamMember.Email ?? teamMember.Id.ToString()} with role {teamMember.Role} from account {owner.AccountId}",
             ChangedProperties = new List <PropertyUpdate>
             {
                 new PropertyUpdate {
                     PropertyName = "AccountId", NewValue = owner.AccountId.ToString()
                 },
                 new PropertyUpdate {
                     PropertyName = "UserId", NewValue = teamMember.Id.ToString()
                 },
                 new PropertyUpdate {
                     PropertyName = "Role", NewValue = teamMember.Role.ToString()
                 }
             },
             RelatedEntities = new List <Entity> {
                 new Entity {
                     Id = owner.AccountId.ToString(), Type = "Account"
                 }
             },
             AffectedEntity = new Entity {
                 Type = "Membership", Id = teamMember.Id.ToString()
             }
         }
     });
 }
        public void IfUserIsCallerWillThrowException()
        {
            var command = new ChangeTeamMemberRoleCommand
            {
                HashedAccountId = "1",
                Email           = "*****@*****.**",
                Role            = Role.Owner,
                ExternalUserId  = Guid.NewGuid().ToString()
            };

            var callerMembership = new MembershipView
            {
                AccountId = ExpectedAccountId,
                UserId    = 1,
                Role      = Role.Owner
            };

            var userMembership = new TeamMember
            {
                AccountId = callerMembership.AccountId,
                Id        = callerMembership.UserId,
                Role      = callerMembership.Role
            };

            _membershipRepository.Setup(x => x.GetCaller(callerMembership.AccountId, command.ExternalUserId)).ReturnsAsync(callerMembership);
            _membershipRepository.Setup(x => x.Get(callerMembership.AccountId, command.Email)).ReturnsAsync(userMembership);

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
            Assert.That(exception.ErrorMessages.FirstOrDefault(x => x.Key == "Membership"), Is.Not.Null);
        }
        public void Setup()
        {
            _command = new ResendInvitationCommand
            {
                Email          = "*****@*****.**",
                AccountId      = ExpectedHashedId,
                ExternalUserId = Guid.NewGuid().ToString(),
            };

            var owner = new MembershipView
            {
                AccountId       = ExpectedAccountId,
                UserId          = 2,
                Role            = Role.Owner,
                HashedAccountId = ExpectedHashedId
            };

            _userRepository = new Mock <IUserAccountRepository>();
            _userRepository.Setup(x => x.Get(ExpectedExistingUserEmail)).ReturnsAsync(new User {
                Email = ExpectedExistingUserEmail, UserRef = Guid.NewGuid().ToString()
            });

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(owner.HashedAccountId, _command.ExternalUserId)).ReturnsAsync(owner);
            _invitationRepository = new Mock <IInvitationRepository>();
            _mediator             = new Mock <IMediator>();

            _config = new EmployerAccountsConfiguration();

            _handler = new ResendInvitationCommandHandler(_invitationRepository.Object, _membershipRepository.Object, _mediator.Object, _config, _userRepository.Object);
        }
        public void Setup()
        {
            _command = new ChangeTeamMemberRoleCommand
            {
                HashedAccountId = "1",
                Email           = "*****@*****.**",
                Role            = Role.Owner,
                ExternalUserId  = Guid.NewGuid().ToString(),
            };

            _callerMembership = new MembershipView
            {
                AccountId = ExpectedAccountId,
                UserRef   = Guid.NewGuid().ToString(),
                UserId    = 1,
                Role      = Role.Owner
            };

            _userMembership = new TeamMember
            {
                AccountId = _callerMembership.AccountId,
                UserRef   = Guid.NewGuid().ToString(),
                Id        = _callerMembership.UserId + 1,
                Role      = _command.Role
            };

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId)).ReturnsAsync(_callerMembership);
            _membershipRepository.Setup(x => x.Get(_callerMembership.AccountId, _command.Email)).ReturnsAsync(_userMembership);

            _mediator       = new Mock <IMediator>();
            _eventPublisher = new Mock <IEventPublisher>();

            _handler = new ChangeTeamMemberRoleCommandHandler(_membershipRepository.Object, _mediator.Object, _eventPublisher.Object);
        }
コード例 #6
0
        public ViewResult CustomerForm(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                var customerView = new MembershipView
                {
                    Customer        = customer,
                    MembershipTypes = _context.MembershipType.ToList()
                };

                return(View(customerView));
            }
            else
            {
                if (customer.Id == null)
                {
                    _context.Customers.Add(customer);
                }
                //else
                //{
                //    var customerDb = _context.Customers.Single(c => c.Id == customer.Id);
                //    customerDb.Name = customer.Name;
                //    customerDb.BirthDate = customer.BirthDate;
                //    customerDb.isSubsribedtoNewsLetter = customer.isSubsribedtoNewsLetter;
                //    customerDb.MembershipTypeId = customer.MembershipTypeId;
                //}
                _context.SaveChanges();
                return(View("Index"));
            }
        }
コード例 #7
0
        //
        // GET: /Manage/Index

        public async Task <ActionResult> Index(Customer customer)
        {
            var userid = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            var customerlgn = _context.Customers.SingleOrDefault(m => m.Email == userid.Email);

            if (!ModelState.IsValid)
            {
                //var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();


                var customerView = new MembershipView
                {
                    Customer        = customerlgn,
                    MembershipTypes = _context.MembershipType.ToList()
                };

                return(View("Index", customerView));
            }
            else
            {
                customerlgn.Name             = customer.Name;
                customerlgn.SecondName       = customer.SecondName;
                customerlgn.MembershipTypeId = customer.MembershipTypeId;
                customerlgn.Email            = customer.Email;
                customerlgn.Address          = customer.Address;
                customerlgn.BirthDate        = customer.BirthDate;
                _context.SaveChanges();


                return(RedirectToAction("Index"));
            }
        }
コード例 #8
0
        public void Arrange()
        {
            _command = new RenameEmployerAccountCommand
            {
                HashedAccountId = HashedAccountId,
                NewName         = "Renamed account"
            };

            _owner = new MembershipView
            {
                AccountId = 1234,
                UserId    = 9876,
                UserRef   = Guid.NewGuid().ToString(),
                Email     = "*****@*****.**",
                FirstName = "Bob",
                LastName  = "Green"
            };

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(_owner);

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(It.Is <string>(s => s == HashedAccountId)))
            .Returns(AccountId);

            _repository = new Mock <IEmployerAccountRepository>();
            _repository.Setup(x => x.GetAccountById(It.IsAny <long>()))
            .ReturnsAsync(new Account
            {
                Id       = AccountId,
                HashedId = HashedAccountId,
                Name     = AccountName
            });

            _validator = new Mock <IValidator <RenameEmployerAccountCommand> >();

            _validator.Setup(x => x.ValidateAsync(It.IsAny <RenameEmployerAccountCommand>()))
            .ReturnsAsync(new ValidationResult());

            _mediator            = new Mock <IMediator>();
            _genericEventFactory = new Mock <IGenericEventFactory>();
            _accountEventFactory = new Mock <IAccountEventFactory>();
            _eventPublisher      = new TestableEventPublisher();

            _commandHandler = new RenameEmployerAccountCommandHandler(
                _eventPublisher,
                _repository.Object,
                _membershipRepository.Object,
                _validator.Object,
                _hashingService.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _accountEventFactory.Object);
        }
コード例 #9
0
        public MainWindowViewModel()
        {
            //http://dotnetpattern.com/mvvm-light-messenger

            //used by TeacherViewModel..ChangeToStudentViewCommand
            gala.Messenger.Default.Register <SwitchViewMessage>(this, (switchViewMessage) =>
            {
                SwitchView(switchViewMessage.ViewName);
            });

            UserControl studentView               = new StudentView();
            UserControl membershipView            = new MembershipView();
            UserControl teacherView               = new TeacherView();
            UserControl classView                 = new ClassView();
            UserControl csSelectionView           = new CSMain();
            UserControl scheduleView              = new ScheduleView();
            UserControl studentRosterView         = new StudentRoster();
            UserControl classStudentEnrollView    = new ClassStudentEnroll();
            UserControl classPnLReportView        = new ClassPnLReport();
            UserControl studentAttendanceView     = new StudentAttendanceReport();
            UserControl semesterStudentReportView = new SemesterStudentReport();

            this.VIEWSpsaces.Add("StudentView", studentView);
            this.VIEWSpsaces.Add("MembershipView", membershipView);
            this.VIEWSpsaces.Add("TeacherView", teacherView);
            this.VIEWSpsaces.Add("ClassView", classView);
            this.VIEWSpsaces.Add("ClassManagementView", csSelectionView);
            this.VIEWSpsaces.Add("ScheduleView", scheduleView);
            this.VIEWSpsaces.Add("StudentRosterView", studentRosterView);
            this.VIEWSpsaces.Add("ChangeClassStudentEnrollView", classStudentEnrollView);
            this.VIEWSpsaces.Add("ClassPnLReportView", classPnLReportView);
            this.VIEWSpsaces.Add("StudentAttendanceView", studentAttendanceView);
            this.VIEWSpsaces.Add("SemesterStudentReportView", semesterStudentReportView);


            ViewModelBase studentViewModel = new StudentViewModel()
            {
                Text = "Student View"
            };
            ViewModelBase teacherViewModel = new TeacherViewModel()
            {
                Text = "Teacher View"
            };
            ViewModelBase classViewModel = new ClassViewModel()
            {
                Text = "Class View"
            };


            this.VMspaces.Add("StudentViewModel", studentViewModel);
            this.VMspaces.Add("TeacherViewModel", teacherViewModel);
            this.VMspaces.Add("ClassViewModel", classViewModel);
            StatusBar = "App Started at " + DateTime.Now;
        }
コード例 #10
0
        public ViewResult Edit(int id)
        {
            var customer = _context.Customers.FirstOrDefault(m => m.Id == id);

            var customerView = new MembershipView
            {
                Customer        = customer,
                MembershipTypes = _context.MembershipType.ToList()
            };

            return(View("CustomerForm", customerView));
        }
コード例 #11
0
        public void Arrange()
        {
            _accountRepository    = new Mock <IAccountRepository>();
            _membershipRepository = new Mock <IMembershipRepository>();
            _mediator             = new Mock <IMediator>();

            _owner = new MembershipView
            {
                AccountId = 1234,
                UserId    = 9876,
                Email     = "*****@*****.**",
                FirstName = "Bob",
                LastName  = "Green"
            };

            _agreementView = new EmployerAgreementView
            {
                AccountId                = _owner.AccountId,
                SignedDate               = DateTime.Now,
                SignedByName             = $"{_owner.FirstName} {_owner.LastName}",
                LegalEntityId            = 5246,
                LegalEntityName          = "Test Corp",
                LegalEntityCode          = "3476782638",
                LegalEntityAddress       = "12, test street",
                LegalEntityInceptionDate = DateTime.Now
            };

            _command = new CreateLegalEntityCommand
            {
                HashedAccountId = "ABC123",
                LegalEntity     = new LegalEntity(),
                SignAgreement   = true,
                SignedDate      = DateTime.Now.AddDays(-10),
                ExternalUserId  = "12345"
            };

            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId))
            .ReturnsAsync(_owner);

            _accountRepository.Setup(x => x.CreateLegalEntity(_owner.AccountId, _command.LegalEntity))
            .ReturnsAsync(_agreementView);

            _genericEventFactory     = new Mock <IGenericEventFactory>();
            _legalEntityEventFactory = new Mock <ILegalEntityEventFactory>();

            _commandHandler = new CreateLegalEntityCommandHandler(
                _accountRepository.Object,
                _membershipRepository.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _legalEntityEventFactory.Object);
        }
コード例 #12
0
        public List <MembershipView> GetGroupMembershipView(string groupID, string userid)
        {
            using (var _gorillaCtx = new MSGorillaEntities())
            {
                UserProfile user = _gorillaCtx.UserProfiles.Find(userid);
                if (user == null)
                {
                    throw new UserNotFoundException(userid);
                }

                HashSet <string> followings = new HashSet <string>();
                foreach (var u in user.Subscriptions)
                {
                    followings.Add(u.FollowingUserid);
                }

                List <Membership> members = GetAllGroupMember(groupID, _gorillaCtx);
                List <string>     users   = new List <string>();
                foreach (var mem in members)
                {
                    users.Add(mem.MemberID);
                }

                Dictionary <string, UserProfile> map = new Dictionary <string, UserProfile>();
                foreach (var userprofile in _gorillaCtx.UserProfiles.Where(u => users.Contains(u.Userid)))
                {
                    map.Add(userprofile.Userid, userprofile);
                }

                List <MembershipView> memberViews = new List <MembershipView>();
                foreach (var m in members)
                {
                    user = map[m.MemberID];
                    int isfollowing        = userid.Equals(user.Userid) ? -1 : (followings.Contains(user.Userid) ? 1 : 0);
                    DisplayUserProfile dup = new DisplayUserProfile(user, isfollowing);
                    MembershipView     mv  = new MembershipView();
                    mv.GroupID = groupID;
                    mv.Role    = m.Role;
                    mv.User    = dup;

                    memberViews.Add(mv);
                }
                return(memberViews);
            }
        }
        public void Setup()
        {
            _user = new User {
                UserRef = Guid.NewGuid().ToString()
            };

            _teamMember = new Membership
            {
                UserId    = 12,
                AccountId = ExpectedAccountId,
                Role      = Role.Owner,
                User      = _user
            };

            _owner = new MembershipView
            {
                UserId    = 1,
                AccountId = ExpectedAccountId,
                Role      = Role.Owner
            };

            _command = new RemoveTeamMemberCommand
            {
                UserId          = _teamMember.UserId,
                UserRef         = Guid.NewGuid(),
                HashedAccountId = "123a",
                ExternalUserId  = Guid.NewGuid().ToString()
            };

            _validator = new Mock <IValidator <RemoveTeamMemberCommand> >();

            _validator.Setup(x => x.Validate(It.IsAny <RemoveTeamMemberCommand>())).Returns(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });

            _mediator             = new Mock <IMediator>();
            _membershipRepository = new Mock <IMembershipRepository>();

            _membershipRepository.Setup(x => x.Get(_teamMember.UserId, _teamMember.AccountId)).ReturnsAsync(_teamMember);
            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId)).ReturnsAsync(_owner);

            _publisher = new Mock <IEventPublisher>();

            _handler = new RemoveTeamMemberCommandHandler(_mediator.Object, _membershipRepository.Object, _validator.Object, _publisher.Object);
        }
        public void Arrange()
        {
            base.SetUp();

            _membershipView = new MembershipView
            {
                AccountId = 2,
                UserId    = long.Parse(ExternalUserId)
            };

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(It.IsAny <long>(), It.IsAny <string>()))
            .ReturnsAsync(_membershipView);

            Query = new GetUserAccountRoleQuery {
                HashedAccountId = HashedAccountId, ExternalUserId = ExternalUserId
            };
            RequestHandler = new GetUserAccountRoleHandler(RequestValidator.Object, _membershipRepository.Object);
        }
        public void IfTryingToRemoveYourselfThenMembershipIsNotRemoved()
        {
            const long accountId = 2;

            var ownerUser = new User
            {
                Id      = 2,
                UserRef = Guid.NewGuid().ToString()
            };

            var membership = new Membership
            {
                UserId    = ownerUser.Id,
                AccountId = accountId,
                Role      = Role.Owner
            };

            var ownerMembership = new MembershipView
            {
                UserId    = ownerUser.Id,
                AccountId = accountId,
                Role      = Role.Owner
            };

            var command = new RemoveTeamMemberCommand
            {
                UserId          = membership.UserId,
                HashedAccountId = "",
                ExternalUserId  = ownerUser.UserRef
            };

            _membershipRepository.Setup(x => x.Get(membership.UserId, membership.AccountId)).ReturnsAsync(membership);
            _membershipRepository.Setup(x => x.GetCaller(ExpectedAccountId, command.ExternalUserId)).ReturnsAsync(ownerMembership);

            var exception = Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(command));

            Assert.That(exception.ErrorMessages.Count, Is.EqualTo(1));
            Assert.That(exception.ErrorMessages.FirstOrDefault(x => x.Key == "Membership"), Is.Not.Null);

            _membershipRepository.Verify(x => x.Remove(command.UserId, ExpectedAccountId), Times.Never);
        }
        public override void Arrange()
        {
            base.Arrange();

            _owner = new MembershipView
            {
                AccountId = 1234,
                UserId    = 9876,
                Email     = "*****@*****.**",
                FirstName = "Bob",
                LastName  = "Green",
                UserRef   = Guid.Parse(Command.ExternalUserId),
                Role      = Role.Owner,
            };

            _agreementView = new EmployerAgreementView
            {
                Id                       = 123,
                AccountId                = _owner.AccountId,
                SignedDate               = DateTime.Now,
                SignedByName             = $"{_owner.FirstName} {_owner.LastName}",
                LegalEntityId            = 5246,
                LegalEntityName          = "Test Corp",
                LegalEntityCode          = "3476782638",
                LegalEntitySource        = OrganisationType.CompaniesHouse,
                LegalEntityAddress       = "123 test street",
                LegalEntityInceptionDate = DateTime.Now,
                AccountLegalEntityId     = 830
            };

            MembershipRepository.Setup(x => x.GetCaller(Command.HashedAccountId, Command.ExternalUserId)).ReturnsAsync(_owner);

            AccountRepository.Setup(x => x.CreateLegalEntityWithAgreement(It.Is <CreateLegalEntityWithAgreementParams>(createParams => createParams.AccountId == _owner.AccountId))).ReturnsAsync(_agreementView);

            HashingService.Setup(hs => hs.HashValue(It.IsAny <long>())).Returns <long>(value => $"*{value}*");
            HashingService.Setup(hs => hs.DecodeValue(Command.HashedAccountId)).Returns(_owner.AccountId);

            AccountLegalEntityPublicHashingService.Setup(x => x.HashValue(_agreementView.AccountLegalEntityId)).Returns(ExpectedAccountLegalEntityPublicHashString);
        }
コード例 #17
0
        public async Task <ActionResult> Add(Movie movie)
        {
            var userid = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            var customerlgn          = _context.Customers.SingleOrDefault(m => m.Email == userid.Email);
            var chosenmv             = _context.Movies.SingleOrDefault(m => m.Id == movie.Id);
            List <MembershipView> li = new List <MembershipView>();
            var customerView         = new MembershipView
            {
                Movie           = chosenmv,
                Customer        = customerlgn,
                MembershipTypes = _context.MembershipType.ToList(),
            };

            if (Session["cart"] == null)
            {
                li.Add(customerView);
                Session["cart"] = li;
                ViewBag.cart    = li.Count();


                Session["count"] = 1;
            }
            else
            {
                li = (List <MembershipView>)Session["cart"];
                if (!li.Any(n => n.Movie.Id == movie.Id))
                {
                    Session["cart"] = li;
                }

                li.Add(customerView);
                Session["cart"]  = li;
                ViewBag.cart     = li.Count();
                Session["count"] = Convert.ToInt32(Session["count"]) + 1;
            }
            return(RedirectToAction("Fantasy", "Home"));
        }
コード例 #18
0
        public void Setup()
        {
            _membershipRepository = new Mock <IMembershipRepository>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(It.IsAny <string>())).Returns(AgreementId);
            _hashingService.Setup(x => x.HashValue(It.IsAny <long>())).Returns(HashedLegalEntityId);

            _validator = new Mock <IValidator <SignEmployerAgreementCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <SignEmployerAgreementCommand>())).ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string> ()
            });


            _agreement = new EmployerAgreementView
            {
                HashedAgreementId = "124GHJG",
                LegalEntityId     = 56465
            };

            _agreementRepository = new Mock <IEmployerAgreementRepository>();

            _agreementRepository.Setup(x => x.GetEmployerAgreement(It.IsAny <long>()))
            .ReturnsAsync(_agreement);

            _agreementEventFactory = new Mock <IEmployerAgreementEventFactory>();

            _agreementEvent = new AgreementSignedEvent();

            _agreementEventFactory.Setup(
                x => x.CreateSignedEvent(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(_agreementEvent);

            _genericEventFactory = new Mock <IGenericEventFactory>();
            _mediator            = new Mock <IMediator>();

            _handler = new SignEmployerAgreementCommandHandler(
                _membershipRepository.Object,
                _agreementRepository.Object,
                _hashingService.Object,
                _validator.Object,
                _agreementEventFactory.Object,
                _genericEventFactory.Object,
                _mediator.Object);

            _command = new SignEmployerAgreementCommand
            {
                HashedAccountId   = "1AVCFD",
                HashedAgreementId = "2EQWE34",
                ExternalUserId    = Guid.NewGuid().ToString(),
                SignedDate        = DateTime.Now
            };

            _owner = new MembershipView
            {
                UserId    = 1,
                RoleId    = (short)Role.Owner,
                FirstName = "Fred",
                LastName  = "Bloggs"
            };

            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId))
            .ReturnsAsync(_owner);
        }
コード例 #19
0
        public void Arrange()
        {
            _accountRepository    = new Mock <IAccountRepository>();
            _membershipRepository = new Mock <IMembershipRepository>();
            _mediator             = new Mock <IMediator>();

            _owner = new MembershipView
            {
                AccountId = 1234,
                UserId    = 9876,
                Email     = "*****@*****.**",
                FirstName = "Bob",
                LastName  = "Green",
                UserRef   = Guid.NewGuid().ToString(),
                Role      = Role.Owner,
            };

            _agreementView = new EmployerAgreementView
            {
                Id                       = 123,
                AccountId                = _owner.AccountId,
                SignedDate               = DateTime.Now,
                SignedByName             = $"{_owner.FirstName} {_owner.LastName}",
                LegalEntityId            = 5246,
                LegalEntityName          = "Test Corp",
                LegalEntityCode          = "3476782638",
                LegalEntitySource        = OrganisationType.CompaniesHouse,
                LegalEntityAddress       = "123 test street",
                LegalEntityInceptionDate = DateTime.Now,
                AccountLegalEntityId     = 830
            };

            _command = new CreateLegalEntityCommand
            {
                HashedAccountId = "ABC123",
                SignAgreement   = true,
                SignedDate      = DateTime.Now.AddDays(-10),
                ExternalUserId  = _owner.UserRef,
                Name            = "Org Ltd",
                Code            = "3476782638",
                Source          = OrganisationType.CompaniesHouse,
                Address         = "123 test street"
            };

            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId))
            .ReturnsAsync(_owner);

            _accountRepository
            .Setup(x => x.CreateLegalEntityWithAgreement(It.Is <CreateLegalEntityWithAgreementParams>(
                                                             createParams => createParams.AccountId == _owner.AccountId)))
            .ReturnsAsync(_agreementView);

            _genericEventFactory     = new Mock <IGenericEventFactory>();
            _legalEntityEventFactory = new Mock <ILegalEntityEventFactory>();
            _eventPublisher          = new Mock <IEventPublisher>();
            _agreementService        = new Mock <IAgreementService>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(hs => hs.HashValue(It.IsAny <long>())).Returns <long>(value => $"*{value}*");
            _hashingService.Setup(hs => hs.DecodeValue(_command.HashedAccountId)).Returns(_owner.AccountId);

            _accountLegalEntityPublicHashingService = new Mock <IAccountLegalEntityPublicHashingService>();
            _accountLegalEntityPublicHashingService.Setup(x => x.HashValue(_agreementView.AccountLegalEntityId)).Returns(ExpectedAccountLegalEntityPublicHashString);

            _employerAgreementRepository = new Mock <IEmployerAgreementRepository>();

            _validator = new Mock <IValidator <CreateLegalEntityCommand> >();

            _validator.Setup(x => x.ValidateAsync(It.IsAny <CreateLegalEntityCommand>()))
            .ReturnsAsync(new ValidationResult()
            {
                IsUnauthorized = false
            });

            _commandHandler = new CreateLegalEntityCommandHandler(
                _accountRepository.Object,
                _membershipRepository.Object,
                _mediator.Object,
                _genericEventFactory.Object,
                _legalEntityEventFactory.Object,
                _eventPublisher.Object,
                _hashingService.Object,
                _accountLegalEntityPublicHashingService.Object,
                _agreementService.Object,
                _employerAgreementRepository.Object,
                _validator.Object
                );
        }
コード例 #20
0
 private async Task PublishEvents(SignEmployerAgreementCommand message, string hashedLegalEntityId, EmployerAgreementView agreement, MembershipView owner, string correlationId)
 {
     await Task.WhenAll(
         PublishLegalGenericEvent(message, hashedLegalEntityId),
         PublihAgreementSignedMessage(agreement, owner, correlationId)
         );
 }
コード例 #21
0
        private async Task PublihAgreementSignedMessage(EmployerAgreementView agreement, MembershipView owner, string correlationId)
        {
            var commitments = await _commitmentService.GetEmployerCommitments(agreement.AccountId);

            var accountHasCommitments = commitments?.Any() ?? false;

            await PublishAgreementSignedMessage(agreement.AccountId, agreement.AccountLegalEntityId, agreement.LegalEntityId, agreement.LegalEntityName,
                                                agreement.Id, accountHasCommitments, owner.FullName(), owner.UserRef, agreement.AgreementType,
                                                agreement.VersionNumber, correlationId);
        }
        private async Task CreateAuditEntries(MembershipView owner, EmployerAgreementView agreementView)
        {
            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "UPDATED",
                    Description       = $"User {owner.Email} added legal entity {agreementView.LegalEntityId} to account {owner.AccountId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        new PropertyUpdate {
                            PropertyName = "AccountId", NewValue = agreementView.AccountId.ToString()
                        },
                        new PropertyUpdate {
                            PropertyName = "Id", NewValue = agreementView.LegalEntityId.ToString()
                        },
                        new PropertyUpdate {
                            PropertyName = "Name", NewValue = agreementView.LegalEntityName
                        },
                        new PropertyUpdate {
                            PropertyName = "Code", NewValue = agreementView.LegalEntityCode
                        },
                        new PropertyUpdate {
                            PropertyName = "Status", NewValue = agreementView.LegalEntityStatus
                        },
                        new PropertyUpdate {
                            PropertyName = "Address", NewValue = agreementView.LegalEntityAddress
                        },
                        new PropertyUpdate {
                            PropertyName = "DateOfInception", NewValue = agreementView.LegalEntityInceptionDate.GetDateString("G")
                        },
                    },
                    RelatedEntities = new List <Entity> {
                        new Entity {
                            Id = agreementView.AccountId.ToString(), Type = "Account"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "LegalEntity", Id = agreementView.LegalEntityId.ToString()
                    }
                }
            });

            await _mediator.SendAsync(new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category          = "UPDATED",
                    Description       = $"User {owner.Email} added signed agreement {agreementView.Id} to account {owner.AccountId}",
                    ChangedProperties = new List <PropertyUpdate>
                    {
                        new PropertyUpdate {
                            PropertyName = "AccountId", NewValue = agreementView.AccountId.ToString()
                        },
                        new PropertyUpdate {
                            PropertyName = "SignedDate", NewValue = agreementView.SignedDate.GetDateString("G")
                        },
                        new PropertyUpdate {
                            PropertyName = "SignedBy", NewValue = $"{owner.FirstName} {owner.LastName}"
                        }
                    },
                    RelatedEntities = new List <Entity> {
                        new Entity {
                            Id = agreementView.AccountId.ToString(), Type = "Account"
                        }
                    },
                    AffectedEntity = new Entity {
                        Type = "EmployerAgreement", Id = agreementView.Id.ToString()
                    }
                }
            });
        }
コード例 #23
0
        private async Task <bool> UserIsWhitelistedForEOIOrThereIsAlreadyAnEOIAgreementForThisAccount(MembershipView accountOwner)
        {
            if (_authorizationService.IsAuthorized("EmployerFeature.ExpressionOfInterest"))
            {
                return(true);
            }

            var existingAgreements = await _employerAgreementRepository.GetAccountAgreements(accountOwner.AccountId);

            return
                (existingAgreements.Any(a => a.Template.AgreementType.Equals(AgreementType.NonLevyExpressionOfInterest)));
        }
        public void Setup()
        {
            _command = new SignEmployerAgreementCommand
            {
                HashedAccountId   = "1AVCFD",
                HashedAgreementId = "2EQWE34",
                ExternalUserId    = Guid.NewGuid().ToString(),
                SignedDate        = DateTime.Now
            };

            _membershipRepository = new Mock <IMembershipRepository>();

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue(_command.HashedAccountId)).Returns(AccountId);
            _hashingService.Setup(x => x.DecodeValue(_command.HashedAgreementId)).Returns(AgreementId);
            _hashingService.Setup(x => x.HashValue(It.IsAny <long>())).Returns(HashedLegalEntityId);

            _validator = new Mock <IValidator <SignEmployerAgreementCommand> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <SignEmployerAgreementCommand>())).ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });


            _agreement = new EmployerAgreementView
            {
                HashedAgreementId    = "124GHJG",
                LegalEntityId        = LegalEntityId,
                LegalEntityName      = OrganisationName,
                AgreementType        = AgreementType,
                AccountId            = AccountId,
                AccountLegalEntityId = AccountLegalEntityId,
                Id = AgreementId
            };

            _agreementRepository = new Mock <IEmployerAgreementRepository>();

            _agreementRepository.Setup(x => x.GetEmployerAgreement(It.IsAny <long>()))
            .ReturnsAsync(_agreement);

            _agreementEventFactory = new Mock <IEmployerAgreementEventFactory>();

            _agreementEvent = new AgreementSignedEvent();

            _agreementEventFactory.Setup(
                x => x.CreateSignedEvent(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(_agreementEvent);

            _genericEventFactory = new Mock <IGenericEventFactory>();
            _mediator            = new Mock <IMediator>();

            _mediator.Setup(x => x.SendAsync(It.Is <GetUserByRefQuery>(s => s.UserRef == _command.ExternalUserId))).ReturnsAsync(new GetUserByRefResponse {
                User = new User {
                    CorrelationId = "CORRELATION_ID"
                }
            });

            _commintmentService = new Mock <ICommitmentService>();

            _commintmentService.Setup(x => x.GetEmployerCommitments(It.IsAny <long>()))
            .ReturnsAsync(new List <Cohort>());

            _eventPublisher = new TestableEventPublisher();

            _handler = new SignEmployerAgreementCommandHandler(
                _membershipRepository.Object,
                _agreementRepository.Object,
                _hashingService.Object,
                _validator.Object,
                _agreementEventFactory.Object,
                _genericEventFactory.Object,
                _mediator.Object,
                _eventPublisher,
                _commintmentService.Object);

            _owner = new MembershipView
            {
                UserId    = 1,
                Role      = Role.Owner,
                FirstName = "Fred",
                LastName  = "Bloggs",
                UserRef   = Guid.NewGuid()
            };

            _membershipRepository.Setup(x => x.GetCaller(_command.HashedAccountId, _command.ExternalUserId))
            .ReturnsAsync(_owner);
        }
コード例 #25
0
        private async Task SignAgreement(SignEmployerAgreementCommand message, long agreementId, MembershipView owner)
        {
            var signedAgreementDetails = new Models.EmployerAgreement.SignEmployerAgreement
            {
                SignedDate   = message.SignedDate,
                AgreementId  = agreementId,
                SignedById   = owner.UserId,
                SignedByName = $"{owner.FirstName} {owner.LastName}"
            };

            await _employerAgreementRepository.SignAgreement(signedAgreementDetails);
        }