예제 #1
0
        public void Delete_Not_Ajax_Request()
        {
            // Arrange
            var component = new Component()
            {
                Name = "Sałata"
            };
            var id         = 1;
            var repository = Substitute.For <IComponentRepository>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeRequest();
            var controller = new ComponentController(repository, mapper);

            controller.ControllerContext = fakeController.GetControllerContext <ComponentController>(new RouteData(), controller);

            repository.Get(id).Returns(component);

            // Act
            var result      = controller.Delete(id) as RedirectToRouteResult;
            var ajaxRequest = controller.Request.IsAjaxRequest();
            var actionName  = result.RouteValues.Values.ElementAt(0);

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(ajaxRequest, Is.False);
            Assert.That("Index", Is.EqualTo(actionName));
        }
예제 #2
0
        public void Good_Delete()
        {
            // Arrange
            var component = new Component()
            {
                Name = "Sałata"
            };
            var id         = 1;
            var repository = Substitute.For <IComponentRepository>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeAjaxRequest();
            var controller = new ComponentController(repository, mapper);

            controller.ControllerContext = fakeController.GetControllerContext <ComponentController>(new RouteData(), controller);

            repository.Get(id).Returns(component);
            repository.Delete(component);
            repository.Save();

            // Act
            var result              = controller.Delete(id) as JsonResult;
            var ajaxRequest         = controller.Request.IsAjaxRequest();
            var jsonRequestBehavior = result.JsonRequestBehavior;
            var data = result.Data;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(ajaxRequest, Is.True);
            Assert.That(jsonRequestBehavior, Is.EqualTo(JsonRequestBehavior.AllowGet));
        }
예제 #3
0
 private void bwRemove_DoWork(object sender, DoWorkEventArgs e)
 {
     foreach (var removeItem in componentToRemoveList)
     {
         ComponentController.Delete(removeItem.ComponentID);
         componentCurrentList.Remove(removeItem);
     }
 }
예제 #4
0
        public void Delete_Id_Is_Null()
        {
            // Arrange
            int?id         = null;
            var repository = Substitute.For <IComponentRepository>();
            var mapper     = Substitute.For <IMapper>();
            var controller = new ComponentController(repository, mapper);

            // Act
            var result     = controller.Delete(id) as HttpStatusCodeResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(400, Is.EqualTo(statusCode));
        }
예제 #5
0
        public void Delete_Component_Is_Null()
        {
            // Arrange
            Component component  = null;
            var       id         = 1;
            var       repository = Substitute.For <IComponentRepository>();
            var       mapper     = Substitute.For <IMapper>();

            var controller = new ComponentController(repository, mapper);

            repository.Get(id).Returns(component);

            // Act
            var result     = controller.Delete(id) as HttpNotFoundResult;
            var statusCode = result.StatusCode;

            // Assert
            Assert.That(result, !Is.Null);
            Assert.That(404, Is.EqualTo(statusCode));
        }