public HopsController(IngredientsContext ctx, ILogger <HopsController> logger, HopRepository hopRepo) { _logger = logger; _context = ctx; _hopRepo = hopRepo; }
public void Create_ThrowsDuplicateHopExpection() { try { using (var context = new DatabaseContext(options)) { IHopRepository service = new HopRepository(context, NullLogger <HopRepository> .Instance); Warehouse wh = new Warehouse() { Code = "123456789", Description = "yo dawg", ProcessingDelayMins = 1 }; service.Create(wh); } using (var context = new DatabaseContext(options)) { IHopRepository service = new HopRepository(context, NullLogger <HopRepository> .Instance); Warehouse wh = new Warehouse() { Code = "123456789", Description = "yo dawg", ProcessingDelayMins = 1 }; Assert.Throws <DuplicateHopExpection>(() => service.Create(wh)); } } finally { } }
public void Create_IsSaved() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IHopRepository service = new HopRepository(context, NullLogger <HopRepository> .Instance); Warehouse wh = new Warehouse() { Code = "123456789", Description = "yo dawg", ProcessingDelayMins = 1 }; service.Create(wh); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { Assert.Equal(1, context.Hops.Count()); Assert.Equal("123456789", context.Hops.Single().Code); Assert.Equal("yo dawg", context.Hops.Single().Description); } } finally { } }
public void GetByCode_ReturnsHop() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { Warehouse wh = new Warehouse() { Code = "123456789", Description = "yo dawg", ProcessingDelayMins = 1 }; context.Hops.Add(wh); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { IHopRepository service = new HopRepository(context, NullLogger <HopRepository> .Instance); Warehouse wh = (Warehouse)service.GetByCode("123456789"); Assert.Equal("123456789", wh.Code); Assert.Equal("yo dawg", wh.Description); } } finally { } }
public void Delete_IsEmpty() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { Warehouse wh = new Warehouse() { Code = "123456789", Description = "yo dawg", ProcessingDelayMins = 1 }; context.Hops.Add(wh); context.SaveChanges(); } // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IHopRepository service = new HopRepository(context, NullLogger <HopRepository> .Instance); service.Delete(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { //Assert.Equal(0, context.Hops.Count()); } } finally { } }
public void GetByCode_ThrowsHopNotFoundExpection() { try { using (var context = new DatabaseContext(options)) { IHopRepository service = new HopRepository(context, NullLogger <HopRepository> .Instance); Warehouse wh = new Warehouse() { Code = "123456789", Description = "yo boi", ProcessingDelayMins = 1 }; Assert.Throws <HopNotFoundExpection>(() => service.GetByCode("123456789")); } } finally { } }