Esempio n. 1
0
        static void Main(string[] args)
        {
            BaseEntity book;
            IEntityService <BaseEntity> entityService = new EntityStorage <BaseEntity>();

            for (int i = 0; i < s_bookNames.Length; i++)
            {
                book = new BookEntity()
                {
                    Id          = i + 1,
                    Description = string.Format("Descrition of a book: {0}", s_bookNames[i]),
                    Name        = s_bookNames[i],
                    Price       = (i + 1) * rand.Next(0, 30)
                };
                entityService.Add(book);
            }

            Console.WriteLine("Library list:");

            ShowAllEntities(entityService);

            Console.WriteLine("If you want to remove a book, then just write an ID below. If no, then press 'Enter' button");
            int id = 0;

            if (int.TryParse(Console.ReadLine(), out id) && id > 0)
            {
                var bookEntity = entityService.Find(id);
                if (bookEntity != null)
                {
                    try
                    {
                        entityService.Delete(bookEntity);
                        ShowAllEntities(entityService);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception received while deliting the book with id {0}\nEcxeption message: ", id, ex.Message);
                    }
                }
                else
                {
                    Console.WriteLine("Book with id {0} not found", id);
                }
            }
            else
            {
                Console.WriteLine("Nothing to delete");
            }

            Console.ReadLine();
        }
Esempio n. 2
0
 public async Task Add_NullEntity()
 {
     // Act & Assert
     await Assert.ThrowsAsync <ArgumentNullException>(async() => await _testObject.Add(null));
 }