public void Delete_IdExisting_ReturnsDeletedProductModelWithSpecifiedId() { //Arrange int existingId = 12; ProductModel expected = new ProductModel { Id = existingId, Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 2 }, ProductMetric = new ProductMetric { Id = 4 }, Price = 120, Products = null }; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Delete(existingId)). Returns(expected); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act ProductModel actual = productModelService.Delete(existingId); //Assert Assert.Equal(expected, actual); }
public void Delete_IdNonExisting_ReturnsNull() { //Arrange int existingId = 12; ProductModel expected = null; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Delete(existingId)). Returns(expected); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act ProductModel actual = productModelService.Delete(existingId); //Assert Assert.Equal(expected, actual); }
public async void Delete() { var mock = new ServiceMockFacade <IProductModelRepository>(); var model = new ApiProductModelRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ProductModelService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductModelModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductModelMapperMock, mock.DALMapperMockFactory.DALProductModelMapperMock, mock.BOLMapperMockFactory.BOLProductMapperMock, mock.DALMapperMockFactory.DALProductMapperMock, mock.BOLMapperMockFactory.BOLProductModelProductDescriptionCultureMapperMock, mock.DALMapperMockFactory.DALProductModelProductDescriptionCultureMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ProductModelModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }