Exemple #1
0
        public async Task GetPurchaseTest()
        {
            purchaseRepository.Setup(t => t.GetById("5f0e43f02f695b5ae0d8526e")).Returns(Task.Run(() => purchase));
            var result = await purchaseController.Get(purchaseRepository.Object, "5f0e43f02f695b5ae0d8526e");

            Assert.That(result, Is.InstanceOf <OkObjectResult>());
            var ok = result as OkObjectResult;

            Assert.That(ok, Is.Not.Null);
        }
        public async Task ReadPurchaseList_Success_ReturnStatusCodeOk()
        {
            IHttpActionResult result = await purchaseController.Get(new BaseApiController <Purchase> .PaginationQuery
            {
                Limit = 2,
                Skip  = 0
            });

            HttpJsonApiResult <IEnumerable <PurchaseViewModel> > contentResult = result as HttpJsonApiResult <IEnumerable <PurchaseViewModel> >;

            Assert.AreEqual(HttpStatusCode.OK, contentResult.StatusCode);
        }
        public PurchaseModule(OrmLiteConnectionFactory db)
            : base("/purchases")
        {
            {
                const string obj = "Purchase";

                Get["/"] = _ =>
                {
                    var controller = new PurchaseController(db);
                    return(View[obj + "List", controller.ListAll()]);
                };

                Get["/{id}"] = req =>
                {
                    var controller = new PurchaseController(db);
                    var item       = controller.Get(req.id);
                    if (item == null)
                    {
                        return(404);
                    }
                    return(View[obj + "Detail", item]);
                };

                Get["/create"] = _ =>
                {
                    var model = new
                    {
                        Movies     = (new MovieController(db)).ListAll().Movies,
                        Showings   = (new ShowingsController(db)).ListAll(),
                        Customers  = new List <Customer>(),
                        Promotions = (new PromotionController(db)).ListAll(),
                    };

                    var selects = new
                    {
                        Movies     = model.Movies.Select(movie => new SelectListItem(movie.Title, movie.MovieId.ToString(), false)),
                        Showings   = model.Showings.Select(showing => new SelectListItem(showing.Time.ToString(), showing.ShowingId.ToString(), false)),
                        Customers  = model.Customers.Select(showing => new SelectListItem(showing.Name.ToString(), showing.CustomerId.ToString(), false)),
                        Promotions = model.Promotions.Select(showing => new SelectListItem(showing.PromotionName.ToString(), showing.PromotionId.ToString(), false)),
                    };
                    return(View["New" + obj, selects]);
                };

                Post["/create"] = _ =>
                {
                    var item = this.Bind <Purchase>();
                    LogTo.Debug("Adding purchase: {0}", item);
                    var controller = new PurchaseController(db);
                    var newId      = controller.Add(item);
                    return(Response.AsRedirect(ModulePath + "/" + newId));
                };

                Post["/update/{id}"] = _ => { return(500); };
            }
        }
        public PurchaseModule(OrmLiteConnectionFactory db)
            : base("/purchases")
        {
            {
                const string obj = "Purchase";

                Get["/"] = _ =>
                {
                    var controller = new PurchaseController(db);
                    return View[obj + "List", controller.ListAll()];
                };

                Get["/{id}"] = req =>
                {
                    var controller = new PurchaseController(db);
                    var item = controller.Get(req.id);
                    if (item == null)
                        return 404;
                    return View[obj + "Detail", item];
                };

                Get["/create"] = _ =>
                {
                    var model = new
                    {
                        Movies = (new MovieController(db)).ListAll().Movies,
                        Showings = (new ShowingsController(db)).ListAll(),
                        Customers = new List<Customer>(),
                        Promotions = (new PromotionController(db)).ListAll(),
                    };

                    var selects = new
                    {
                        Movies = model.Movies.Select(movie => new SelectListItem(movie.Title, movie.MovieId.ToString(), false)),
                        Showings = model.Showings.Select(showing => new SelectListItem(showing.Time.ToString(), showing.ShowingId.ToString(), false)),
                        Customers = model.Customers.Select(showing => new SelectListItem(showing.Name.ToString(), showing.CustomerId.ToString(), false)),
                        Promotions = model.Promotions.Select(showing => new SelectListItem(showing.PromotionName.ToString(), showing.PromotionId.ToString(), false)),
                    };
                    return View["New" + obj, selects];
                };

                Post["/create"] = _ =>
                {
                    var item = this.Bind<Purchase>();
                    LogTo.Debug("Adding purchase: {0}", item);
                    var controller = new PurchaseController(db);
                    var newId = controller.Add(item);
                    return Response.AsRedirect(ModulePath + "/" + newId);
                };

                Post["/update/{id}"] = _ => { return 500; };
            }
        }
        public void TestAdd()
        {
            var mockRepo = new Mock <ECommerceContext>();

            mockRepo.Setup(repo => repo.Orders)
            .ReturnsAsync();

            var controller    = new PurchaseController(mockRepo.Object);
            var returnedValue = controller.Get("123456");

            Assert.True(returnedValue == "success");
        }
Exemple #6
0
        public void TestPurchaseGetByIdNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Purchase.GetById(id))
            .Returns(null as Purchase);

            var controller = new PurchaseController(mockBusinessLogic.Object);

            // Act
            var result = controller.Get(id);

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Exemple #7
0
        public void TestPurchaseGetById()
        {
            // Arrange
            var expectedPurchase = FakePurchases().First();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Purchase.GetById(expectedPurchase.Id))
            .Returns(expectedPurchase);

            var controller = new PurchaseController(mockBusinessLogic.Object);

            // Act
            var result           = controller.Get(expectedPurchase.Id);
            var obtainedPurchase = (result as OkNegotiatedContentResult <Purchase>).Content;

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsNotNull(obtainedPurchase);
            Assert.AreEqual(expectedPurchase.Id, obtainedPurchase.Id);
        }