public CandidateRole GetCandidateRoleById(int id) { CandidateRole res = null; var query = "SELECT [CR].[Id], " + " [CR].[Code]," + " [CR].[Name] " + "FROM [dbo].[CandidateRole] AS [CR] " + "WHERE [CR].[Id] = @id"; using (var conn = new SqlConnection(Config.GetConnectionString())) { using (var cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add("@id", SqlDbType.Int); cmd.Parameters["@id"].Value = id; conn.Open(); var dt = new DataTable(); var da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count == 1) { res = getCandidateRoleFromDataRow(dt.Rows[0]); } } } return(res); }
private CandidateRole getCandidateRoleFromDataRow(DataRow dr) { CandidateRole res = null; res = new CandidateRole() { Id = dr.Db2Int("Id"), Code = dr.Db2String("Code"), Name = dr.Db2String("Name"), }; return(res); }
private Candidate getCandidateFromDataRow(DataRow dr, DeliveryUnit deliveryUnit, CandidateRole candidateRole, Project currentProject, List <Evaluation> evaluations) { Candidate res = null; string pictureFullUrl = getPictureFromDB(dr.Db2String("Picture")); res = new Candidate() { Id = dr.Db2Int("Id"), DeliveryUnitId = dr.Db2Int("DeliveryUnitId"), DeliveryUnit = deliveryUnit, RelationType = (CandidateRelationType)dr.Db2Int("RelationType"), FirstName = dr.Db2String("FirstName"), LastName = dr.Db2String("LastName"), CandidateRoleId = dr.Db2Int("CandidateRoleId"), CandidateRole = candidateRole, DocType = (DocumentType?)dr.Db2NullableInt("DocType"), DocNumber = dr.Db2String("DocNumber"), EmployeeNumber = dr.Db2NullableInt("EmployeeNumber"), InBench = dr.Db2Bool("InBench"), Picture = pictureFullUrl, IsActive = dr.Db2Bool("IsActive"), Grade = (CandidateGrade?)dr.Db2NullableInt("Grade"), CurrentProjectId = dr.Db2NullableInt("CurrentProjectId"), CurrentProjectJoin = dr.Db2NullableDateTime("CurrentProjectJoin"), CurrentProject = currentProject, Evaluations = evaluations, }; return(res); }
public CandidateRoleTests(ITestOutputHelper output) { var builder = new AutoSubstitute(cb => cb.Register(_ => Substitute.For <IRaftGrain <int> >()).InstancePerDependency()); builder.Provide <ILogger>(new TestLogger(output)); this.volatileState = new VolatileState(); builder.Provide <IRaftVolatileState>(this.volatileState); // Configure settings this.settings = builder.Resolve <ISettings>(); this.settings.MinElectionTimeoutMilliseconds.Returns(MinElectionTime); this.settings.MaxElectionTimeoutMilliseconds.Returns(MaxElectionTime); // Rig random number generator to always return the same value. this.random = builder.Resolve <IRandom>(); this.random.Next(Arg.Any <int>(), Arg.Any <int>()).Returns(RiggedRandomResult); this.coordinator = builder.Resolve <IRoleCoordinator <int> >(); this.coordinator.StepDownIfGreaterTerm(Arg.Any <IMessage>()) .Returns( info => Task.FromResult(((IMessage)info[0]).Term > this.persistentState.CurrentTerm)); var currentRole = builder.Resolve <IRaftRole <int> >(); currentRole.RequestVote(Arg.Any <RequestVoteRequest>()) .Returns(Task.FromResult(new RequestVoteResponse { Term = 1, VoteGranted = true })); currentRole.Append(Arg.Any <AppendRequest <int> >()) .Returns(Task.FromResult(new AppendResponse { Term = 1, Success = true })); this.coordinator.Role.Returns(currentRole); this.timers = new MockTimers(); builder.Provide <RegisterTimerDelegate>(this.timers.RegisterTimer); this.persistentState = Substitute.ForPartsOf <InMemoryPersistentState>(); builder.Provide <IRaftPersistentState>(this.persistentState); this.journal = Substitute.ForPartsOf <InMemoryLog <int> >(); builder.Provide <IPersistentLog <int> >(this.journal); this.identity = Substitute.For <IServerIdentity>(); this.identity.Id.Returns(Guid.NewGuid().ToString()); builder.Provide(this.identity); this.members = builder.Resolve <StaticMembershipProvider>(); this.members.SetServers(new[] { this.identity.Id, "other1", "other2", "other3", "other4" }); builder.Provide <IMembershipProvider>(this.members); this.grainFactory = new FakeGrainFactory(builder.Container); builder.Provide <IGrainFactory>(this.grainFactory); this.OnRaftGrainCreated = (id, grain) => grain.RequestVote(Arg.Any <RequestVoteRequest>()) .Returns(Task.FromResult(new RequestVoteResponse { VoteGranted = true })); // After the container is configured, resolve required services. this.role = builder.Resolve <CandidateRole <int> >(); this.container = builder; }
public CandidateRoleTests(ITestOutputHelper output) { var builder = new AutoSubstitute(cb => cb.Register(_ => Substitute.For<IRaftGrain<int>>()).InstancePerDependency()); builder.Provide<ILogger>(new TestLogger(output)); this.volatileState = new VolatileState(); builder.Provide<IRaftVolatileState>(this.volatileState); // Configure settings this.settings = builder.Resolve<ISettings>(); this.settings.MinElectionTimeoutMilliseconds.Returns(MinElectionTime); this.settings.MaxElectionTimeoutMilliseconds.Returns(MaxElectionTime); // Rig random number generator to always return the same value. this.random = builder.Resolve<IRandom>(); this.random.Next(Arg.Any<int>(), Arg.Any<int>()).Returns(RiggedRandomResult); this.coordinator = builder.Resolve<IRoleCoordinator<int>>(); this.coordinator.StepDownIfGreaterTerm(Arg.Any<IMessage>()) .Returns( info => Task.FromResult(((IMessage)info[0]).Term > this.persistentState.CurrentTerm)); var currentRole = builder.Resolve<IRaftRole<int>>(); currentRole.RequestVote(Arg.Any<RequestVoteRequest>()) .Returns(Task.FromResult(new RequestVoteResponse { Term = 1, VoteGranted = true })); currentRole.Append(Arg.Any<AppendRequest<int>>()) .Returns(Task.FromResult(new AppendResponse { Term = 1, Success = true })); this.coordinator.Role.Returns(currentRole); this.timers = new MockTimers(); builder.Provide<RegisterTimerDelegate>(this.timers.RegisterTimer); this.persistentState = Substitute.ForPartsOf<InMemoryPersistentState>(); builder.Provide<IRaftPersistentState>(this.persistentState); this.journal = Substitute.ForPartsOf<InMemoryLog<int>>(); builder.Provide<IPersistentLog<int>>(this.journal); this.identity = Substitute.For<IServerIdentity>(); this.identity.Id.Returns(Guid.NewGuid().ToString()); builder.Provide(this.identity); this.members = builder.Resolve<StaticMembershipProvider>(); this.members.SetServers(new[] { this.identity.Id, "other1", "other2", "other3", "other4" }); builder.Provide<IMembershipProvider>(this.members); this.grainFactory = new FakeGrainFactory(builder.Container); builder.Provide<IGrainFactory>(this.grainFactory); this.OnRaftGrainCreated = (id, grain) => grain.RequestVote(Arg.Any<RequestVoteRequest>()) .Returns(Task.FromResult(new RequestVoteResponse { VoteGranted = true })); // After the container is configured, resolve required services. this.role = builder.Resolve<CandidateRole<int>>(); this.container = builder; }