Exemplo n.º 1
0
        public HopsController(IngredientsContext ctx, ILogger <HopsController> logger, HopRepository hopRepo)
        {
            _logger  = logger;
            _context = ctx;

            _hopRepo = hopRepo;
        }
Exemplo n.º 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 { }
        }
Exemplo n.º 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 { }
        }
Exemplo n.º 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 { }
        }
Exemplo n.º 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 { }
        }
Exemplo n.º 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 { }
 }