public void PersonController_Add_Update() {
            var Name_Original = "Added Person";
            var Name_Updated = "Updated Person";

            var PersonController = new PersonController();

            var ItemsAtStart = PersonController.Current().Count();

            var Person = PersonController.Add(new Person() {
                Name = Name_Original,
                DateOfBirth = DateTime.Now
            });

            Person.Name = Name_Updated;
            PersonController.Update(Person);

            Person = PersonController.Get(Person.InstanceId);

            var ItemsAtEnd = PersonController.Current().Count();

            //Make sure our count increased by 1.
            Assert.AreEqual(ItemsAtStart + 1, ItemsAtEnd);
            //Make sure that we have the updated name.
            Assert.AreEqual(Name_Updated, Person.Name);
        }
示例#2
0
        public void ControllerAddSuccess()
        {
            var context = Substitute.For <AgeRangerContext>();

            context.SaveChanges().Returns(1);

            var target = new PersonController(context, new
                                              HttpStatusMapper(HttpStatusMapper.HttpStatusList), appConfigMock);
            var statusResult = target.Add(ShannonPerson);

            var result = (StatusCodeResult)statusResult;

            Assert.IsTrue(result.StatusCode == HttpCreated);
        }
        public void AddTest()
        {
            PersonController controller = new PersonController(_iPersonLogicRepository);

            SetupControllerForTests(controller);
            Person person = new Person
            {
                Active    = true,
                BirthDate = DateTime.Now.AddYears(-19),
                FirstName = "TestFirstName",
                LastName  = "TestLastName"
            };

            var result = controller.Add(person);

            Assert.Equals(HttpStatusCode.Created, result.StatusCode);
        }
示例#4
0
        public void Add_ReturnsCreatedPerson()
        {
            // Arrange
            var mockPersonService = new Mock <IPersonService>();

            mockPersonService
            .Setup(x => x.Add(expectedPerson))
            .Returns(expectedPerson.PersonID);
            var personController = new PersonController(mockPersonService.Object);

            // Act
            var actionResult = personController.Add(expectedPerson) as OkObjectResult;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.AreEqual(200, actionResult.StatusCode);
            Assert.AreEqual(expectedPerson, actionResult.Value);
        }
        public void TestAddModelNotValid()
        {
            var context = new FakePersonSharingContext();

            context.Persons = new[] {
                new Person {
                    personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "56457866", adresId = 1
                },
                new Person {
                    personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = "56457867", adresId = 2
                },
                new Person {
                    personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = "56457868", adresId = 3
                }
            }.AsQueryable();
            context.Adreses = new[]
            {
                new Adres {
                    adresId = 1, miasto = "Gdańsk", ulica = "Góralska", kodPocztowy = "80-292", nrBloku = "54f", nrMieszkania = "6"
                },
                new Adres {
                    adresId = 2, miasto = "Gdańsk", ulica = "Góralska", kodPocztowy = "80-292", nrBloku = "54f", nrMieszkania = "6"
                },
                new Adres {
                    adresId = 3, miasto = "Gdańsk", ulica = "Góralska", kodPocztowy = "80-292", nrBloku = "54f", nrMieszkania = "6"
                }
            }.AsQueryable();
            PersonAdres person = new PersonAdres();

            person.kodPocztowy  = "80-292";
            person.miasto       = "Gdańsk";
            person.nazwisko     = "Kowalska";
            person.pesel        = "6743678908";
            person.nrBloku      = "56";
            person.ulica        = "Focha";
            person.nrMieszkania = "6";

            var controller = new PersonController(context);

            controller.ViewData.ModelState.AddModelError("imie", "Podaj imię");
            var result = (ViewResult)controller.Add(person);

            Assert.AreEqual("Add", result.ViewName);
        }
        public void TestAddConf()
        {
            var context = new FakePersonSharingContext();

            context.Persons = new[] {
                new Person {
                    personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "56457866", adresId = 1
                },
                new Person {
                    personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = "56457867", adresId = 2
                },
                new Person {
                    personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = "56457868", adresId = 3
                }
            }.AsQueryable();
            context.Adreses = new[]
            {
                new Adres {
                    adresId = 1, miasto = "Gdańsk", ulica = "Góralska", kodPocztowy = "80-292", nrBloku = "54f", nrMieszkania = "6"
                },
                new Adres {
                    adresId = 2, miasto = "Gdańsk", ulica = "Góralska", kodPocztowy = "80-292", nrBloku = "54f", nrMieszkania = "6"
                },
                new Adres {
                    adresId = 3, miasto = "Gdańsk", ulica = "Góralska", kodPocztowy = "80-292", nrBloku = "54f", nrMieszkania = "6"
                }
            }.AsQueryable();
            PersonAdres person = new PersonAdres();

            person.imie         = "Kasia";
            person.kodPocztowy  = "80-292";
            person.miasto       = "Gdańsk";
            person.nazwisko     = "Kowalska";
            person.nrBloku      = "56";
            person.ulica        = "Focha";
            person.nrMieszkania = "6";

            var controller = new PersonController(context);
            var result     = controller.Add(person) as RedirectToRouteResult;

            Assert.AreEqual("All", result.RouteValues["Action"]);
            Assert.AreEqual("Person", result.RouteValues["Controller"]);
        }
        public void PersonController_Add() {
            //This should add a person to the database and make sure that they got added.
            var Name_Original = "Added Person";

            var PersonController = new PersonController();

            var ItemsAtStart = PersonController.Current().Count();

            var Person = PersonController.Add(new Person() {
                Name = Name_Original,
                DateOfBirth = DateTime.Now,
            });

            var ItemsAtEnd = PersonController.Current().Count();

            Person = PersonController.Get(Person.InstanceId);

            //The items in our list should have increased by 1.
            Assert.AreEqual(ItemsAtStart + 1, ItemsAtEnd);
            Assert.AreEqual(Name_Original, Person.Name);
        }
