public void Create_IdSpecified_ThrowsArgumentException() { //Arrange ProductModel invalidProductModel = new ProductModel { Id = 1, Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 2 }, ProductMetric = new ProductMetric { Id = 4 }, Price = 130, Products = null }; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act Action actual = () => productModelService.Create(invalidProductModel); //Assert Assert.Throws <ArgumentException>(actual); }
public void Create_ProductMetricNull_ThrowsArgumentException() { //Arrange ProductModel invalidProductModel = new ProductModel { Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 4 }, ProductMetric = null, Price = 120, Products = null }; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); productCategoryRepository.Setup(repo => repo.Read(invalidProductModel.ProductCategory.Id)). Returns(invalidProductModel.ProductCategory); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act Action actual = () => productModelService.Create(invalidProductModel); //Assert Assert.Throws <ArgumentException>(actual); }
public void Create_ProductModelValid_ReturnsCreatedProductModelWithId() { //Arrange ProductModel validProductModel = new ProductModel { Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 2 }, ProductMetric = new ProductMetric { Id = 4 }, Price = 130, Products = null }; ProductModel expected = new ProductModel { Id = 1, Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 2 }, ProductMetric = new ProductMetric { Id = 4 }, Price = 130, Products = null }; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Create(validProductModel)). Returns(expected); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); productCategoryRepository.Setup(repo => repo.Read(validProductModel.ProductCategory.Id)). Returns(validProductModel.ProductCategory); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); productMetricRepository.Setup(repo => repo.Read(validProductModel.ProductMetric.Id)). Returns(validProductModel.ProductMetric); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act ProductModel actual = productModelService.Create(validProductModel); //Assert Assert.Equal(expected, actual); }
public void Create_ProductModelNull_ThrowsArgumentNullException() { //Arrange ProductModel invalidProductModel = null; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act Action actual = () => productModelService.Create(invalidProductModel); //Assert Assert.Throws <ArgumentNullException>(actual); }
public async void Create() { var mock = new ServiceMockFacade <IProductModelRepository>(); var model = new ApiProductModelRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductModel>())).Returns(Task.FromResult(new ProductModel())); 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); CreateResponse <ApiProductModelResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductModelModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductModelRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductModel>())); }