Example #1
0
        public TechnicalAdvisorServiceTests()
        {
            _loggerAdapter = Substitute.For <ILoggerAdapter>();
            _nyssContext   = Substitute.For <INyssContext>();
            _identityUserRegistrationServiceMock = Substitute.For <IIdentityUserRegistrationService>();
            _verificationEmailServiceMock        = Substitute.For <IVerificationEmailService>();
            _nationalSocietyUserService          = Substitute.For <INationalSocietyUserService>();
            _deleteUserService = Substitute.For <IDeleteUserService>();

            var applicationLanguages      = new List <ApplicationLanguage>();
            var applicationLanguagesDbSet = applicationLanguages.AsQueryable().BuildMockDbSet();

            _nyssContext.ApplicationLanguages.Returns(applicationLanguagesDbSet);

            _technicalAdvisorService = new TechnicalAdvisorService(_identityUserRegistrationServiceMock, _nationalSocietyUserService, _nyssContext, _loggerAdapter, _verificationEmailServiceMock,
                                                                   _deleteUserService);

            _identityUserRegistrationServiceMock.CreateIdentityUser(Arg.Any <string>(), Arg.Any <Role>()).Returns(ci => new IdentityUser
            {
                Id    = "123",
                Email = (string)ci[0]
            });

            SetupTestNationalSocieties();
        }
Example #2
0
 public TechnicalAdvisorService(IIdentityUserRegistrationService identityUserRegistrationService, INationalSocietyUserService nationalSocietyUserService, INyssContext dataContext,
                                ILoggerAdapter loggerAdapter, IVerificationEmailService verificationEmailService, IDeleteUserService deleteUserService)
 {
     _identityUserRegistrationService = identityUserRegistrationService;
     _dataContext   = dataContext;
     _loggerAdapter = loggerAdapter;
     _nationalSocietyUserService = nationalSocietyUserService;
     _verificationEmailService   = verificationEmailService;
     _deleteUserService          = deleteUserService;
 }
 public GlobalCoordinatorService(
     IIdentityUserRegistrationService identityUserRegistrationService,
     INyssContext dataContext,
     ILoggerAdapter loggerAdapter, IVerificationEmailService verificationEmailService, IDeleteUserService deleteUserService)
 {
     _identityUserRegistrationService = identityUserRegistrationService;
     _dataContext              = dataContext;
     _loggerAdapter            = loggerAdapter;
     _verificationEmailService = verificationEmailService;
     _deleteUserService        = deleteUserService;
 }
        public GlobalCoordinatorServiceTests()
        {
            _loggerAdapter = Substitute.For <ILoggerAdapter>();
            _nyssContext   = Substitute.For <INyssContext>();
            _identityUserRegistrationServiceMock = Substitute.For <IIdentityUserRegistrationService>();
            _verificationEmailServiceMock        = Substitute.For <IVerificationEmailService>();
            _deleteUserService = Substitute.For <IDeleteUserService>();

            _globalCoordinatorService =
                new GlobalCoordinatorService(_identityUserRegistrationServiceMock, _nyssContext, _loggerAdapter, _verificationEmailServiceMock, _deleteUserService);

            _identityUserRegistrationServiceMock.CreateIdentityUser(Arg.Any <string>(), Arg.Any <Role>()).Returns(ci => new IdentityUser
            {
                Id    = "123",
                Email = (string)ci[0]
            });

            ArrangeApplicationLanguages();
        }
        public DataConsumerServiceTests()
        {
            _loggerAdapter = Substitute.For <ILoggerAdapter>();
            _nyssContext   = Substitute.For <INyssContext>();
            _identityUserRegistrationServiceMock = Substitute.For <IIdentityUserRegistrationService>();
            _verificationEmailServiceMock        = Substitute.For <IVerificationEmailService>();
            _nationalSocietyUserService          = Substitute.For <INationalSocietyUserService>();
            _deleteUserService = Substitute.For <IDeleteUserService>();

            _dataConsumerService = new DataConsumerService(_identityUserRegistrationServiceMock, _nationalSocietyUserService, _nyssContext, _loggerAdapter, _verificationEmailServiceMock,
                                                           _deleteUserService);

            _identityUserRegistrationServiceMock.CreateIdentityUser(Arg.Any <string>(), Arg.Any <Role>()).Returns(ci => new IdentityUser
            {
                Id    = "123",
                Email = (string)ci[0]
            });

            SetupTestNationalSocieties();
        }
