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

            try
            {
                weightTicketBL.InsertWeightTicket(weightTicket);
            }
            catch (WeightTicketException exception)
            {
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidCicle));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidFolio));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidProducer));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidWareHouse));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidProduct));
            }
            try
            {
                weightTicketBL.UpdateWeightTicket(weightTicket);
            }
            catch (WeightTicketException exception)
            {
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidCicle));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidFolio));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidProducer));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidWareHouse));
                Assert.IsTrue(exception.Error.HasFlag(WeightTicketError.InvalidProduct));
            }
        }
Esempio n. 2
0
        public IHttpActionResult Add(WeightTicket weightTicket)
        {
            WeightTicketResponse response = new WeightTicketResponse();

            try
            {
                weightTicket.UserId = CurrentUserId;
                WeightTicket weightTicketSaved = weightTicketsBL.InsertWeightTicket(weightTicket);
                response.WeightTicket = weightTicketSaved;
                response.Success      = true;
            }
            catch (WeightTicketException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.WeightTicket = null;
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.WeightTicket = null;
                response.Success      = false;
            }
            return(Ok(response));
        }
Esempio n. 3
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);
        }