Пример #1
0
        public void Post_Success()
        {
            // Arrange
            CheckOutItem item = new CheckOutItem()
            {
                Id = ""
            };

            _checkOutServicesMock.Setup(x => x.AddCheckOut(item))
            .Verifiable();
            _checkOutFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Create, It.IsAny <CheckOutItem>(), null))
            .Returns(true)
            .Verifiable();

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Post(item);

            // Assert.
            Assert.IsType <CreatedResult>(actionResult);
            CreatedResult actionResultType = actionResult as CreatedResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.Created);
            _checkOutServicesMock.Verify();
            _checkOutFlowValidMock.Verify();
            _checkOutFlowValidMock.Verify();
        }
Пример #2
0
        public void Delete_Success()
        {
            // Arrange
            CheckOutItem item = new CheckOutItem()
            {
                Id = "5c012842f8e2708cf041e247"
            };
            Acknowledged deleteResult = new Acknowledged(1);

            _checkOutServicesMock.Setup(x => x.GetCheckOut(item.Id)).Returns(Task.FromResult(item));
            _checkOutServicesMock.Setup(x => x.DeleteCheckOut(item.Id))
            .ReturnsAsync(deleteResult)
            .Verifiable();
            _checkOutFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Delete, It.IsAny <CheckOutItem>(), null))
            .Returns(true)
            .Verifiable();

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Delete(item.Id);

            // Assert.
            Assert.IsType <NoContentResult>(actionResult);
            NoContentResult actionResultType = actionResult as NoContentResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.NoContent);
            _checkOutServicesMock.Verify();
            _checkOutFlowValidMock.Verify();
        }
Пример #3
0
        public void CheckOut()
        {
            CheckOutController controller = new CheckOutController();
            ViewResult         result     = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
        }
Пример #4
0
        public void Get_All_Success()
        {
            // Arrange
            CheckOutItem item = new CheckOutItem()
            {
                Id = "5c012842f8e2708cf041e247"
            };
            IEnumerable <CheckOutItem> items = new List <CheckOutItem>()
            {
                item
            };

            _checkOutServicesMock.Setup(x => x.GetCheckOutList()).Returns(Task.FromResult(items));

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Get().Result;

            // Assert.
            Assert.IsType <OkObjectResult>(actionResult);
            OkObjectResult actionResultType = actionResult as OkObjectResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal(((List <CheckOutItem>)actionResultType.Value), ((List <CheckOutItem>)items.ToList()));
        }
Пример #5
0
        public void Put_FlowValidError()
        {
            // Arrange
            CheckOutItem item = new CheckOutItem()
            {
                Id = "5c012842f8e2708cf041e247"
            };

            _checkOutServicesMock.Setup(x => x.GetCheckOut(item.Id)).Returns(Task.FromResult(item));
            _checkOutFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Update, It.IsAny <CheckOutItem>(), It.IsAny <CheckOutItem>()))
            .Returns(false)
            .Verifiable();

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Put(item);

            // Assert.
            Assert.IsType <BadRequestResult>(actionResult);
            BadRequestResult actionResultType = actionResult as BadRequestResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
            _checkOutServicesMock.Verify();
            _checkOutFlowValidMock.Verify();
        }
 public void TestMethod2()
 {
     using (TransactionScope transaction = new TransactionScope())
     {
         CheckOutController checkOutController = new CheckOutController();
         ViewResult         result             = checkOutController.Index("900047107") as ViewResult;
         Assert.AreEqual("", result.ViewName);
     }
 }
 public void TestMethod1()
 {
     using (TransactionScope transaction = new TransactionScope())
     {
         CheckOutController checkOutController = new CheckOutController();
         PartialViewResult  result             = checkOutController.CheckOutCardInfo("900047107");
         Assert.AreEqual("_showPatronInfo", result.ViewName);
     }
 }
        public CheckOutControllerTest(DbContextFixture fixture)
        {
            fixture.Seed();
            var context = new LibraryContext(fixture.ContextOptions);

            controller        = new CheckOutController(context, checkOutServiceMock.Object, new BranchesService(context));
            checkOutViewModel = new CheckOutViewModel
            {
                Barcode  = "QA123:1",
                PatronId = 1
            };
        }
            private int CreateCheckedOutHolding(int id, CheckOutController checkoutController, int copyNumber)
            {
                var holdingId = holdingRepo.Create(new Holding {
                    Classification = "X", CopyNumber = copyNumber, BranchId = branchId
                });
                var checkOutViewModel = new CheckOutViewModel {
                    Barcode = $"X:{copyNumber}", PatronId = id
                };
                var result = checkoutController.Index(checkOutViewModel) as ViewResult;

                return(holdingId);
            }
