コード例 #1
0
        public void ShouldBeAbleToSaveContactToAddressBook()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var firstName = "Amanda" + random.Next();
            var surname = "Jones" + random.Next();
            var telephoneNumber = "01724 567892" + random.Next();

            var customer = new Contact(firstName, surname, telephoneNumber);

            var previousContact = addressBook.Contacts.Last();

            var lastContact = addressBook.Save(customer, username);

            Assert.That(lastContact.FirstName, Is.EqualTo(firstName));
            Assert.That(lastContact.Surname, Is.EqualTo(surname));
            Assert.That(lastContact.TelephoneNumber, Is.EqualTo(telephoneNumber));
            Assert.That(lastContact.Id, Is.GreaterThan(previousContact.Id));
        }
コード例 #2
0
        public void ShouldBeAbleToReadASpecificContactFromAddressBook()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var firstName = "Amanda" + random.Next();
            var surname = "Jones" + random.Next();
            var telephoneNumber = "01724 567892" + random.Next();

            var customer = new Contact(firstName, surname, telephoneNumber);

            var lastContact = addressBook.Save(customer, username);

            var expectedResult = addressBook.Read(lastContact.Id);

            Assert.That(expectedResult.FirstName, Is.EqualTo(firstName));
            Assert.That(expectedResult.Surname, Is.EqualTo(surname));
            Assert.That(expectedResult.TelephoneNumber, Is.EqualTo(telephoneNumber));
            Assert.That(expectedResult.Id, Is.EqualTo(lastContact.Id));
        }
コード例 #3
0
        public ActionResult SaveNewContact(string firstName, string surname, string telephoneNumber)
        {
            var username = Request.Cookies["UserId"].Value;

            var addressBook = new RealAddressBook(username);

            var newContact = new Contact(firstName, surname, telephoneNumber);

            var contact = addressBook.Save(newContact, username);

            var createdContactModel = new SavedContactModel(contact, "Contact successfully created!");

            return View("SavedContact", createdContactModel);
        }
コード例 #4
0
        public void ShouldDeleteContactFromAddressBook()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var firstName = "Amanda" + random.Next();
            var surname = "Jones" + random.Next();
            var telephoneNumber = "01724 567892" + random.Next();

            var customer = new Contact(firstName, surname, telephoneNumber);

            var contact = addressBook.Save(customer, username);

            var id = contact.Id.ToString();

            addressBook.Delete(id);

            var expectedResult = addressBook.Read(contact.Id);

            Assert.That(expectedResult, Is.EqualTo(null));
        }
コード例 #5
0
        public void ShouldUpdateTelephoneNumberForContactInAddressBookWithIdEqualTo1()
        {
            const string username = "******";
            const string firstName = "Joe";
            const string surname = "Bloggs";
            const string telephoneNumber = "Joe";

            var addressBook = new RealAddressBook(username);
            var randomNumber = Guid.NewGuid();

            var contact = new Contact(firstName, surname, telephoneNumber);

            var savedContact = addressBook.Save(contact, username);

            var iD = savedContact.Id;

            var readContact = addressBook.Read(iD);
            readContact.TelephoneNumber = "01733777111" + randomNumber;

            addressBook.Save(readContact, username);

            var expectedResult = addressBook.Read(iD);

            Assert.That(expectedResult.TelephoneNumber, Is.EqualTo(readContact.TelephoneNumber));
        }
コード例 #6
0
        public void ShouldReturnTwoContactsWhichFirstnameAndSurnameMatchSearchText()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var name = random.Next().ToString();

            var contact = new Contact(name, "Smith", "01733 333555" + random.Next());
            var contactTwo = new Contact("Joe", name, "01733 444888" + random.Next());

            addressBook.Save(contact, username);
            addressBook.Save(contactTwo, username);

            var searchText = name;
            var searchResult = addressBook.Search(searchText);

            Assert.That(searchResult.Count, Is.EqualTo(2));
        }
コード例 #7
0
        public void ShouldReturnContactUsingSearchByTelephone()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var firstName = "Amanda" + random.Next();
            var surname = "Jones" + random.Next();
            var telephoneNumber = "01724 567555" + random.Next();

            var customer = new Contact(firstName, surname, telephoneNumber);

            var lastContact = addressBook.Save(customer, username);

            var expectedResult = addressBook.Read(lastContact.Id);

            var searchedPerson = addressBook.Search(telephoneNumber);

            Assert.That(searchedPerson.Count, Is.EqualTo(1));
            var contact = searchedPerson.Single();

            Assert.That(contact.Id, Is.EqualTo(expectedResult.Id));
            Assert.That(contact.FirstName, Is.EqualTo(expectedResult.FirstName));
            Assert.That(contact.Surname, Is.EqualTo(expectedResult.Surname));
            Assert.That(contact.TelephoneNumber, Is.EqualTo(expectedResult.TelephoneNumber));
        }
コード例 #8
0
        public void ShouldReturnContactBySearchingOnlyTheFirstSetOfCharactersOfATelephoneNumber()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var firstName = "Amanda" + random.Next();
            var surname = "Jones" + random.Next();
            var telephoneNumber = "01724 567892" + random.Next();

            var customer = new Contact(firstName, surname, telephoneNumber);

            var lastContact = addressBook.Save(customer, username);

            var expectedResult = addressBook.Read(lastContact.Id);

            const string searchText = "01724";
            var searchResult = addressBook.Search(searchText);

            Assert.That(searchResult.Any(p => p.TelephoneNumber == expectedResult.TelephoneNumber && p.Surname == expectedResult.Surname && p.FirstName == expectedResult.FirstName),Is.True);
        }
コード例 #9
0
        public void ShouldFindContactUsingSearchWithAtLeastThreeCharacters()
        {
            const string username = "******";
            var addressBook = new RealAddressBook(username);

            var random = new Random();

            var firstName = "Amanda" + random.Next();
            var surname = "Jones" + random.Next();
            var telephoneNumber = "01724 567892" + random.Next();

            var customer = new Contact(firstName, surname, telephoneNumber);

            var lastContact = addressBook.Save(customer, username);

            var expectedResult = addressBook.Read(lastContact.Id);

            const string searchText = "ama";
            var searchResult = addressBook.Search(searchText);

            Assert.That(
                searchResult.Any(p => p.Surname == expectedResult.Surname && p.FirstName == expectedResult.FirstName),
                Is.True);
        }
コード例 #10
0
 public Contact Save(Contact person, string _username)
 {
     Contacts.Add(person);
     return person;
 }