public void GetPasswdByUserName_Should_Return_Passwd_Info() { var actual = Syscall.GetPasswdByUserName("root"); Assert.Equal("root", actual.pw_name); Assert.Equal("root", actual.pw_gecos); Assert.Equal("/root", actual.pw_dir); Assert.Equal("x", actual.pw_passwd); Assert.Equal("/bin/bash", actual.pw_shell); Assert.Equal(0u, actual.pw_uid); Assert.Equal(0u, actual.pw_gid); }
public void GetPasswdByUserName_Should_Return_Empty_If_Passwd_Not_Found() { var expected = new Syscall.Passwd(); var actual = Syscall.GetPasswdByUserName(Guid.NewGuid().ToString()); Assert.Equal(expected.pw_uid, actual.pw_uid); Assert.Equal(expected.pw_gid, actual.pw_gid); Assert.Equal(expected.pw_gecos, actual.pw_gecos); Assert.Equal(expected.pw_dir, actual.pw_dir); Assert.Equal(expected.pw_name, actual.pw_name); Assert.Equal(expected.pw_passwd, actual.pw_passwd); Assert.Equal(expected.pw_shell, actual.pw_shell); }
public void GetPasswdByUserName_Should_Retrieve_Passwd_Thread_Safe() { var simpleUserId = GetSimpleUserId(); var rootId = 0; var expected = Syscall.GetPasswdByUserId(simpleUserId); var rootExpected = Syscall.GetPasswdByUserId(rootId); var tasksCount = 1024; var tasks = new Task <KeyValuePair <string, Syscall.Passwd> > [tasksCount]; for (var i = 0; i < tasksCount; i++) { tasks[i] = i % 2 == 0 ? new Task <KeyValuePair <string, Syscall.Passwd> >(() => new KeyValuePair <string, Syscall.Passwd>(expected.pw_name, Syscall.GetPasswdByUserName(expected.pw_name))) :new Task <KeyValuePair <string, Syscall.Passwd> >(() => new KeyValuePair <string, Syscall.Passwd>(rootExpected.pw_name, Syscall.GetPasswdByUserName(rootExpected.pw_name))); } tasks.ForEach(_ => _.Start()); var actual = Task.WhenAll(tasks).Result; var root = actual.Where(_ => _.Key == rootExpected.pw_name); var simple = actual.Where(_ => _.Key == expected.pw_name); Assert.All(root, _ => AssertEqual(rootExpected, _.Value)); Assert.All(simple, _ => AssertEqual(expected, _.Value)); }