public void GetPropertyValueTest()
        {
            // Arrange.
            var employee = new TestEmployee
                               {
                                   FirstName = "aaa",
                                   LastName = "AAA",
                                   BusinessUnit = 11,
                                   BusinessUnitMember =
                                       new TestBusinessUnit
                                           {
                                               Name = "Test BU",
                                               ParentBusinessUnit = 12,
                                               ParentBusinessUnitMember = new TestBusinessUnit { Name = "Parent BU" }
                                           }
                               };

            var itemsRetrieverFactory = Mock.Create<IProcessFieldItemsRetrieverFactory>(Behavior.Loose);

            var context = new EditableRootDataContext(employee, itemsRetrieverFactory);

            // Act / Assert.
            Assert.IsNull(context.GetPropertyValue(null));
            Assert.IsNull(context.GetPropertyValue("TestProp"));
            Assert.AreEqual("aaa", context.GetPropertyValue("FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("LastName"));
            Assert.AreEqual("Test BU", context.GetPropertyValue("BusinessUnit.Name"));
            Assert.AreEqual("Parent BU", context.GetPropertyValue("BusinessUnit.ParentBusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Roles.Name"));
        }
Esempio n. 2
0
        internal static List <Domain.Tests.TestEmployee> GetEmployees()
        {
            List <TestEmployee> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Employees_Select"
                                    , inputParamMapper : null
                                    , map : delegate(IDataReader reader, short set)
            {
                TestEmployee p    = new TestEmployee();
                int startingIndex = 0;    //startingOrdinal

                p.Id       = reader.GetSafeInt32(startingIndex++);
                p.LastName = reader.GetSafeString(startingIndex++);

                p.FirstName = reader.GetSafeString(startingIndex++);
                p.Title     = reader.GetSafeString(startingIndex++);
                p.Dob       = reader.GetSafeDateTime(startingIndex++);
                p.Status    = reader.GetSafeInt32(startingIndex++);

                if (list == null)
                {
                    list = new List <TestEmployee>();
                }

                list.Add(p);
            }
                                    );


            return(list);
        }
Esempio n. 3
0
        public TestEmployee Add(TestEmployee item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to save record into database
            item.Id = _nextId++;
            this._data.Add((TestBoss)item);
            return(item);
        }
        public TestEmployee Add(TestEmployee item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to save record into database
            item.Id = _nextId++;
            this._data.Add((TestBoss) item);
            return item;
        }
Esempio n. 5
0
        public void SerializeItem()
        {
            //Arrange
            var employee = new TestEmployee {
                Name = "John Doe", Salary = 56000, Married = true
            };

            //Act
            var json = JsonHelper <TestEmployee> .Serialize(employee);

            //Assert
            Assert.IsNotNull(json);
        }
Esempio n. 6
0
 public ActionResult Delete(int id)
 {
     using (PracticeDBEntities db = new PracticeDBEntities())
     {
         var          employee = db.Employees.Where(x => x.Eno == id).FirstOrDefault();
         TestEmployee model    = new TestEmployee();
         model.Eno    = employee.Eno;
         model.Ename  = employee.Ename;
         model.Job    = employee.Job;
         model.Salary = employee.Salary;
         model.Dname  = employee.Dname;
         return(View(model));
     }
 }
Esempio n. 7
0
        public ActionResult Edit(int id, TestEmployee model)
        {
            using (PracticeDBEntities db = new PracticeDBEntities())
            {
                Employee employee = new Employee();
                employee.Eno    = model.Eno;
                employee.Ename  = model.Ename;
                employee.Job    = model.Job;
                employee.Salary = model.Salary;
                employee.Dname  = model.Dname;

                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 8
0
        public ActionResult Create(TestEmployee model)
        {
            using (PracticeDBEntities db = new PracticeDBEntities())
            {
                Employee employee = new Employee();
                employee.Eno    = model.Eno;
                employee.Ename  = model.Ename;
                employee.Job    = model.Job;
                employee.Salary = model.Salary;
                employee.Dname  = model.Dname;

                db.Employees.Add(employee);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        public bool Update(TestEmployee item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to update record into database
            int index = this._data.FindIndex(p => p.Id == item.Id);
            if (index == -1)
            {
                return false;
            }
            this._data.RemoveAt(index);
            this._data.Add(item);
            return true;
        }
Esempio n. 10
0
        public bool Update(TestEmployee item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to update record into database
            int index = this._data.FindIndex(p => p.Id == item.Id);

            if (index == -1)
            {
                return(false);
            }
            this._data.RemoveAt(index);
            this._data.Add(item);
            return(true);
        }
Esempio n. 11
0
        public HttpResponseMessage TestInjectedService(int employeeId)
        {
            TestEmployee employee = null;

            try
            {
                employee = _employeeService.Get(employeeId);
            }
            catch (ObjectNotFoundException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
            }

            ItemResponse <TestEmployee> response = new ItemResponse <TestEmployee>();

            response.Item = employee;

            return(Request.CreateResponse(response));
        }
Esempio n. 12
0
        public void CalculateSalary(Employee employee, Company company, double salary)
        {
            "Given a company working Mo-Fr between 08:00-12:00 and 13:00-17:00"
            .x(() => company = TestCompany.Working()
                               .On(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday)
                               .Daily.From(08, 00).To(12, 00)
                               .Daily.From(13, 00).To(17, 00).Company);

            "And an employee payed 30$ per hour"
            .x(() => employee = TestEmployee.Create()
                                .WithContract(TestEmployeeContract.For(company).Earning(30).Per(TimeSpan.FromHours(1))));

            "When the employee has worked November 2021"
            .x(() => salary = SalaryCalculator
                              .CalculateSalary(employee, DateTime.Parse("2021-11-01"), DateTime.Parse("2021-12-01")));

            "Then his salary is "
            .x(() => salary.Should().Be(5280));
        }
        public void GetPropertyValueTest()
        {
            // Arrange.
            var typeResolver = Mock.Create<ITypeResolver>(Behavior.Loose);
            var role1 = new TestRole { Name = "Test Role 1" };
            var role2 = new TestRole { Name = "Test Role 2", ParentRole = new TestRole { Name = "Parent Role" } };
            var businessUnit = new TestBusinessUnit { Name = "Test BU", ParentBusinessUnit = new TestBusinessUnit { Name = "Parent BU" } };
            var employee = new TestEmployee { FirstName = "aaa", LastName = "AAA", BusinessUnit = businessUnit, Roles = new[] { role1, role2 } };
            var request = new TestRequest1 { Employee = employee };

            var context = new WebMethodResultDataContext(request, typeResolver);

            // Act / Assert.
            Assert.IsNull(context.GetPropertyValue(null));
            Assert.AreEqual("aaa", context.GetPropertyValue("Employee|FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employee|LastName"));
            Assert.AreEqual("Test BU", context.GetPropertyValue("Employee|BusinessUnit|Name"));
            Assert.AreEqual("Parent BU", context.GetPropertyValue("Employee|BusinessUnit|ParentBusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employee|Roles|Name"));
            Assert.IsNull(context.GetPropertyValue("Employee|Roles|ParentRole|Name"));
        }
Esempio n. 14
0
        public static List <TestEmployee> GetEmployees(List <int> ids)
        {
            List <TestEmployee> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Employees_SelectByIds"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                SqlParameter p = new SqlParameter("@EmployeeIds", System.Data.SqlDbType.Structured);

                if (ids != null && ids.Any())
                {
                    p.Value = new Sabio.Data.IntIdTable(ids);
                }

                paramCollection.Add(p);
            }, map : delegate(IDataReader reader, short set)
            {
                TestEmployee p    = new TestEmployee();
                int startingIndex = 0;    //startingOrdinal

                p.Id       = reader.GetSafeInt32(startingIndex++);
                p.LastName = reader.GetSafeString(startingIndex++);

                p.FirstName = reader.GetSafeString(startingIndex++);
                p.Title     = reader.GetSafeString(startingIndex++);
                p.Dob       = reader.GetSafeDateTime(startingIndex++);
                p.Status    = reader.GetSafeInt32(startingIndex++);

                if (list == null)
                {
                    list = new List <TestEmployee>();
                }

                list.Add(p);
            }
                                    );


            return(list);
        }
Esempio n. 15
0
        public static void Case1()
        {
            TestEmployee ee = new TestEmployee
            {
                Age            = 999999,
                Name           = "ZZZZZZZZZZZZZZZZZ",
                CanWorkNightly = true
            };

            IList <TestEmployee> items = new List <TestEmployee>();

            for (int ii = 0; ii < 6; ++ii)
            {
                items.Add(ee);
            }

            HtmlTableMaker maker = new HtmlTableMaker();

            string html = maker.Make <TestEmployee>();

            Console.WriteLine($"{html}");
        }
        public void EnumerateItemsTest()
        {
            // Arrange.
            var editItem = new TestEdit();

            var employee1 = new TestEmployee
                                {
                                    FirstName = "aaa",
                                    LastName = "AAA",
                                    BusinessUnit = 11,
                                    BusinessUnitMember = new TestBusinessUnit { Name = "BU 1" }
                                };
            var employee2 = new TestEmployee
                                {
                                    FirstName = "bbb",
                                    LastName = "BBB",
                                    BusinessUnit = 12,
                                    BusinessUnitMember = new TestBusinessUnit { Name = "BU 2" }
                                };

            var employeesRetriever = new Mock<IProcessFieldItemsRetriever>();
            employeesRetriever.Setup(x => x.ItemType).Returns(typeof(TestEmployee));
            employeesRetriever.Setup(x => x.GetItems(editItem)).Returns(new[] { employee1, employee2 });

            var role1 = new TestRole { Name = "Role 1" };
            var role2 = new TestRole { Name = "Role 2" };
            var role3 = new TestRole { Name = "Role 3" };

            var rolesRetriever = new Mock<IProcessFieldItemsRetriever>();
            rolesRetriever.Setup(x => x.ItemType).Returns(typeof(TestRole));
            rolesRetriever.Setup(x => x.GetItems(employee1)).Returns(new[] { role1 });
            rolesRetriever.Setup(x => x.GetItems(employee2)).Returns(new[] { role2, role3 });

            var retrieverFactory = new Mock<IProcessFieldItemsRetrieverFactory>();
            retrieverFactory.Setup(x => x.CreateItemsRetriever(typeof(TestEdit), "Employees")).Returns(employeesRetriever.Object);
            retrieverFactory.Setup(x => x.CreateItemsRetriever(typeof(TestEmployee), "Roles")).Returns(rolesRetriever.Object);

            var context = new EditableRootDataContext(editItem, retrieverFactory.Object);

            // Act / Assert.
            var employees = context.EnumerateItems("Employees");
            var employeeEnumerator = employees.GetEnumerator();

            Assert.IsNull(context.GetPropertyValue("Employees.FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees.LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsTrue(employeeEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            var roles = context.EnumerateItems("Employees.Roles");
            var rolesEnumerator = roles.GetEnumerator();
            
            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.AreEqual("Role 1", context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsFalse(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsTrue(employeeEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            roles = context.EnumerateItems("Employees.Roles");
            rolesEnumerator = roles.GetEnumerator();

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.AreEqual("Role 2", context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.AreEqual("Role 3", context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsFalse(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsFalse(employeeEnumerator.MoveNext());
            Assert.IsNull(context.GetPropertyValue("Employees.FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees.LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));
        }
 public bool Update(TestEmployee item)
 {
     throw new NotImplementedException();
 }
        public void EnumerateItemsTest()
        {
            // Arrange.
            var typeResolver = Mock.Create<ITypeResolver>(Behavior.Loose);
            var role1 = new TestRole { Name = "Role 1" };
            var role2 = new TestRole { Name = "Role 2" };
            var role3 = new TestRole { Name = "Role 3" };
            var businessUnit1 = new TestBusinessUnit { Name = "BU 1" };
            var businessUnit2 = new TestBusinessUnit { Name = "BU 2" };

            var employee1 = new TestEmployee { FirstName = "aaa", LastName = "AAA", BusinessUnit = businessUnit1, Roles = new[] { role1 } };
            var employee2 = new TestEmployee { FirstName = "bbb", LastName = "BBB", BusinessUnit = businessUnit2, Roles = new[] { role2, role3 } };
            var request = new TestRequest2 { Employees = new[] { employee1, employee2 } };

            var context = new WebMethodResultDataContext(request, typeResolver);

            // Act / Assert.
            var employees = context.EnumerateItems("Employees");
            var employeeEnumerator = employees.GetEnumerator();

            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Name"));

            Assert.IsTrue(employeeEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            var roles = context.EnumerateItems("Employees|Item[]|Roles");
            var rolesEnumerator = roles.GetEnumerator();

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.AreEqual("Role 1", context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            Assert.IsFalse(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            Assert.IsTrue(employeeEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            roles = context.EnumerateItems("Employees|Item[]|Roles");
            rolesEnumerator = roles.GetEnumerator();

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.AreEqual("Role 2", context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.AreEqual("Role 3", context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            Assert.IsFalse(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

            Assert.IsFalse(employeeEnumerator.MoveNext());
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));
        }
Esempio n. 19
0
 public bool Update(TestEmployee item)
 {
     throw new NotImplementedException();
 }