Example #6
0
        public ManagerServiceTests()
        {
            _loggerAdapter = Substitute.For <ILoggerAdapter>();
            _nyssContext   = Substitute.For <INyssContext>();
            _identityUserRegistrationServiceMock = Substitute.For <IIdentityUserRegistrationService>();
            _verificationEmailServiceMock        = Substitute.For <IVerificationEmailService>();
            _nationalSocietyUserService          = Substitute.For <INationalSocietyUserService>();
            _deleteUserService = Substitute.For <IDeleteUserService>();

            _managerService = new ManagerService(_identityUserRegistrationServiceMock, _nationalSocietyUserService, _nyssContext, _loggerAdapter, _verificationEmailServiceMock, _deleteUserService);


            var nationalSocieties = new List <NationalSociety>
            {
                new NationalSociety
                {
                    Id   = _nationalSocietyId,
                    Name = "Test national society"
                }
            };
            var applicationLanguages = new List <ApplicationLanguage>();
            var users = new List <User>
            {
                new AdministratorUser
                {
                    Id   = _administratorId,
                    Role = Role.Administrator
                },
                new ManagerUser
                {
                    Id                    = _managerId,
                    Role                  = Role.Manager,
                    EmailAddress          = "*****@*****.**",
                    Name                  = "*****@*****.**",
                    Organization          = "org org",
                    PhoneNumber           = "123",
                    AdditionalPhoneNumber = "321"
                }
            };
            var userNationalSocieties = new List <UserNationalSociety>
            {
                new UserNationalSociety
                {
                    User              = users[1],
                    UserId            = _managerId,
                    NationalSocietyId = _nationalSocietyId,
                    NationalSociety   = nationalSocieties[0]
                }
            };

            users[1].UserNationalSocieties = new List <UserNationalSociety> {
                userNationalSocieties[0]
            };

            var applicationLanguagesDbSet = applicationLanguages.AsQueryable().BuildMockDbSet();
            var usersDbSet                 = users.AsQueryable().BuildMockDbSet();
            var nationalSocietiesDbSet     = nationalSocieties.AsQueryable().BuildMockDbSet();
            var userNationalSocietiesDbSet = userNationalSocieties.AsQueryable().BuildMockDbSet();

            _nyssContext.ApplicationLanguages.Returns(applicationLanguagesDbSet);
            _nyssContext.Users.Returns(usersDbSet);
            _nyssContext.NationalSocieties.Returns(nationalSocietiesDbSet);
            _nyssContext.UserNationalSocieties.Returns(userNationalSocietiesDbSet);

            _identityUserRegistrationServiceMock.CreateIdentityUser(Arg.Any <string>(), Arg.Any <Role>()).Returns(ci => new IdentityUser
            {
                Id    = "123",
                Email = (string)ci[0]
            });
            _nyssContext.NationalSocieties.FindAsync(1).Returns(nationalSocieties[0]);

            _nationalSocietyUserService.GetNationalSocietyUser <ManagerUser>(Arg.Any <int>()).Returns(ci =>
            {
                var user = users.OfType <ManagerUser>().FirstOrDefault(x => x.Id == (int)ci[0]);
                if (user == null)
                {
                    throw new ResultException(ResultKey.User.Registration.UserNotFound);
                }

                return(user);
            });

            _nationalSocietyUserService.GetNationalSocietyUserIncludingNationalSocieties <ManagerUser>(Arg.Any <int>())
            .Returns(ci => _nationalSocietyUserService.GetNationalSocietyUser <ManagerUser>((int)ci[0]));
        }
