public async void Update() { var mock = new ServiceMockFacade <IProductModelRepository>(); var model = new ApiProductModelRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductModel>())).Returns(Task.FromResult(new ProductModel())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).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.BOLProductModelIllustrationMapperMock, mock.DALMapperMockFactory.DALProductModelIllustrationMapperMock, mock.BOLMapperMockFactory.BOLProductModelProductDescriptionCultureMapperMock, mock.DALMapperMockFactory.DALProductModelProductDescriptionCultureMapperMock); UpdateResponse <ApiProductModelResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductModelModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiProductModelRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <ProductModel>())); }
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 Update_ProductMetricNull_ThrowsArgumentException() { //Arrange ProductModel invalidProductModel = new ProductModel { Id = 1, Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 4 }, ProductMetric = null, Price = 120, Products = null }; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Read(invalidProductModel.Id)). Returns(invalidProductModel); 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.Update(invalidProductModel); //Assert Assert.Throws <ArgumentException>(actual); }
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 Update_NameNull_ThrowsArgumentException() { //Arrange ProductModel invalidProductModel = new ProductModel { Id = 1, Name = null, 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.Update(invalidProductModel); //Assert Assert.Throws <ArgumentException>(actual); }
public void UpdateProductTest() { IDataContext <Product> dataContext = new TestDataContext(); IDataRepository dataRepository = new DataRepository(dataContext); ProductModelService product = new ProductModelService(new Product { Name = "Witaj" }); dataRepository.AddProduct(product); Assert.AreEqual(1, dataRepository.GetProducts().Count()); Assert.AreEqual("Witaj", dataRepository.GetProduct(1).Name); ProductModelService update = new ProductModelService(new Product { ProductID = 1, Name = "Test", MakeFlag = true }); dataRepository.UpdateProduct(update); Assert.AreEqual("Test", dataRepository.GetProduct(1).Name); Assert.AreEqual(true, dataRepository.GetProduct(1).MakeFlag); }
public void GetProductsTest() { IDataContext <Product> dataContext = new TestDataContext(); IDataRepository dataRepository = new DataRepository(dataContext); ProductModelService product = new ProductModelService(); Assert.AreEqual(0, dataRepository.GetProducts().Count()); dataContext.AddItem(product.CreateProduct()); Assert.AreEqual(1, dataRepository.GetProducts().Count()); }
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 AddProductTest() { IDataContext <Product> dataContext = new TestDataContext(); IDataRepository dataRepository = new DataRepository(dataContext); ProductModelService product = new ProductModelService(); Assert.AreEqual(0, dataContext.GetItems().Count()); dataRepository.AddProduct(product); Assert.AreEqual(1, dataContext.GetItems().Count()); Assert.AreEqual(1, dataContext.GetItems().First().ProductID); }
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 void DeleteProductTest() { IDataContext <Product> dataContext = new TestDataContext(); IDataRepository dataRepository = new DataRepository(dataContext); ProductModelService product = new ProductModelService(); dataRepository.AddProduct(product); Assert.AreEqual(1, dataRepository.GetProducts().Count()); ProductModelService delete = new ProductModelService(new Product { ProductID = 1 }); dataRepository.DeleteProduct(delete); Assert.AreEqual(0, dataRepository.GetProducts().Count()); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IProductModelRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ProductModel>(null)); 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); ApiProductModelResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ProductModelProductDescriptionCulturesByProductModelID_Not_Exists() { var mock = new ServiceMockFacade <IProductModelRepository>(); mock.RepositoryMock.Setup(x => x.ProductModelProductDescriptionCulturesByProductModelID(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ProductModelProductDescriptionCulture> >(new List <ProductModelProductDescriptionCulture>())); 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); List <ApiProductModelProductDescriptionCultureResponseModel> response = await service.ProductModelProductDescriptionCulturesByProductModelID(default(int)); response.Should().BeEmpty(); mock.RepositoryMock.Verify(x => x.ProductModelProductDescriptionCulturesByProductModelID(default(int), It.IsAny <int>(), It.IsAny <int>())); }
public void Update_IdNotExisting_ThrowsArgumentException() { //Arrange ProductModel nonExistingProductModel = new ProductModel { Id = 1, Name = "Rust In Peace Hoodie", ProductCategory = new ProductCategory { Id = 2 }, ProductMetric = new ProductMetric { Id = 4 }, Price = 130, Products = null }; ProductModel nullProductModel = null; Mock <IProductModelRepository> productModelRepository = new Mock <IProductModelRepository>(); productModelRepository.Setup(repo => repo.Read(nonExistingProductModel.Id)). Returns(nullProductModel); Mock <IProductCategoryRepository> productCategoryRepository = new Mock <IProductCategoryRepository>(); productCategoryRepository.Setup(repo => repo.Read(nonExistingProductModel.ProductCategory.Id)). Returns(nonExistingProductModel.ProductCategory); Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>(); productMetricRepository.Setup(repo => repo.Read(nonExistingProductModel.ProductMetric.Id)). Returns(nonExistingProductModel.ProductMetric); IProductModelService productModelService = new ProductModelService(productModelRepository.Object, productCategoryRepository.Object, productMetricRepository.Object); //Act Action actual = () => productModelService.Update(nonExistingProductModel); //Assert Assert.Throws <ArgumentException>(actual); }
public async void ByName_Exists() { var mock = new ServiceMockFacade <IProductModelRepository>(); var record = new ProductModel(); mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record)); 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); ApiProductModelResponseModel response = await service.ByName(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>())); }
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 All() { var mock = new ServiceMockFacade <IProductModelRepository>(); var records = new List <ProductModel>(); records.Add(new ProductModel()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); 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); List <ApiProductModelResponseModel> response = await service.All(); response.Should().HaveCount(1); mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
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>())); }
public async void ByCatalogDescription_Not_Exists() { var mock = new ServiceMockFacade <IProductModelRepository>(); mock.RepositoryMock.Setup(x => x.ByCatalogDescription(It.IsAny <string>())).Returns(Task.FromResult <List <ProductModel> >(new List <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.BOLProductModelIllustrationMapperMock, mock.DALMapperMockFactory.DALProductModelIllustrationMapperMock, mock.BOLMapperMockFactory.BOLProductModelProductDescriptionCultureMapperMock, mock.DALMapperMockFactory.DALProductModelProductDescriptionCultureMapperMock); List <ApiProductModelResponseModel> response = await service.ByCatalogDescription(default(string)); response.Should().BeEmpty(); mock.RepositoryMock.Verify(x => x.ByCatalogDescription(It.IsAny <string>())); }
public ProductModel() { ProductModelService = new ProductModelService(); }
public ProductModel(ProductModelService x) { ProductModelService = x; }