示例#8
0
        public async Task AddShouldCallAddPersonOnce()
        {
            //Arrange
            PersonViewModel pvm = new PersonViewModel
            {
                FirstName = "Bob",
                LastName  = "Smith",
                Phone     = "0636363636",
                Email     = "email.email.com"
            };
            var mock       = new Mock <IPersonWebService>();
            var controller = new PersonController(mock.Object);

            mock.Setup(x => x.Add(It.IsAny <PersonViewModel>())).ReturnsAsync(It.IsAny <PersonViewModel>());

            //Act
            await controller.Add(pvm);

            //Assert
            mock.Verify(x => x.Add(It.IsAny <PersonViewModel>()), Times.Once);
        }
        public void PersonController_Add_Update_Archive() {
            var Name_Original = "Added Person";
            var Name_Updated = "Updated Person";

            var PersonController = new PersonController();

            var ItemsAtStart = PersonController.Current().Count();

            var Person = PersonController.Add(new Person() {
                Name = Name_Original,
                DateOfBirth = DateTime.Now
            });

            Person.Name = Name_Updated;
            PersonController.Update(Person);
            PersonController.Archive(Person);
            Person = PersonController.Get(Person.InstanceId);

            var ItemsAtEnd = PersonController.Current().Count();

            //Make sure our count hasn't changed since the item was archived.
            Assert.AreEqual(ItemsAtStart, ItemsAtEnd);
        }
        public void StaticFunctionAdd()
        {
            var result1 = _pc.Add(1, 2);

            Assert.Equal(3, result1.Object);
        }
示例#11
0
        public int? Save(bool isSystem, int? recordTypeValueId = null, int? recordStatusValueId = 0, int? recordStatusReasonValueId = null, int? connectionStatusValueId = null, bool isDeceased = false, 
                int? titleValueId = null, string firstName = null, string nickName = null, string middleName = null, string lastName = null, int? suffixValueId = null, int? photoId = null, int? birthDay = null,
                int? birthMonth = null, int? birthYear = null, int gender = 0, int? maritalStatusValueId = null, DateTime? anniversaryDate = null, DateTime? graduationDate = null, int? givingGroupId = null, 
                string email= null, bool isEmailActive = false, string emailNote = null, string systemNote = null, int? emailPreference = 2, string inactiveReasonNote = null, string foreignId = null, 
                int? reviewReasonValueId = null, string reviewReasonNote = null, int? personId = null)
        {
            Person p;
            PersonController controller = new PersonController( Service );
            if ( personId > 0 )
            {
                p = controller.GetById( (int)personId );

                if ( p == null )
                {
                    return null;
                }
            }
            else
            {
                p = new Person();
            }

            p.IsSystem = isSystem;
            p.RecordTypeValueId = recordTypeValueId;
            p.RecordStatusValueId = recordStatusValueId;
            p.RecordStatusReasonValueId = recordStatusReasonValueId;
            p.ConnectionStatusValueId = connectionStatusValueId;
            p.IsDeceased = isDeceased;
            p.TitleValueId = titleValueId;
            p.FirstName = firstName;
            p.NickName = nickName;
            p.MiddleName = middleName;
            p.LastName = lastName;
            p.SuffixValueId = suffixValueId;
            p.PhotoId = photoId;
            p.BirthDay = birthDay;
            p.BirthMonth = birthMonth;
            p.BirthYear = birthYear;
            p.Gender = (Gender)gender;
            p.MaritalStatusValueId = maritalStatusValueId;
            p.AnniversaryDate = anniversaryDate;
            p.GraduationDate = graduationDate;
            p.GivingGroupId = givingGroupId;
            p.Email = email;
            p.IsEmailActive = isEmailActive;
            p.EmailNote = emailNote;
            p.SystemNote = systemNote;
            p.EmailPreference = (EmailPreference)emailPreference;
            p.InactiveReasonNote = inactiveReasonNote;
            p.ForeignId = foreignId;
            p.ReviewReasonValueId = reviewReasonValueId;
            p.ReviewReasonNote = reviewReasonNote;

            if ( p.Id == 0 )
            {
                p.CreatedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId;
                controller.Add( p );
            }
            else
            {
                p.ModifiedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId;
                controller.Update( p );
            }

            p = controller.GetByGuid( p.Guid, true );

            return p.Id;
        }