Example #7
0
        public SupervisorServiceTests()
        {
            _loggerAdapter = Substitute.For <ILoggerAdapter>();
            _nyssContext   = Substitute.For <INyssContext>();
            _identityUserRegistrationServiceMock = Substitute.For <IIdentityUserRegistrationService>();
            _verificationEmailServiceMock        = Substitute.For <IVerificationEmailService>();
            _nationalSocietyUserService          = Substitute.For <INationalSocietyUserService>();
            _deleteUserService = Substitute.For <IDeleteUserService>();
            var dateTimeProvider          = Substitute.For <IDateTimeProvider>();
            var applicationLanguages      = new List <ApplicationLanguage>();
            var applicationLanguagesDbSet = applicationLanguages.AsQueryable().BuildMockDbSet();

            _nyssContext.ApplicationLanguages.Returns(applicationLanguagesDbSet);

            _supervisorService = new SupervisorService(_identityUserRegistrationServiceMock, _nationalSocietyUserService, _nyssContext, _loggerAdapter, _verificationEmailServiceMock,
                                                       _deleteUserService, dateTimeProvider);

            _identityUserRegistrationServiceMock.CreateIdentityUser(Arg.Any <string>(), Arg.Any <Role>()).Returns(ci => new IdentityUser
            {
                Id    = "123",
                Email = (string)ci[0]
            });


            var nationalSocieties = new List <NationalSociety>
            {
                new NationalSociety
                {
                    Id   = _nationalSocietyId1,
                    Name = "Test national society 1"
                },
                new NationalSociety
                {
                    Id   = _nationalSocietyId2,
                    Name = "Test national society 2"
                }
            };

            var projects = new List <Project>
            {
                new Project
                {
                    Id = _projectId1,
                    NationalSociety = nationalSocieties[0],
                    Name            = "project 1",
                    State           = ProjectState.Open
                },
                new Project
                {
                    Id = _projectId2,
                    NationalSociety = nationalSocieties[0],
                    Name            = "project 2",
                    State           = ProjectState.Open
                },
                new Project
                {
                    Id = _projectId3,
                    NationalSociety = nationalSocieties[0],
                    Name            = "project 3",
                    State           = ProjectState.Closed
                },
                new Project
                {
                    Id = _projectId4,
                    NationalSociety = nationalSocieties[1],
                    Name            = "project 4",
                    State           = ProjectState.Open
                },
                new Project
                {
                    Id = _projectId5,
                    NationalSociety = nationalSocieties[1],
                    Name            = "project 5",
                    State           = ProjectState.Open
                }
            };

            var users = new List <User>
            {
                new AdministratorUser
                {
                    Id   = _administratorId,
                    Role = Role.Administrator
                },
                new SupervisorUser
                {
                    Id                    = _supervisorWithDataCollectorsId,
                    Role                  = Role.Supervisor,
                    EmailAddress          = "*****@*****.**",
                    Name                  = "*****@*****.**",
                    PhoneNumber           = "123",
                    AdditionalPhoneNumber = "321",
                    Sex                   = Sex.Male,
                    DecadeOfBirth         = 1990
                },
                new SupervisorUser
                {
                    Id                    = _supervisorWithoutDataCollectorsId,
                    Role                  = Role.Supervisor,
                    EmailAddress          = "*****@*****.**",
                    Name                  = "*****@*****.**",
                    PhoneNumber           = "123456",
                    AdditionalPhoneNumber = "321",
                    Sex                   = Sex.Male,
                    DecadeOfBirth         = 1990
                },
                new SupervisorUser
                {
                    Id                    = _supervisorWithDeletedDataCollectorsId,
                    Role                  = Role.Supervisor,
                    EmailAddress          = "*****@*****.**",
                    Name                  = "*****@*****.**",
                    PhoneNumber           = "123456",
                    AdditionalPhoneNumber = "321",
                    Sex                   = Sex.Male,
                    DecadeOfBirth         = 1990
                }
            };

            var supervisorWithDataCollectors        = (SupervisorUser)users[1];
            var supervisorWithoutDataCollectors     = (SupervisorUser)users[2];
            var supervisorWithDeletedDataCollectors = (SupervisorUser)users[3];
            var supervisorUserProjects = new List <SupervisorUserProject>
            {
                new SupervisorUserProject
                {
                    Project          = projects[0],
                    ProjectId        = _projectId1,
                    SupervisorUser   = supervisorWithDataCollectors,
                    SupervisorUserId = _supervisorWithDataCollectorsId
                },
                new SupervisorUserProject
                {
                    Project          = projects[2],
                    ProjectId        = _projectId3,
                    SupervisorUser   = supervisorWithDataCollectors,
                    SupervisorUserId = _supervisorWithDataCollectorsId
                },
                new SupervisorUserProject
                {
                    Project          = projects[1],
                    ProjectId        = _projectId3,
                    SupervisorUser   = supervisorWithoutDataCollectors,
                    SupervisorUserId = _supervisorWithoutDataCollectorsId
                },
                new SupervisorUserProject
                {
                    Project          = projects[0],
                    ProjectId        = _projectId1,
                    SupervisorUser   = supervisorWithDeletedDataCollectors,
                    SupervisorUserId = _supervisorWithDeletedDataCollectorsId
                }
            };

            supervisorWithDataCollectors.SupervisorUserProjects = new List <SupervisorUserProject>
            {
                supervisorUserProjects[0],
                supervisorUserProjects[1]
            };
            supervisorWithoutDataCollectors.SupervisorUserProjects = new List <SupervisorUserProject> {
                supervisorUserProjects[2]
            };
            supervisorWithDeletedDataCollectors.SupervisorUserProjects = new List <SupervisorUserProject> {
                supervisorUserProjects[3]
            };

            supervisorWithDataCollectors.CurrentProject        = supervisorWithDataCollectors.SupervisorUserProjects.Single(p => p.Project.State == ProjectState.Open).Project;
            supervisorWithoutDataCollectors.CurrentProject     = supervisorWithoutDataCollectors.SupervisorUserProjects.Single(p => p.Project.State == ProjectState.Open).Project;
            supervisorWithDeletedDataCollectors.CurrentProject = supervisorWithDeletedDataCollectors.SupervisorUserProjects.Single(p => p.Project.State == ProjectState.Open).Project;

            var userNationalSocieties = new List <UserNationalSociety>
            {
                new UserNationalSociety
                {
                    NationalSociety   = nationalSocieties[0],
                    NationalSocietyId = _nationalSocietyId1,
                    User   = supervisorWithDataCollectors,
                    UserId = _supervisorWithDataCollectorsId
                },
                new UserNationalSociety
                {
                    NationalSociety   = nationalSocieties[0],
                    NationalSocietyId = _nationalSocietyId1,
                    User   = supervisorWithoutDataCollectors,
                    UserId = _supervisorWithoutDataCollectorsId
                },
                new UserNationalSociety
                {
                    NationalSociety   = nationalSocieties[0],
                    NationalSocietyId = _nationalSocietyId1,
                    User   = supervisorWithDeletedDataCollectors,
                    UserId = _supervisorWithDeletedDataCollectorsId
                }
            };

            supervisorWithDataCollectors.UserNationalSocieties = new List <UserNationalSociety> {
                userNationalSocieties[0]
            };
            supervisorWithoutDataCollectors.UserNationalSocieties = new List <UserNationalSociety> {
                userNationalSocieties[1]
            };
            supervisorWithDeletedDataCollectors.UserNationalSocieties = new List <UserNationalSociety> {
                userNationalSocieties[2]
            };

            var dataCollectors = new List <DataCollector>
            {
                new DataCollector
                {
                    Id         = _dataCollectorId,
                    Supervisor = supervisorWithDataCollectors
                },
                new DataCollector
                {
                    Id         = _deletedDataCollectorId,
                    Supervisor = supervisorWithDeletedDataCollectors,
                    DeletedAt  = new DateTime(2020, 01, 01)
                }
            };


            var supervisorUserProjectsDbSet = supervisorUserProjects.AsQueryable().BuildMockDbSet();
            var nationalSocietiesDbSet      = nationalSocieties.AsQueryable().BuildMockDbSet();
            var projectsDbSet = projects.AsQueryable().BuildMockDbSet();
            var usersDbSet    = users.AsQueryable().BuildMockDbSet();
            var userNationalSocietiesDbSet = userNationalSocieties.AsQueryable().BuildMockDbSet();
            var dataCollectorsDbSet        = dataCollectors.AsQueryable().BuildMockDbSet();

            _nyssContext.NationalSocieties.Returns(nationalSocietiesDbSet);
            _nyssContext.Projects.Returns(projectsDbSet);
            _nyssContext.Users.Returns(usersDbSet);
            _nyssContext.SupervisorUserProjects.Returns(supervisorUserProjectsDbSet);
            _nyssContext.UserNationalSocieties.Returns(userNationalSocietiesDbSet);
            _nyssContext.DataCollectors.Returns(dataCollectorsDbSet);


            _nyssContext.NationalSocieties.FindAsync(1).Returns(nationalSocieties[0]);
            _nyssContext.NationalSocieties.FindAsync(2).Returns(nationalSocieties[1]);


            _nationalSocietyUserService.GetNationalSocietyUser <SupervisorUser>(Arg.Any <int>()).Returns(ci =>
            {
                var user = users.OfType <SupervisorUser>().FirstOrDefault(x => x.Id == (int)ci[0]);
                if (user == null)
                {
                    throw new ResultException(ResultKey.User.Registration.UserNotFound);
                }

                return(user);
            });
        }