Esempio n. 1
0
        public void TestInsertUpdateAndGetWeightTicket()
        {
            WeightTicketsBL weightTicketBL = new WeightTicketsBL(connectionString);
            WeightTicket    weightTicket   = WeightTicketHelper.CreateDummyTicket();

            weightTicket = weightTicketBL.InsertWeightTicket(weightTicket);
            Assert.IsTrue(weightTicket.Id > 0);
            //Test get by Id
            List <WeightTicket> savedTickets = weightTicketBL.GetWeightTicket(weightTicket.Id);

            Assert.IsTrue(savedTickets.Count() == 1);
            WeightTicket savedTicket = savedTickets[0];

            Assert.IsTrue(savedTicket.Id == weightTicket.Id); //Todo create custom validator to check all properties
            //Test get all
            savedTickets = weightTicketBL.GetWeightTicket();
            savedTicket  = (from ticket in savedTickets where ticket.Id == savedTicket.Id select ticket).FirstOrDefault();
            Assert.IsTrue(savedTicket != null);
            //Test update
            weightTicket.SubTotal    = 20;
            weightTicket.ApplyDrying = false; //Todo check other properties
            weightTicket             = weightTicketBL.UpdateWeightTicket(weightTicket);
            savedTickets             = weightTicketBL.GetWeightTicket(weightTicket.Id);
            Assert.IsTrue(savedTickets != null && savedTickets.Count() == 1);
            savedTicket = savedTickets[0];
            Assert.IsTrue(savedTicket.SubTotal == 20);
            Assert.IsTrue(!savedTicket.ApplyDrying);
            //Test delete
            bool result = weightTicketBL.DeleteWeightTicket(savedTicket.Id);

            Assert.IsTrue(result);
            savedTickets = weightTicketBL.GetWeightTicket(weightTicket.Id);
            Assert.IsTrue(savedTickets.Count() == 0);
        }
Esempio n. 2
0
        public void TestGetErrors()
        {
            WeightTicketsBL weightTicketBL = new WeightTicketsBL(connectionString);

            try
            {
                weightTicketBL.GetWeightTicket(0);
            }
            catch (WeightTicketException exception)
            {
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidId));
            }
        }
Esempio n. 3
0
        public IHttpActionResult GetAll()
        {
            GetWeightTicketResponse response = new GetWeightTicketResponse();

            try
            {
                List <WeightTicket> tickets = weightTicketsBL.GetWeightTicket();
                response.WeightTickets = tickets;
                response.Success       = true;
            }
            catch (WeightTicketException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Success      = false;
            }
            return(Ok(response));
        }