// Primer ejemplo
        static void FirtExample()
        {
            var authorService = new AuthorService();
            var albumService  = new AlbumService();
            var songService   = new SongService();

            var album = new Album
            {
                Title  = "The Trooper",
                Author = new Author
                {
                    Name = "Iron Maiden"
                }
            };

            albumService.Add(album);

            songService.Add(new Song
            {
                Description = "Es una canción escrita por el bajista Steve Harris publicado el 20 de junio de 1983",
                Title       = "The Trooper",
                Duration    = TimeSpan.FromSeconds(250),
                AlbumId     = album.Id
            });
        }
Beispiel #2
0
        public void Add_sale()
        {
            var conn = new SqliteConnection("DataSource=:memory:");

            conn.Open();

            try
            {
                var options = new DbContextOptionsBuilder <DatabaseContext>()
                              .UseSqlite(conn)
                              .Options;

                using (var context = new DatabaseContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new DatabaseContext(options))
                {
                    CashbackService cashbackService = new CashbackService(new CashbackRepository(context));
                    cashbackService.InitializeCashbackDatabase();

                    AlbumService albumService = new AlbumService(new AlbumRepository(context));

                    DataMock
                    .GenerateAlbums()
                    .ToList()
                    .ForEach(album => albumService.Add(album));

                    var albums = albumService.GetPaged(1, 5).ToList();

                    List <AlbumDTO> dtos = new List <AlbumDTO>();

                    albums.ForEach(x => dtos.Add(x.ConvertTo(typeof(AlbumDTO))));

                    SaleService saleService = new SaleService(new SaleRepository(context), cashbackService, albumService);

                    int insertedId = saleService.RegisterSale(dtos);

                    Assert.Equal(1, insertedId);
                }
            }
            finally
            {
                conn.Close();
            }
        }