Beispiel #1
0
        public void MapperTest_FriendContactToFriendDto()
        {
            //Arrange
            //Act
            FriendContact fc = new FriendContact()
            {
                TaxId        = 1,
                Name         = "Name",
                DateCreated  = new DateTime(),
                DateModified = new DateTime(),
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "999-999-9999",
                Address      = "Address",
                Birthday     = "01/01/1999",
            };

            FriendDto fDto = fc.ToFriendDto();

            //Assert
            Assert.AreEqual(fDto.Name, fc.Name);
            Assert.AreEqual(fDto.TaxId, fc.TaxId);
            Assert.AreEqual(fDto.DateCreated, fc.DateCreated);
            Assert.AreEqual(fDto.DateModified, fc.DateModified);
            Assert.AreEqual(fDto.EmailAddress, fc.EmailAddress);
            Assert.AreEqual(fDto.PhoneNumber, fc.PhoneNumber);
            Assert.AreEqual(fDto.Address, fc.Address);
            Assert.AreEqual(fDto.Birthday, fc.Birthday);
        }
        public IHttpActionResult PutFriendContact(int id, FriendContact friendContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != friendContact.FriendId)
            {
                return(BadRequest());
            }

            db.Entry(friendContact).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FriendContactExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void RepositoryTest_Update_Friend_Success()
        {
            //Arrange
            var           dateTime = DateTime.Now;
            FriendContact wc       = ((FriendContact)FakeDataFactory.Get <FriendContact>(
                                          taxId: 10,
                                          name: "Name1",
                                          address: "address11",
                                          company: "Company1",
                                          dateModified: dateTime,
                                          emailAddress: "[email protected]",
                                          phoneNumber: "000000001",
                                          birthday: "01/01/2000"
                                          ));
            var contactsDto = new List <ContactDto>()
            {
                FakeDataFactory.GetDto <FriendDto>()
            };
            var repository = new ContactRepository(contactsDto);

            //Act
            repository.Update(wc, 1);

            //Assert
            Assert.AreEqual(contactsDto.Count, 1);
            Assert.IsInstanceOfType(contactsDto[0], typeof(FriendDto));
            Assert.AreEqual(contactsDto[0].Address, wc.Address);
            Assert.AreEqual(contactsDto[0].Name, wc.Name);
            Assert.AreEqual(contactsDto[0].PhoneNumber, wc.PhoneNumber);
            Assert.AreEqual(contactsDto[0].TaxId, wc.TaxId);
            Assert.AreEqual(((FriendDto)contactsDto[0]).Birthday, wc.Birthday);
        }
Beispiel #4
0
        public void MapperTest_ContactToContactDto_Friend()
        {
            //Arrange
            //Act
            FriendContact wc = new FriendContact()
            {
                TaxId        = 1,
                Name         = "Name",
                DateCreated  = new DateTime(),
                DateModified = new DateTime(),
                PhoneNumber  = "999-999-9999",
                Address      = "Address",
                Birthday     = "01/01/1999"
            };

            ContactDto cDto = ((Contact)wc).ToContactDto();

            //Assert
            Assert.AreEqual(cDto.Name, wc.Name);
            Assert.AreEqual(cDto.TaxId, wc.TaxId);
            Assert.AreEqual(cDto.DateCreated, wc.DateCreated);
            Assert.AreEqual(cDto.DateModified, wc.DateModified);
            Assert.AreEqual(((FriendDto)cDto).Birthday, wc.Birthday);
            Assert.AreEqual(cDto.PhoneNumber, wc.PhoneNumber);
            Assert.AreEqual(cDto.Address, wc.Address);
        }
        public void FriendContactPrintTest()
        {
            // Arrange
            FriendContact contact = new FriendContact("1");

            contact.Name        = "Name 1";
            contact.Address     = "Address 1";
            contact.PhoneNumber = "23453545434";
            contact.Employer    = "Emp";
            contact.Birthday    = DateTime.Parse("01/30/1999");

            string expectedResult =
                String.Format(Constants.Defaults.DefaultPrintFormat, Constants.Fields.TaxID,
                              contact.TaxID) +
                String.Format(Constants.Defaults.DefaultPrintFormat, nameof(contact.Name),
                              contact.Name) +
                String.Format(Constants.Defaults.DefaultPrintFormat, nameof(contact.Address),
                              (contact.Address != null) ? contact.Address : String.Empty) +
                String.Format(Constants.Defaults.DefaultPrintFormat, Constants.Fields.PhoneNumber,
                              (contact.PhoneNumber != null) ? contact.PhoneNumber : String.Empty) +
                String.Format(Constants.Defaults.DefaultPrintFormat, nameof(contact.Employer),
                              contact.Employer) +
                String.Format(Constants.Defaults.DefaultPrintFormat, Constants.Fields.ModifiedDate,
                              String.Format(Constants.Defaults.DefaultPrintFormat, nameof(contact.Birthday),
                                            ((contact.Birthday != null) ? contact.Birthday.Value.ToString(Constants.Defaults.DateFormat) : String.Empty)) +
                              contact.ModifiedDate.ToString(Constants.Defaults.DateFormat)) +
                String.Format(Constants.Defaults.DefaultPrintFormat, Constants.Fields.CreatedDate,
                              contact.CreatedDate.ToString(Constants.Defaults.DateFormat));

            // act
            string actualResult = contact.ToString();

            // asset
            StringAssert.Equals(actualResult, expectedResult);
        }
        public IHttpActionResult GetFriendContact(int id)
        {
            FriendContact friendContact = db.FriendContacts.Find(id);

            if (friendContact == null)
            {
                return(NotFound());
            }

            return(Ok(friendContact));
        }
        public IHttpActionResult PostFriendContact(FriendContact friendContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.FriendContacts.Add(friendContact);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = friendContact.FriendId }, friendContact));
        }
        public IHttpActionResult DeleteFriendContact(int id)
        {
            FriendContact friendContact = db.FriendContacts.Find(id);

            if (friendContact == null)
            {
                return(NotFound());
            }

            db.FriendContacts.Remove(friendContact);
            db.SaveChanges();

            return(Ok(friendContact));
        }
