Example #1
0
        public void AttemptingToUpdateANonExistentItemThrowsAnException()
        {
            var newItem = new NameListEntry(
                99,
                "F99-new",
                "L99-new",
                "E99-new");

            Assert.Throws <System.InvalidOperationException>(() => _nameListController.Post(newItem.Id, newItem));
        }
Example #2
0
 private void ReadNameList()
 {
     decrypted.Seek(header.NameOffset, 0);
     NameList = new List <NameListEntry>();
     for (int i = 0; i < header.NameCount; i++)
     {
         NameListEntry e = new NameListEntry();
         e.ReadFromStream(decrypted);
         NameList.Add(e);
     }
 }
Example #3
0
 public void Create(NameListEntry nameListEntry)
 {
     lock (_lockObject)
     {
         var id        = ++_nextId;
         var newRecord = new NameListEntry(
             id,
             nameListEntry.FirstName,
             nameListEntry.LastName,
             nameListEntry.Email);
         _records.Add(newRecord);
     }
 }
Example #4
0
        public void Update(NameListEntry nameListEntry)
        {
            lock (_lockObject)
            {
                var oldRecord = _records.FirstOrDefault(r => r.Id == nameListEntry.Id);

                if (oldRecord == null)
                {
                    throw new InvalidOperationException(string.Format("Could not find a record with id {0}.", nameListEntry.Id));
                }

                var newRecord = new NameListEntry(oldRecord.Id, nameListEntry.FirstName, nameListEntry.LastName, nameListEntry.Email);
                _records.Remove(oldRecord);
                _records.Add(newRecord);
            }
        }
Example #5
0
        public void CanCreateANewItem()
        {
            var newItem = new NameListEntry(
                "F-new",
                "L-new",
                "E-new");

            _nameListController.Post(newItem);

            var actual = _nameListController.Get().ToList();

            CheckRepositoryContents(
                actual,
                new[]
            {
                new NameListEntry("F1", "L1", "E1"),
                new NameListEntry("F2", "L2", "E2"),
                new NameListEntry("F3", "L3", "E3"),
                new NameListEntry("F-new", "L-new", "E-new")
            });
        }
Example #6
0
        public void CanUpdateAnExistingItem()
        {
            var oldItem = _nameListController.Get(2);
            var newItem = new NameListEntry(
                oldItem.Id,
                "F2-new",
                "L2-new",
                "E2-new");

            _nameListController.Post(newItem.Id, newItem);

            var actual = _nameListController.Get().ToList();

            CheckRepositoryContents(
                actual,
                new[]
            {
                new NameListEntry("F1", "L1", "E1"),
                new NameListEntry("F2-new", "L2-new", "E2-new"),
                new NameListEntry("F3", "L3", "E3")
            });
        }
 public void Post(int id, [FromBody] NameListEntry nameListEntry)
 {
     _nameListRepository.Update(nameListEntry);
 }
 public void Post([FromBody] NameListEntry nameListEntry)
 {
     _nameListRepository.Create(nameListEntry);
 }