Beispiel #1
0
        public HopsController(IngredientsContext ctx, ILogger <HopsController> logger, HopRepository hopRepo)
        {
            _logger  = logger;
            _context = ctx;

            _hopRepo = hopRepo;
        }
Beispiel #2
0
        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 { }
        }
Beispiel #3
0
        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 { }
        }
Beispiel #4
0
        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 { }
        }
Beispiel #5
0
        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 { }
        }
Beispiel #6
0
 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 { }
 }