Ejemplo n.º 1
0
        public void ConvertFromJson_NullParameters_ReturnsZeroResults()
        {
            var convert = new PersonConverter();
            var people  = convert.ConvertFromJson(null, null);

            Assert.AreEqual(0, people.Count());
        }
Ejemplo n.º 2
0
        public void ConvertFromJson_EmptyString_ReturnsZeroResults()
        {
            var convert = new PersonConverter();
            var people  = convert.ConvertFromJson("", "");

            Assert.AreEqual(0, people.Count());
        }
Ejemplo n.º 3
0
        public void ConvertFromJson_HourlyAndSalariedEmployees_GetMerged()
        {
            var convert = new PersonConverter();
            var people  = convert.ConvertFromJson("[ { Name: 'Sam', Salary: 15 } ]", "[ { Name: 'Bob', RatePerHour: 5.50 } ]").ToList();

            Assert.AreEqual(2, people.Count());
            Assert.AreEqual(1, people.Count(i => i is SalariedEmployee));
            Assert.AreEqual(1, people.Count(i => i is HourlyEmployee));
        }
Ejemplo n.º 4
0
        public void ConvertFromJson_HourlyEmployee_ReturnsStronglyTypedHourlyEmployee()
        {
            var convert = new PersonConverter();
            var people  = convert.ConvertFromJson(null, "[ { Name: 'Bob', RatePerHour: 5.50 } ]").ToList();

            Assert.AreEqual(1, people.Count());
            var bob = people[0] as HourlyEmployee;

            Assert.IsNotNull(bob, "Expected a SalariedEmployee, but got a Person");
            Assert.AreEqual("Bob", bob.Name);
            Assert.AreEqual(5.5M, bob.RatePerHour);
        }
Ejemplo n.º 5
0
        public void ConvertFromJson_SalariedEmployee_ReturnsStronglyTypedEmployee()
        {
            var convert = new PersonConverter();
            var people  = convert.ConvertFromJson("[ { Name: 'Bob', Salary: 10 } ]", null).ToList();

            Assert.AreEqual(1, people.Count());
            var bob = people[0] as SalariedEmployee;

            Assert.IsNotNull(bob, "Expected a SalariedEmployee, but got some other type (Person?)");
            Assert.AreEqual("Bob", bob.Name);
            Assert.AreEqual(10, bob.Salary);
        }