Ejemplo n.º 1
0
        public void Controller_Avatar_Delete_Post_Valid_Data_Should_Delete_Pass()
        {
            // Arrange
            AvatarItemController controller = new AvatarItemController();
            var data = new AvatarItemModel
            {
                Description = "description",
                Name        = "Name",
                Uri         = "picture"
            };

            var id = data.Id;

            bool isFound = true;

            // Make an avatar
            AvatarItemBackend.Instance.Create(data);

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(data) as ViewResult;

            var dataRead = AvatarItemBackend.Instance.Read(id);

            if (dataRead == null)
            {
                isFound = false;
            }

            // Assert
            Assert.AreEqual(false, isFound, TestContext.TestName);
        }
Ejemplo n.º 2
0
        public void Controller_Avatar_Delete_ID_Bogus_Should_Return_Empty_Model()
        {
            // Arrange
            AvatarItemController controller = new AvatarItemController();
            string id = "bogus";

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(id) as ViewResult;

            // Assert
            Assert.AreEqual(null, result.Model, TestContext.TestName);
        }
Ejemplo n.º 3
0
        public void Controller_Avatar_Delete_Post_InValid_Should_Return_Error_Page()
        {
            /// <summary>
            /// This Test calls the Delete, but passes null data
            /// The controller will return a redirect to the error home page
            /// So the test needs to cast the return to a redirect, and then check that it got to the home error page
            /// </summary>

            // Arrange
            AvatarItemController controller = new AvatarItemController();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Delete((AvatarItemModel)null);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
Ejemplo n.º 4
0
        public void Controller_Avatar_Delete_ID_Valid_Should_Pass()
        {
            // Arrange
            AvatarItemController controller = new AvatarItemController();

            // Get the first Avatar from the DataSource
            string id = AvatarItemBackend.Instance.GetFirstAvatarItemId();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(id) as ViewResult;

            var resultAvatar = result.Model as AvatarItemModel;

            AvatarItemBackend.Instance.Reset();

            // Assert
            Assert.AreEqual(id, resultAvatar.Id, TestContext.TestName);
        }
Ejemplo n.º 5
0
        public void Controller_Avatar_Delete_Post_InValid_Model_Should_Return_Error()
        {
            // Arrange
            var controller = new AvatarItemController();

            var data = new AvatarItemModel
            {
                Description = "description"
            };

            // Make a model error then try to send it as a Avatar
            controller.ModelState.AddModelError("test", "test");

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(data) as ViewResult;

            // Assert
            Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName);
        }
Ejemplo n.º 6
0
        public void Controller_Avatar_Delete_Post_Invalid_Null_Id_Should_Return_Model()
        {
            // Arrange
            AvatarItemController controller = new AvatarItemController();
            var data = new AvatarItemModel
            {
                Description = "description",
                Id          = null,
                Name        = "Name",
                Uri         = "picture"
            };

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(data) as ViewResult;

            var resultAvatar = result.Model as AvatarItemModel;

            // Assert
            Assert.AreEqual(data.Description, resultAvatar.Description, TestContext.TestName);
        }