// Test DELETE for Location
        public void LocationController_Delete_ReturnsNoContentResult_WhenDeleted()
        {
            //Arrange
            int Id = 1;

            //Act
            var result           = controller.Delete(Id);
            var getDeletedResult = controller.Get(Id);

            //Assert
            Assert.IsType <NoContentResult>(result);
            Assert.IsType <NotFoundResult>(getDeletedResult);
        }
        public async void Delete_WhenNotFound()
        {
            // arrange
            var errorCodeConverter = new ErrorCodeConverter();

            var locationServiceMoq = new Mock <ILocationService>();

            locationServiceMoq.Setup(x => x.Delete(It.IsAny <Guid>()))
            .ReturnsAsync(() => ResultCode.NotFound);

            var dataStructureConverterMoq = new Mock <IDataStructureConverter>();

            var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object)
            {
                ControllerContext = DefaultControllerContext()
            };

            // act
            var result = await sut.Delete(TestLocation().Id);

            var notFoundResult = result as NotFoundResult;

            // assert
            Assert.NotNull(notFoundResult);
        }
Esempio n. 3
0
        public void Can_Delete_Valid_Locations()
        {
            //Arrange - create a location
            Location loc = new Location {
                Id = 2, Name = "Test", Address1 = "123 N. Address", City = "Troy", Zip = "87654"
            };

            // Arrange - create the mock repository
            Mock <ILocationRepository> mock = new Mock <ILocationRepository>();

            mock.Setup(m => m.Locations).Returns(new Location[]
            {
                new Location {
                    Id = 1, Name = "L1", Address1 = "123 N. Address", City = "Troy", Zip = "87654"
                },
                loc,
                new Location {
                    Id = 3, Name = "L3", Address1 = "123 N. Address", City = "Troy", Zip = "87654"
                }
            });

            // Arrange - create the controller
            LocationsController target = new LocationsController(mock.Object);

            // Act - delete the product
            target.Delete(loc.Id);

            //Assert - ensure that the repository delete method was called with the correct location
            mock.Verify(m => m.DeleteLocation(loc.Id));
        }
        public void Location_Can_Delete()
        {
            // Arrange
            Location Location = new Location {
                LocationId = 2, ParentId = 1, Description = "L2"
            };

            Mock <ILogger <LocationsController> > mockLogger             = new Mock <ILogger <LocationsController> >();
            Mock <ILocationRepository>            mockLocationRepository = new Mock <ILocationRepository>();
            Mock <ITempDataDictionary>            tempData = new Mock <ITempDataDictionary>();

            mockLocationRepository.Setup(m => m.GetLocations).Returns(new Location[] {
                new Location {
                    LocationId = 1, ParentId = 0, Description = "L1"
                },
                Location,
                new Location {
                    LocationId = 3, ParentId = 1, Description = "L3"
                },
            }.AsQueryable <Location>());

            LocationsController controller = new LocationsController(mockLogger.Object, mockLocationRepository.Object)
            {
                TempData = tempData.Object
            };

            // Act
            controller.Delete(Location.LocationId);

            // Assert
            mockLocationRepository.Verify(m => m.DeleteLocation(Location.LocationId));
        }
        public void DeletGet()
        {
            var controller = new LocationsController();

            var result = controller.Delete(2);

            Assert.IsNotNull(result);
        }
        public void Post_MethodDeletesItem_Test()
        {
            DBSetUp();
            LocationsController controller = new LocationsController(mock.Object);
            ViewResult          indexView  = new LocationsController(mock.Object).Index() as ViewResult;
            var      collection            = indexView.ViewData.Model as IEnumerable <Location>;
            Location location = collection.FirstOrDefault(c => c.LocationId == 1);

            controller.Delete(1);
            var expectedCollection = indexView.ViewData.Model as IEnumerable <Location>;

            Assert.DoesNotContain <Location>(location, expectedCollection);
        }
Esempio n. 7
0
        public async Task Delete_LocationName_RepoDeleteHitWithExpression()
        {
            // Arrange
            ILocationService    service    = Substitute.For <ILocationService>();
            LocationsController controller = GetController(locationService: service);
            string id = "Contoso";

            // Act
            await controller.Delete(id);

            // Assert
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            service.Received(1).DeleteByName("Contoso");
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
Esempio n. 8
0
        public async void DeleteNonExistingLocationReturnNotFound()
        {
            //A -arrange
            var mockRepo = new Mock <ILocationRepository>();

            mockRepo.Setup(repo => repo.GetByIdAsync(It.IsAny <long>()));
            mockRepo.Setup(repo => repo.Delete(It.IsAny <Location>()))
            .Verifiable();
            var controller = new LocationsController(mockRepo.Object);
            //A -act
            var result = await controller.Delete(69);

            //A -assert
            Assert.Equal((result as StatusCodeResult).StatusCode, 404);
            // TODO
            // mockRepo.Verify();
        }
Esempio n. 9
0
        public async void DeleteExistingLocationReturnNoContent()
        {
            //A -arrange
            var location1 = new Location();

            location1.ID = 1;
            var mockRepo = new Mock <ILocationRepository>();

            mockRepo.Setup(repo => repo.GetByIdAsync(It.IsAny <long>()))
            .Returns(Task.FromResult(location1));
            mockRepo.Setup(repo => repo.Delete(It.IsAny <Location>()))
            .Verifiable();
            var controller = new LocationsController(mockRepo.Object);
            //A -act
            var result = await controller.Delete(location1.ID);

            //A -assert
            Assert.Equal((result as StatusCodeResult).StatusCode, 204);
        }