public void Initialize_items() { 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 service = new CashbackService(new CashbackRepository(context)); service.InitializeCashbackDatabase(); } using (var context = new DatabaseContext(options)) { Assert.Equal(28, context.Cashbacks.Count()); } } finally { conn.Close(); } }
public void Get_cashbacks_for_today() { 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 service = new CashbackService(new CashbackRepository(context)); service.InitializeCashbackDatabase(); } using (var context = new DatabaseContext(options)) { CashbackService service = new CashbackService(new CashbackRepository(context)); var forToday = service.GetCashbacksForToday(); Assert.NotEmpty(forToday); } } finally { conn.Close(); } }
public CashbackServiceTest() { _fixture = new Fixture(); _cashbackRepositoryMock = new Mock <ICashbackRepository>(); _cashbackConfiguration = new CashbackConfiguration(); _cashbackService = new CashbackService(_cashbackRepositoryMock.Object); }
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(); } }
public CashbackController(CashbackService service, ILogger <CashbackController> logger) { this.service = service; this.logger = logger; }