Beispiel #9
0
        private void AddContact()
        {
            bool runNextCommand;

            do
            {
                runNextCommand = false;
                printListOfAddCommands();
                string subCommand = this.consoleService.ReadLine().Trim();
                switch (subCommand)
                {
                case "1":
                {
                    CompanyContact contact = new CompanyContact(ReadTaxID(true));
                    BuildContact(contact);
                    break;
                }

                case "2":
                {
                    WorkContact contact = new WorkContact(ReadTaxID(true));
                    BuildContact(contact);
                    break;
                }

                case "3":
                {
                    FriendContact contact = new FriendContact(ReadTaxID(true));
                    BuildContact(contact);
                    break;
                }

                case "4":
                {
                    break;
                }

                default:
                {
                    InvalidSelection();
                    runNextCommand = true;
                    break;
                }
                }
            } while (runNextCommand);
        }
Beispiel #10
0
        public void BuildContact(Contact addEntry, bool isUpdate = false)
        {
            addEntry.Name        = ReadValueCannotBeEmpty(nameof(addEntry.Name), addEntry.Name, isUpdate);
            addEntry.Address     = ReadValueFromUser(nameof(addEntry.Address), addEntry.Address, isUpdate);
            addEntry.PhoneNumber = ReadValueFromUser(Constants.Fields.PhoneNumber, addEntry.PhoneNumber, isUpdate);

            if (addEntry is CompanyContact)
            {
                CompanyContact cContact = (CompanyContact)addEntry;
                cContact.Url = ReadValueFromUser(nameof(cContact.Url), cContact.Url, isUpdate);
            }
            else if (addEntry is WorkContact)
            {
                WorkContact wContact = (WorkContact)addEntry;
                wContact.Url      = ReadValueFromUser(nameof(wContact.Url), wContact.Url, isUpdate);
                wContact.Employer = ReadValueFromUser(nameof(wContact.Employer), wContact.Employer, isUpdate);
                wContact.Email    = ReadValueFromUser(nameof(wContact.Email), wContact.Email, isUpdate);
                wContact.Title    = ReadTitle();
            }
            else if (addEntry is FriendContact)
            {
                FriendContact fContact = (FriendContact)addEntry;
                fContact.Birthday = ReadDateValue(nameof(fContact.Birthday), fContact.Birthday, isUpdate);
                fContact.Email    = ReadValueFromUser(nameof(fContact.Email), fContact.Email, isUpdate);
            }
            if (isUpdate)
            {
                addEntry.ModifiedDate = DateTime.Now;
            }
            this.AddressBook.Add(addEntry);
            if (isUpdate)
            {
                consoleService.WriteLine(Constants.Messages.SuccessfullyUpdated);
            }
            else
            {
                consoleService.WriteLine(Constants.Messages.SuccessfullyAdded);
            }
            PressEnterToContinue();
        }
Beispiel #11
0
 public static FriendDto ToFriendDto(this FriendContact item)
 {
     return(Mapper.Map <FriendDto>(item));
 }
