public void AddEmployeeTest()
        {
            var emp = new Employee
                {
                    FullName = "Васин Василий Васильевич",
                    HireDate = new DateTime(2012, 10, 25),
                    Phone = "+7(3452)736291",
                    Position = "Уборщик",
                    Department = "Уборщики"
                };

            var accessControl = new AccessControlModule();
            var jsonSerializer = new JsonConvertWrapper();
            var serializedEmp = jsonSerializer.Serialize(emp);
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);
            writer.Write(serializedEmp);
            writer.Flush();
            stream.Position = 0;

            var answer = accessControl.AddEmployee(stream);
            var reader = new StreamReader(answer);
            var data = reader.ReadToEnd();
            var res = JsonConvert.DeserializeObject<int>(data);
            Assert.AreEqual(res, 1);
        }
Example #2
0
 protected bool Equals(Employee other)
 {
     return string.Equals(FullName, other.FullName) && string.Equals(Department, other.Department) && string.Equals(Position, other.Position) && HireDate.Equals(other.HireDate) && string.Equals(EmployeeNumber, other.EmployeeNumber);
 }
        public void AddSeveralEmployeesTest()
        {
            var employees = new List<Employee>();
            var rnd = new Random();
            var bytes = new byte[30];
            for (int i = 0; i < 1000; i++)
            {
                var emp = new Employee();
                rnd.NextBytes(bytes);
                emp.FullName = Encoding.UTF8.GetString(bytes);
                emp.HireDate = DateTime.MinValue.AddDays(rnd.Next(1000000,3000000));
                emp.Phone = rnd.Next(111111, 9999999).ToString();
                rnd.NextBytes(bytes);
                emp.Position = Encoding.UTF8.GetString(bytes);
                rnd.NextBytes(bytes);
                emp.Department = Encoding.UTF8.GetString(bytes);
                employees.Add(emp);
            }

            Stopwatch sWatch = new Stopwatch();
            sWatch.Start();
            var accessControl = new AccessControlModule();
            var jsonSerializer = new JsonConvertWrapper();
            foreach (var employee in employees)
            {
                var serializedEmp = jsonSerializer.Serialize(employee);
                var stream = new MemoryStream();
                var writer = new StreamWriter(stream);
                writer.Write(serializedEmp);
                writer.Flush();
                stream.Position = 0;
                var answer = accessControl.AddEmployee(stream);
            }
            sWatch.Stop();
            TimeSpan tSpan = sWatch.Elapsed;
        }
        public void GetEmployeesTest()
        {
            var emp = new Employee
            {
                Id = 4,
                FullName = "Иванов Иван Иванович",
                HireDate = new DateTime(2012, 10, 25),
                Phone = "+7(3452)736291",
                Position = "Уборщик",
                Department = "Уборщики"
            };

            var accessControl = new AccessControlModule();
            var answer = accessControl.GetEmployees();
            var reader = new StreamReader(answer);
            var data = reader.ReadToEnd();
            var res = JsonConvert.DeserializeObject<List<Employee>>(data);
            Assert.AreEqual(res[0], emp);
        }