Пример #1
0
        public void Setup()
        {
            var playersRepository = Ioc.Get<IPlayersRepository>() as PlayersRepositoryStub;
            playersRepository.Players.Clear();

            _player = null;
            _httpNotFoundResult = null;
        }
        public void PurchaseOrderLinesController_Details_isNotValid()
        {
            PurchaseOrderLinesController controller = new PurchaseOrderLinesController();

            HttpNotFoundResult result = controller.Details(9999999) as HttpNotFoundResult;
            var expectedResult = new HttpNotFoundResult().GetType();

            Assert.IsInstanceOfType(result, expectedResult);
        }
        public void RetailersController_Delete_GET_isNotValid()
        {
            RetailersController controller = new RetailersController();

            HttpNotFoundResult result = controller.Delete(9999999) as HttpNotFoundResult;
            var expectedResult = new HttpNotFoundResult().GetType();

            Assert.IsInstanceOfType(result, expectedResult);
        }
        public void RawMaterialsController_Details_isNotValid()
        {
            RawMaterialsController controller = new RawMaterialsController();

            HttpNotFoundResult result = controller.Details(9999999) as HttpNotFoundResult;
            var expectedResult = new HttpNotFoundResult().GetType();

            Assert.IsInstanceOfType(result, expectedResult);
        }
        public ActionResult Destroy(int UserId, int Id) {
            ActionResult result = null;

            switch (Users.GetById(UserId).DeleteAccount(Id)) {
                case AccountDeleteResult.Deleted:
                    result = Json(new { success = true });
                    break;

                case AccountDeleteResult.NoSuchAccount:
                    result = new HttpNotFoundResult();
                    break;
            }

            return result;
        }
        public ActionResult Update(int Id, string Name, string Email) {
            ActionResult result = null;

            User user = new User {Id = Id, Name = Name, Email = Email};
            switch (Users.Update(user)) {
                case UserUpdateResult.Updated:
                    result = Json(Users.GetById(Id));
                    break;

                case UserUpdateResult.NoSuchUser:
                    result = new HttpNotFoundResult();
                    break;

                case UserUpdateResult.EmailInvalid:
                    result = new HttpStatusCodeResult(400);
                    break;

                case UserUpdateResult.NameOrEmailAlreadyTaken:
                    result = new HttpStatusCodeResult(409);
                    break;
            }

            return result;
        }
        public ActionResult GetVisualization(string ltiSessionId)
        {
            ActionResult res = new HttpNotFoundResult("Failed to get visualization: unknown error");

            try
            {
                LtiSession session = null;

                using (var sessionManager = _unityContainer.Resolve<ISessionManager>())
                {
                    session = sessionManager.GetAndRefreshSession(Guid.Parse(ltiSessionId), Request.UserHostAddress);

                    if (!session.Valid)
                    {
                        throw new Exception("Unauthorized.");
                    }
                    else
                    {
                        var tool = _unityContainer.Resolve<ITool>(session.ConsumerKey)
                            .SetSessionManager(sessionManager)
                            .SetSession(session);

                        var visualizationData = tool.HandleVisualizationRequest();

                        res = View(visualizationData.ViewIdentifier, visualizationData.Model);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("Failed to get visualization: " + e.Message);
                res = new HttpNotFoundResult("Failed to get visualization: " + e.Message);
            }

            return res;
        }
        public ActionResult GetData(string ltiSessionId)
        {
            ActionResult res = new HttpNotFoundResult("Failed to download data: unknown error");

            try
            {
                LtiSession session = null;

                using (var sessionManager = _unityContainer.Resolve<ISessionManager>())
                {
                    session = sessionManager.GetAndRefreshSession(Guid.Parse(ltiSessionId), Request.UserHostAddress);

                    if (!session.Valid)
                    {
                        throw new Exception("Unauthorized.");
                    }
                    else
                    {
                        var tool = _unityContainer.Resolve<ITool>(session.ConsumerKey)
                            .SetSessionManager(sessionManager)
                            .SetSession(session);

                        var data = tool.HandleDataRequest();

                        res = File(data.Data, CsvFileData.CONTENT_TYPE, data.Filename);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("Failed to get data: " + e.Message);
                res = new HttpNotFoundResult("Failed to download data: " + e.Message);
            }

            return res;
        }
        public void ReviewsRatingInvalid()
        {
            //Initialize null game id
            int id = -1;

            //Call the controller method
            var result = controller.ReviewsRating(id);

            //Bad request for comparison
            HttpNotFoundResult badRequest = new HttpNotFoundResult();

            //Check if not found result occurs
            Assert.IsInstanceOf(badRequest.GetType(), result);
        }
        public void MemberIndex()
        {
            //Get member from db
            Member member = db.Members.FirstOrDefault();

            //Set controller context
            controller.ControllerContext = MockHelpers.GetControllerContext(db, member, "Member");

            //Call the controller method
            var result = controller.Index();
            HttpNotFoundResult badRequest = new HttpNotFoundResult();

            //Check if not found result occurs
            Assert.IsInstanceOf(badRequest.GetType(), result);
        }
        public void PurchaseOrderLinesController_Edit_GET_isNotValid()
        {
            PurchaseOrderLinesController controller = new PurchaseOrderLinesController();
            var request = new Mock<HttpRequestBase>();
            request.SetupGet(x => x.Headers).Returns(new System.Net.WebHeaderCollection { { "X-Requested-With", "XMLHttpRequest" } });
            var context = new Mock<HttpContextBase>();
            context.SetupGet(x => x.Request).Returns(request.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            HttpNotFoundResult result = controller.Edit(9999999) as HttpNotFoundResult;
            var expectedResult = new HttpNotFoundResult().GetType();

            Assert.IsInstanceOfType(result, expectedResult);
        }
        public void ProductController_Edit_GET_isNotValid()
        {
            ProductController controller = new ProductController();

            HttpNotFoundResult result = controller.Edit(9999999) as HttpNotFoundResult;
            var expectedResult = new HttpNotFoundResult().GetType();

            Assert.IsInstanceOfType(result, expectedResult);
        }
Пример #13
0
        public void WhenIGetAPlayerWhoseIdIs(int playerId)
        {
            var result = Ioc.Get<RosterController>().Details(playerId);

            if (result as ViewResult != null)
            {
                var viewResult = result as ViewResult;
                _player = viewResult.Model as Player;
            }
            else
                _httpNotFoundResult = result as HttpNotFoundResult;
        }