Пример #10
0
        public void Put_ObjectNull()
        {
            // Arrange

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Put(null);

            // Assert.
            Assert.IsType <BadRequestResult>(actionResult);
            BadRequestResult actionResultType = actionResult as BadRequestResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
        }
Пример #11
0
        public void Delete_IdEmpty()
        {
            // Arrange

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Delete(string.Empty);

            // Assert.
            Assert.IsType <BadRequestResult>(actionResult);
            BadRequestResult actionResultType = actionResult as BadRequestResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
            _checkOutServicesMock.Verify();
        }
Пример #12
0
        public void Post_ObjectIdNotEmpty()
        {
            // Arrange
            CheckOutItem item = new CheckOutItem()
            {
                Id = "5c012842f8e2708cf041e247"
            };

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Post(item);

            // Assert.
            Assert.IsType <BadRequestResult>(actionResult);
            BadRequestResult actionResultType = actionResult as BadRequestResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
        }
Пример #13
0
        public void Initialize()
        {
            holdingRepo = new InMemoryRepository <Holding>();

            var branchRepo = new InMemoryRepository <Branch>();

            someValidBranchId = branchRepo.Create(new Branch()
            {
                Name = "b"
            });

            patronRepo        = new InMemoryRepository <Patron>();
            someValidPatronId = patronRepo.Create(new Patron {
                Name = "x"
            });

            controller = new CheckOutController(branchRepo, holdingRepo, patronRepo);
            checkout   = new CheckOutViewModel();
        }
Пример #14
0
        public void Get_Id_IdError()
        {
            // Arrange
            string       fakeId = "this_is_not_a_id";
            CheckOutItem item   = new CheckOutItem()
            {
                Id = "5c012842f8e2708cf041e247"
            };

            _checkOutServicesMock.Setup(x => x.GetCheckOut(item.Id)).Returns(Task.FromResult(item));

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Get(fakeId).Result;

            // Assert.
            Assert.IsType <NotFoundResult>(actionResult);
            NotFoundResult actionResultType = actionResult as NotFoundResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.NotFound);
        }
Пример #15
0
        public void Get_Id_Success()
        {
            // Arrange
            string       fakeId = "5c012842f8e2708cf041e247";
            CheckOutItem item   = new CheckOutItem()
            {
                Id = "5c012842f8e2708cf041e247"
            };

            _checkOutServicesMock.Setup(x => x.GetCheckOut(item.Id)).Returns(Task.FromResult(item));

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Get(fakeId).Result;

            // Assert.
            Assert.IsType <OkObjectResult>(actionResult);
            OkObjectResult actionResultType = actionResult as OkObjectResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal(((CheckOutItem)actionResultType.Value), item);
        }
Пример #16
0
        public void Put_Success()
        {
            // Arrange
            CheckOutItem itemFrom = new CheckOutItem()
            {
                Id           = "5c012842f8e2708cf041e247",
                CurrentState = CheckOutItem.STATE_PAID
            };
            CheckOutItem itemTo = new CheckOutItem()
            {
                Id           = "5c012842f8e2708cf041e247",
                CurrentState = CheckOutItem.STATE_CLOSED
            };

            _checkOutServicesMock.Setup(x => x.GetCheckOut(itemFrom.Id)).Returns(Task.FromResult(itemFrom));
            _checkOutServicesMock.Setup(x => x.UpdateCheckOut(itemTo.Id, itemTo))
            .ReturnsAsync(true)
            .Verifiable();
            _checkOutFlowValidMock
            .Setup(x => x.IsValidOperation(BaseValidatorType.Update, It.IsAny <CheckOutItem>(), It.IsAny <CheckOutItem>()))
            .Returns(true)
            .Verifiable();

            // Act
            CheckOutController controller   = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object);
            ActionResult       actionResult = controller.Put(itemTo);

            // Assert.
            Assert.IsType <AcceptedResult>(actionResult);
            AcceptedResult actionResultType = actionResult as AcceptedResult;

            Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.Accepted);
            _checkOutServicesMock.Verify();
            _checkOutFlowValidMock.Verify();

            // Assert Bus.
            _eventBusMock.Verify(x => x.Publish(It.IsAny <CheckOutEvent>()));
        }
 public void CreateCheckoutController()
 {
     checkoutController = new CheckOutController(branchRepo, holdingRepo, patronRepo);
 }