Exemplo n.º 1
0
        public void AddPerson_should_returnBadRequest_because_noPersonName()
        {
            var invalidPerson = new Person();
            var actionResult  = controller.AddPerson(invalidPerson);

            Assert.Equal(typeof(BadRequestObjectResult), actionResult.GetType());
        }
        public async Task WhenPersonAddedPersonIsReturned()
        {
            Person personToAdd = new Person
            {
                FirstName = "John",
                LastName  = "Doe"
            };
            long personCountBefore = await _personRepository.GetPersonCount();

            Person addedPerson      = GetValueFromOkObjectResult <Person>(await _personController.AddPerson(personToAdd) as OkObjectResult);
            long   personCountAfter = await _personRepository.GetPersonCount();

            Assert.IsTrue(--personCountAfter == personCountBefore);
            Assert.AreEqual(personToAdd.FirstName, addedPerson.FirstName);
            Assert.AreEqual(personToAdd.LastName, addedPerson.LastName);

            await _personController.DeletePerson(personToAdd.Id);
        }
        public void TestAddInvalidPerson()
        {
            PersonContext testContext = InitalizeTestDBContext();

            PersonController testController = new PersonController(testContext);

            var result = testController.AddPerson(new Person {
                Birthday = new DateTime(2000, 01, 01)
            });

            Assert.IsInstanceOfType(result, typeof(BadRequestResult));

            testContext.Dispose();
        }
        public void TestAddValidPerson()
        {
            PersonContext testContext = InitalizeTestDBContext();

            PersonController testController = new PersonController(testContext);

            var result = testController.AddPerson(new Person {
                Birthday = new DateTime(2000, 01, 01), FirstName = "Test", LastName = "User", Interests = "Fishing, skiing"
            });

            Assert.IsInstanceOfType(result, typeof(OkResult));

            testContext.Dispose();
        }
        public void TestSearchWithSpaceSeparatedFirstLastNames()
        {
            PersonContext testContext = InitalizeTestDBContext();

            PersonController testController = new PersonController(testContext);

            testController.AddPerson(new Person {
                Birthday = new DateTime(2000, 01, 01), FirstName = "Space", LastName = "Separated", Interests = "Fishing, skiing"
            });

            List <Person> result = testController.GetPersons("Space Separated");

            Assert.IsTrue(result.Count() == 1);

            testContext.Dispose();
        }
        public void TestSearchEmptyString()
        {
            PersonContext testContext = InitalizeTestDBContext();

            PersonController testController = new PersonController(testContext);

            testController.AddPerson(new Person {
                Birthday = new DateTime(2000, 01, 01), FirstName = "Test", LastName = "User", Interests = "Fishing, skiing"
            });

            List <Person> result = testController.GetPersons("");

            Assert.IsTrue(result.Count() == 0);

            testContext.Dispose();
        }
        public void TestAddGetManyUsers()
        {
            PersonContext testContext = InitalizeTestDBContext();

            PersonController testController = new PersonController(testContext);

            for (int i = 0; i < 100; i++)
            {
                testController.AddPerson(new Person {
                    Birthday = new DateTime(2000, 01, 01), FirstName = "Test" + i, LastName = "User", Interests = "Fishing, skiing"
                });
            }

            Assert.IsTrue(testController.GetPersons("Test").Count == 100);
            testContext.Dispose();
        }
        public void TestSearchCaseInsensitive()
        {
            PersonContext testContext = InitalizeTestDBContext();

            PersonController testController = new PersonController(testContext);

            testController.AddPerson(new Person {
                Birthday = new DateTime(2000, 01, 01), FirstName = "CASE", LastName = "INSENSTIVE", Interests = "Fishing, skiing"
            });

            List <Person> result = testController.GetPersons("CASE");

            Assert.IsTrue(result.Count() == 1);

            testContext.Dispose();
        }
Exemplo n.º 9
0
        public void TestMethod1()
        {
            IPerson          personSvc = container.Resolve <IPerson>();
            PersonController pc        = new PersonController(personSvc);
            var personmodel            = new Person
            {
                Id         = 0,
                Age        = 22,
                Address    = "aaa",
                Mobile     = "15313150410",
                Name       = "zoupch",
                Sex        = true,
                CreateTime = DateTime.Now
            };
            var result = pc.AddPerson(personmodel);

            Assert.IsTrue(result > 0);
        }
Exemplo n.º 10
0
        public ViewModel()
        {
            #region --  Use Generics class and methods --
            var book = new Book {
                Id = "1110", Name = "C# Advanced"
            };

            var numbrers = new GenericsList <int>();
            numbrers.Add(10);

            var books = new GenericsList <Book>();
            books.Add(new Book()
            {
                Id = "1111", Name = "Titre n°2"
            });

            // --  Generic Dictionary --
            var dictionary = new GenericsDictionary <string, Book>();
            dictionary.Add("1102", new Book()
            {
                Id = "1111", Name = "Titre n°2"
            });


            // -- Use Generic value type  --
            var num = new Repositories.Objects_Generics.Nullable <int>();
            Console.WriteLine("As est-elle une valeure ? " + num.HasValue);
            Console.WriteLine("New value = : " + num.HasValue);

            #endregion

            // --  Get All  --
            pController.GetPersons();

            // --    --
            Person person = new Person()
            {
                Id      = 4,
                Name    = "Chateau",
                Adresse = "Versailles Chantiers"
            };
            string insert = pController.AddPerson(person);
        }