Beispiel #12
0
        private void LoadComponents()
        {
            Contact.Contacts.Clear();

            if (File.Exists(@"..\..\contacts.txt"))
            {
                var reader = new StreamReader(@"..\..\contacts.txt");

                try
                {
                    using (reader)
                    {
                        var serializedPersons = reader.ReadToEnd();
                        var persons           = serializedPersons.Split(new string[] { Environment.NewLine },
                                                                        StringSplitOptions.RemoveEmptyEntries);
                        foreach (var person in persons)
                        {
                            if (person.StartsWith(ContactGroup.Family.ToString()))
                            {
                                Contact contact = new FamillyContact();
                                Contact.AddContact(contact.Deserialize(person));
                            }
                            else if (person.StartsWith(ContactGroup.Business.ToString()))
                            {
                                Contact contact = new BusinessContact();
                                Contact.AddContact(contact.Deserialize(person));
                            }
                            else if (person.StartsWith(ContactGroup.Friends.ToString()))
                            {
                                Contact contact = new FriendContact();
                                Contact.AddContact(contact.Deserialize(person));
                            }
                            else if (person.StartsWith(ContactGroup.Other.ToString()))
                            {
                                Contact contact = new OtherContact();
                                Contact.AddContact(contact.Deserialize(person));
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
                catch (FileLoadException ex) { MessageBox.Show(ex.Message); }
                catch (IOException ex) { MessageBox.Show(ex.Message); }
            }
            else
            {
                try { File.Create(@"..\..\contacts.txt"); }
                catch (PathTooLongException ex) { MessageBox.Show(ex.Message); }
                catch (DirectoryNotFoundException ex) { MessageBox.Show(ex.Message); }
                catch (UnauthorizedAccessException ex) { MessageBox.Show(ex.Message); }
                catch (IOException ex) { MessageBox.Show(ex.Message); }
            }

            GroupedContacts = new ListCollectionView(Contact.Contacts);
            GroupedContacts.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            GroupedContacts.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            preview.ItemsSource = GroupedContacts;
        }
Beispiel #13
0
        private void OnAddBtnClick(object sender, RoutedEventArgs e)
        {
            DateTime date;
            bool     isDate = DateTime.TryParse(this.PersonBirthday.Text, out date);

            try
            {
                if (this.PersonName.Text.Trim() == "")
                {
                    throw new AddressBookException("Name is mandatory!", new InvalidNameException());
                }
                if (this.Mobile.Text.Trim() == "")
                {
                    throw new AddressBookException("Mobile phone is mandatory!", new InvalidPhoneException());
                }
                if (this.PersonBirthday.Text.Trim() != "")
                {
                    if (!isDate)
                    {
                        throw new InvalidDateException("Enter correct date!");
                    }
                }
                if (this.Mobile.Text.Trim() != null)
                {
                    string mobile = this.Mobile.Text.Trim();
                    for (int i = 0; i < mobile.Length; i++)
                    {
                        if (!char.IsDigit(mobile[i]))
                        {
                            throw new InvalidPhoneException("Enter valid mobile number!");
                        }
                    }
                }

                if (GroupType.SelectionBoxItem.ToString() == "Family")
                {
                    Contact newContact = new FamillyContact(this.PersonName.Text.Trim(), this.Mobile.Text.Trim(),
                                                            this.PersonEmail.Text.Trim(), date == DateTime.MinValue ? (DateTime?)null : date);
                    (GroupedContacts as ListCollectionView).AddNewItem(newContact);
                }
                else if (GroupType.SelectionBoxItem.ToString() == "Friends")
                {
                    Contact newContact = new FriendContact(this.PersonName.Text.Trim(), this.Mobile.Text.Trim(),
                                                           this.PersonEmail.Text.Trim(), date == DateTime.MinValue ? (DateTime?)null : date);
                    (GroupedContacts as ListCollectionView).AddNewItem(newContact);
                }
                else if (GroupType.SelectionBoxItem.ToString() == "Business")
                {
                    Contact newContact = new BusinessContact(this.PersonName.Text.Trim(), this.Mobile.Text.Trim(),
                                                             this.PersonEmail.Text.Trim(), date == DateTime.MinValue ? (DateTime?)null : date);
                    (GroupedContacts as ListCollectionView).AddNewItem(newContact);
                }
                else
                {
                    Contact newContact = new OtherContact(this.PersonName.Text.Trim(), this.Mobile.Text.Trim(),
                                                          this.PersonEmail.Text.Trim(), date == DateTime.MinValue ? (DateTime?)null : date);
                    (GroupedContacts as ListCollectionView).AddNewItem(newContact);
                }

                (GroupedContacts as ListCollectionView).CommitNew();

                this.PersonName.Text     = "";
                this.PersonEmail.Text    = "";
                this.PersonBirthday.Text = "";
                this.Mobile.Text         = "";
            }
            catch (InvalidDateException ex) { MessageBox.Show(ex.Message); }
            catch (AddressBookException ex) { MessageBox.Show(ex.Message); }
        }