Esempio n. 1
0
        public void ConfirmRetrieval_DoesNotExist()
        {
            // Arrange
            var controller = new RetrievalAPIController()
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration(),
                Context       = context,
            };

            // Act
            IHttpActionResult actionResult = controller.ConfirmRetrieval(new ConfirmRetrievalViewModel()
            {
                RetrievalId = "RETCONTROLTEST",
                Email       = "*****@*****.**",
            });
            BadRequestErrorMessageResult badRequest = actionResult as BadRequestErrorMessageResult;

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult));
            Assert.AreEqual("Retrieval does not exist", badRequest.Message);
        }
Esempio n. 2
0
        public void ConfirmRetrieval_AlreadyConfirmed_BadRequest()
        {
            // Arrange
            var requisitionRepository = new RequisitionRepository(context);
            var departmentRepository  = new DepartmentRepository(context);

            var requisition = requisitionRepository.Save(new Requisition()
            {
                RequisitionId      = "RETCONTROLTEST",
                CollectionPoint    = departmentRepository.FindById("ENGL").CollectionPoint,
                Department         = departmentRepository.FindById("ENGL"),
                CreatedDateTime    = DateTime.Now,
                RequisitionDetails = new List <RequisitionDetail>()
                {
                    new RequisitionDetail()
                    {
                        RequisitionId = "RETCONTROLTEST",
                        ItemCode      = "E030",
                        Item          = new ItemService(context).FindItemByItemCode("E030"),
                        Quantity      = 30,
                    }
                }
            });
            var retrieval = retrievalRepository.Save(new Retrieval()
            {
                RetrievalId  = "RETCONTROLTEST",
                Requisitions = new List <Requisition>()
                {
                    requisition
                },
                CreatedDateTime = DateTime.Now,
                Status          = new StatusService(context).FindStatusByStatusId(20),
            });
            var disbursement = disbursementRepository.Save(new Disbursement()
            {
                DisbursementId      = "RETCONTROLTEST",
                Department          = departmentRepository.FindById("ENGL"),
                DisbursementDetails = new List <DisbursementDetail>()
                {
                    new DisbursementDetail()
                    {
                        DisbursementId = "RETCONTROLTEST",
                        ItemCode       = "E030",
                        Item           = new ItemService(context).FindItemByItemCode("E030"),
                        PlanQuantity   = 30,
                        ActualQuantity = 30,
                        Status         = new StatusService(context).FindStatusByStatusId(18),
                    }
                },
                Retrieval       = retrieval,
                Status          = new StatusService(context).FindStatusByStatusId(7),
                CreatedDateTime = DateTime.Now,
            });
            var expectedStatus = new StatusService(context).FindStatusByStatusId(20);

            var controller = new RetrievalAPIController()
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration(),
                Context       = context,
            };

            // Act
            IHttpActionResult actionResult = controller.ConfirmRetrieval(new ConfirmRetrievalViewModel()
            {
                RetrievalId = "RETCONTROLTEST",
                Email       = "*****@*****.**",
            });
            BadRequestErrorMessageResult badRequest = actionResult as BadRequestErrorMessageResult;

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult));
            Assert.AreEqual("Retrieval already confirmed", badRequest.Message);
        }
Esempio n. 3
0
        public void ConfirmRetrieval_Valid()
        {
            // Arrange
            var requisitionRepository = new RequisitionRepository(context);
            var departmentRepository  = new DepartmentRepository(context);

            var requisition = requisitionRepository.Save(new Requisition()
            {
                RequisitionId      = "RETCONTROLTEST",
                CollectionPoint    = departmentRepository.FindById("ENGL").CollectionPoint,
                Department         = departmentRepository.FindById("ENGL"),
                CreatedDateTime    = DateTime.Now,
                Status             = new StatusRepository(context).FindById(7),
                RequisitionDetails = new List <RequisitionDetail>()
                {
                    new RequisitionDetail()
                    {
                        RequisitionId = "RETCONTROLTEST",
                        ItemCode      = "E030",
                        Item          = new ItemService(context).FindItemByItemCode("E030"),
                        Quantity      = 30,
                        Status        = new StatusRepository(context).FindById(7),
                    }
                }
            });
            var retrieval = retrievalRepository.Save(new Retrieval()
            {
                RetrievalId  = "RETCONTROLTEST",
                Requisitions = new List <Requisition>()
                {
                    requisition
                },
                CreatedDateTime = DateTime.Now,
                Status          = new StatusService(context).FindStatusByStatusId(19),
            });
            var disbursement = disbursementRepository.Save(new Disbursement()
            {
                DisbursementId      = "RETCONTROLTEST",
                Department          = departmentRepository.FindById("ENGL"),
                DisbursementDetails = new List <DisbursementDetail>()
                {
                    new DisbursementDetail()
                    {
                        DisbursementId = "RETCONTROLTEST",
                        ItemCode       = "E030",
                        Item           = new ItemService(context).FindItemByItemCode("E030"),
                        PlanQuantity   = 30,
                        ActualQuantity = 30,
                        Status         = new StatusService(context).FindStatusByStatusId(18),
                    }
                },
                Retrieval       = retrieval,
                Status          = new StatusService(context).FindStatusByStatusId(7),
                CreatedDateTime = DateTime.Now,
            });
            var expectedStatus = new StatusService(context).FindStatusByStatusId(20);

            var controller = new RetrievalAPIController()
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration(),
                Context       = context,
            };

            // Act
            IHttpActionResult actionResult = controller.ConfirmRetrieval(new ConfirmRetrievalViewModel()
            {
                RetrievalId = "RETCONTROLTEST",
                Email       = "*****@*****.**",
            });
            var contentResult = actionResult as OkNegotiatedContentResult <MessageViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(contentResult.Content.Message, "Successfully confirmed");
            var result = new RetrievalRepository(context).FindById("RETCONTROLTEST");

            Assert.AreEqual(expectedStatus.Name, result.Status.Name);
        }