public void Setup() { #region Mock DbContext DbContext = new Mock <ProductContext>("test-connection-string"); var productDataSet = new List <Product>() { DataHelper.Prodcut_IPhone, DataHelper.Product_SamsungPhone }; DbContext.Setup(a => a.Set <Product>()).Returns(base.GetMockDbSet <Product>(productDataSet)); DbContext.Setup(a => a.Set <ProductOption>()).Returns(base.GetMockDbSet <ProductOption>(DataHelper.Option_DataSet.ToList())); #endregion #region Mock DbFactory DbFactory = new Mock <IDbFactory>(); DbFactory.Setup(a => a.GetDbContext()) .Returns(DbContext.Object); #endregion UnitOfWork = new UnitOfWork(DbFactory.Object); ProductRepository = new ProductRepository(DbFactory.Object); ProductOptionRepository = new ProductOptionRepository(DbFactory.Object); _productService = new ProductService(base.ProductRepository, base.ProductOptionRepository, base.UnitOfWork); }
public void SetUp() { var productOptionRepository = new ProductOptionRepository(); var productRepository = new ProductRepository(productOptionRepository); _productsController = new ProductsController(productRepository, productOptionRepository); _productOptionIds = new List <Guid>(); }
public void GetByProductIdTest() { ProductOptionRepository repo = new ProductOptionRepository(); List <ProductOption> options = repo.GetByProductID(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3")); Assert.AreEqual(2, options.Count); }
public void GetByIdFailureTest() { ProductOptionRepository repo = new ProductOptionRepository(); ProductOption test = repo.GetByID(Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")); Assert.IsNull(test); }
public void GetByIdTest() { ProductOptionRepository repo = new ProductOptionRepository(); ProductOption test = repo.GetByID(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9")); Assert.AreEqual("White", test.Name); Assert.AreEqual("White Samsung Galaxy S7", test.Description); Assert.AreEqual(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), test.ProductId); }
public void ProductOptionRepositoryGetAllTest() { //Arrange using (ProductOptionRepository productOptionRepository = new ProductOptionRepository()) { //Action IQueryable <ProductOption> queryable = productOptionRepository.GetAll(); //Assert Assert.IsNotNull(queryable); } }
public void TestGetProductOptionByProductIdNotFound() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); var p = productOptionRepository.GetProductOptionsByProductId(new Guid()); p.Result.Should().BeEmpty(); context.Database.EnsureDeleted(); } }
public void ProductOptionRepositoryTest() { //Arrange DBUtil.InitDB(); //Action using (ProductOptionRepository productOptionRepository = new ProductOptionRepository()) { //Assert Assert.IsNotNull(productOptionRepository); } }
public void TestGetProductOptionByIdNotFound() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); ProductOption po = productOptionRepository.GetById(new Guid()); po.Should().BeNull(); context.Database.EnsureDeleted(); } }
public void TestDeleteProductOptionOK() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); productOptionRepository.DeleteAsync(productOptions[0]); var currentProductOptions = productOptionRepository.GetProductOptions(); currentProductOptions.Result.Should().BeEmpty(); context.Database.EnsureDeleted(); } }
public void Delete_deletes_a_ProductOption_via_context() { //Arrange var repository = new ProductOptionRepository(_mapper, _mockContext,_logging); //Act repository.Delete(new Guid("a21d5777-a655-4020-b431-624bb331e9a2")); var productOptions = repository.GetAll(); //Assert Assert.IsNotNull(productOptions); Assert.AreEqual(productOptions.Count(),2); }
public void GetById_gets_a_ProductOption_via_context() { //Arrange var repository = new ProductOptionRepository(_mapper, _mockContext,_logging); //Act var productOption = repository.GetById(new Guid("0643ccf0-ab00-4862-b3c5-40e2731abcc9")); //Assert Assert.IsNotNull(productOption); Assert.AreEqual(productOption.Name, "White"); }
public void ProductOptionRepositoryGetOneTest() { //Arrange Guid guid = new Guid("0643ccf0-ab00-4862-b3c5-40e2731abcc9"); using (ProductOptionRepository productOptionRepository = new ProductOptionRepository()) { //Action ProductOption productOption = productOptionRepository.GetOne(guid); //Assert Assert.IsNotNull(productOption); } }
public void GetByAll_gets_all_ProductOptions_via_context() { //Arrange var repository = new ProductOptionRepository(_mapper, _mockContext,_logging); //Act var productOptions = repository.GetAll().ToList(); //Assert Assert.IsNotNull(productOptions); Assert.AreEqual(productOptions.Count,3); }
public void Create_saves_a_ProductOption_via_context() { //Arrange var repository = new ProductOptionRepository(_mapper, _mockContext,_logging); var productOption = new core.Models.ProductOption { Id = new Guid(), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Rose Gold", Description = "Gold Apple iPhone 6S" }; //Act repository.Create(productOption); var count = _mockContext.ProductOptions.Local.Count; //Assert Assert.AreEqual(count, 4); }
public void TestGetProductOptionByIdOK() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); ProductOption po = productOptionRepository.GetById(productOptions[0].Id); po.Should().NotBeNull(); po.Id.Should().Equals(productOptions[0].Id); po.Name.Should().Equals(productOptions[0].Name); po.Description.Should().Equals(productOptions[0].Description); po.ProductId.Should().Equals(productOptions[0].ProductId); context.Database.EnsureDeleted(); } }
public void Update_update_specified_ProductOption_via_context() { //Arrange var repository = new ProductOptionRepository(_mapper, _mockContext,_logging); var productOptionToUpdate = new core.Models.ProductOption { Id = new Guid("5c2996ab-54ad-4999-92d2-89245682d534"), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Rose Gold Test Mock", Description = "Gold Apple iPhone 6S" }; //Act repository.Update(productOptionToUpdate); var updatedProductOption = repository.GetById(new Guid("5c2996ab-54ad-4999-92d2-89245682d534")); //Assert Assert.IsNotNull(updatedProductOption); Assert.AreEqual(updatedProductOption.Name, "Rose Gold Test Mock"); Assert.AreEqual(updatedProductOption.Name, productOptionToUpdate.Name); }
/// <summary> /// The product option repository re index. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The product keys. /// </param> /// <remarks> /// REFACTOR v3 /// </remarks> private void ProductOptionRepositoryReIndex(ProductOptionRepository sender, Core.Events.ObjectEventArgs <IEnumerable <Guid> > e) { var keys = e.EventObject; if (MerchelloContext.HasCurrent) { var products = MerchelloContext.Current.Services.ProductService.GetByKeys(keys).ToArray(); var contentCache = new VirtualProductContentCache(); foreach (var p in products) { IndexProduct(p); // we also need to refresh the published product cache contentCache.ClearVirtualCache(p); } } }
public void TestInitialize() { // Initialize database connection factory var connectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString; _dbConnectionFactory = new DbConnectionFactory(connectionString); // initialize repositories var productOptionRepository = new ProductOptionRepository(_dbConnectionFactory); var productRepository = new ProductRepository(_dbConnectionFactory, productOptionRepository); // initialize controllers _productController = new ProductsController(productRepository); _productOptionController = new ProductOptionsController(productOptionRepository); InitializeDatabase(); }
public void ProductOptionRepositoryDeleteByEntityTest() { //Arrange ProductOption productOption = new ProductOption { Id = new Guid("a21d5777-a655-4020-b431-624bb331e9a2"), ProductId = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "HUAWEI", Description = "HUAWEI HONOR Updated" }; //Action using (ProductOptionRepository productOptionRepository = new ProductOptionRepository()) { //Assert Assert.AreEqual(1, productOptionRepository.Delete(productOption)); } }
public void ProductOptionRepositoryAddTest() { //Arrange ProductOption productOption = new ProductOption { Id = Guid.NewGuid(), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "New Color", Description = "New Color Apple", }; //Action using (ProductOptionRepository productOptionRepository = new ProductOptionRepository()) { //Assert Assert.AreEqual(1, productOptionRepository.Add(productOption)); } }
public void ProductOptionRepositoryUpdateTest() { //Arrange ProductOption productOption = new ProductOption { Id = new Guid("0643ccf0-ab00-4862-b3c5-40e2731abcc9"), ProductId = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "HUAWEI", Description = "HUAWEI HONOR Updated" }; //Action using (ProductOptionRepository productOptionRepository = new ProductOptionRepository()) { //Assert Assert.AreEqual(1, productOptionRepository.Update(productOption.Id, productOption)); } }
public void TestAddProductOptionFail() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductRepository productRepository = new ProductRepository(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); ProductsController productController = new ProductsController(productRepository, productOptionRepository); Func <Task> act = async() => await productController.AddProductOptionsForProdId(new ProductOptionDto { Id = productOptions[0].Id }); act.Should().Throw <HttpResponseException>(); context.Database.EnsureDeleted(); } }
public void TestUpdateProductOptionOK() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); productOptions[0].Name = "Test Update Product Option"; productOptions[0].Description = "Test Update product option"; productOptionRepository.AddOrUpdateAsync(productOptions[0], false); var currentProductOptions = productOptionRepository.GetProductOptions(); currentProductOptions.Result.Count.Should().Be(1); currentProductOptions.Result[0].Name.Should().Equals("Test Update Product Option"); currentProductOptions.Result[0].Description.Should().Equals("Test Update product option"); context.Database.EnsureDeleted(); } }
public void TestGetProductOptionByProductIdOK() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); var po = productOptionRepository.GetProductOptionsByProductId(products[0].Id); po.Result.Should().NotBeEmpty(); po.Result.Should().HaveCount(1); ProductOption prodOpt = po.Result[0]; prodOpt.Id.Should().Equals(productOptions[0].Id); prodOpt.Name.Should().Equals(productOptions[0].Name); prodOpt.Description.Should().Equals(productOptions[0].Description); prodOpt.ProductId.Should().Equals(products[0].Id); context.Database.EnsureDeleted(); } }
public void Initialize() { //Arrange for Tests var mapperConfig = new MapperConfiguration(cnfig => { cnfig.AddProfile(new RepositoryMapper()); }); _mapper = mapperConfig.CreateMapper(); _mockContext = new FakeDatabaseEntitiesContext { Products = { new data.Product { Id = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "Samsung Galaxy S7", Description = "Newest mobile product from Samsung.", Price = 1024.99M, DeliveryPrice = 16.99M }, new data.Product { Id = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Apple iPhone 6S", Description = "Newest mobile product from Apple.", Price = 1299.99M, DeliveryPrice = 15.99M } }, ProductOptions = { new data.ProductOption { Id = new Guid("0643ccf0-ab00-4862-b3c5-40e2731abcc9"), ProductId = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "White", Description = "White Samsung Galaxy S7" }, new data.ProductOption { Id = new Guid("a21d5777-a655-4020-b431-624bb331e9a2"), ProductId = new Guid("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), Name = "Black", Description = "Black Samsung Galaxy S7" }, new data.ProductOption { Id = new Guid("5c2996ab-54ad-4999-92d2-89245682d534"), ProductId = new Guid("de1287c0-4b15-4a7b-9d8a-dd21b3cafec3"), Name = "Rose Gold", Description = "Gold Apple iPhone 6S" } } }; _logging = new LoggingService(); var productOptionRepository = new ProductOptionRepository(_mapper, _mockContext, _logging); var productRepository = new ProductRepository(_mapper, _mockContext, _logging); var productOptionService = new ProductOptionService(productOptionRepository); var productService = new ProductService(productRepository); _Controller = new ProductsController(productService, productOptionService, _logging); }
public void UpdateTest() { ProductOptionRepository repo = new ProductOptionRepository(); ProductOption test = repo.GetByID(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9")); string description = test.Description; test.Description = "This has been changed by a unit test"; repo.Update(test); ProductOption postUpdate = repo.GetByID(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9")); Assert.AreEqual(test.Description, postUpdate.Description); postUpdate.Description = description; repo.Update(postUpdate); }
public void TestAddProductOptionOK() { using (var context = new ProductDbContext(builder.Options)) { SetUpTestData(context); IProductOptionRepository productOptionRepository = new ProductOptionRepository(context); ProductOption p = new ProductOption { Id = new Guid(), ProductId = products[0].Id, Name = "Test add Product Option 2", Description = "Test add product option" }; productOptionRepository.AddOrUpdateAsync(p, true); var currentProductOptions = productOptionRepository.GetProductOptions(); currentProductOptions.Result.Count.Should().Be(2); p.ProductId.Should().Equals(currentProductOptions.Result[1].ProductId); p.Name.Should().Equals(currentProductOptions.Result[1].Name); context.Database.EnsureDeleted(); } }
public void InsertAndDeleteTest() { ProductOptionRepository repo = new ProductOptionRepository(); Guid id = new Guid(); ProductOption test = new ProductOption(id, Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), "TestProductOption", "This is a unit test created product option"); repo.Insert(test); ProductOption postInsert = repo.GetByID(id); Assert.AreEqual(test.Id, postInsert.Id); Assert.AreEqual(test.ProductId, postInsert.ProductId); Assert.AreEqual(test.Name, postInsert.Name); Assert.AreEqual(test.Description, postInsert.Description); repo.Delete(postInsert); ProductOption postDelete = repo.GetByID(id); Assert.IsNull(postDelete); }
protected ProductsController EstablishEnvironment() { // Establish the environment var baseDir = System.IO.Directory.GetCurrentDirectory(); var configuration = new ConfigurationBuilder() .SetBasePath(System.IO.Directory.GetCurrentDirectory()) .AddInMemoryCollection(new[] { new KeyValuePair <string, string>("ConnectionString", "Data Source=../../../TestDatabase/products.db") }) .Build(); ProductMicroservice.API.Mappers.DapperMappers.Config(); var productRepository = new ProductRepository(configuration); var productOptionRepository = new ProductOptionRepository(configuration); var productService = new ProductService(new ProductValidator(), productRepository, productOptionRepository); var logger = new Mock <ILogger <ProductsController> >(); var controller = new ProductsController(productService, logger.Object); return(controller); }