Exemple #1
0
 /// <summary>
 /// 创建一个供应商信息
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个供应商信息</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, Supplier entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
        public void Create_WithValidEntity_ShouldCreateDatabaseRecord()
        {
            var options = ConnectionOptionHelper.Sqlite();
            // Arrange
            var supplier = new Supplier
            {
                Name        = "Shoes Supplier",
                Description = "This is a Shoes Supplier",
                IsActive    = true
            };

            using (var context = new ECommerceDbContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();
                var sut = new SupplierRepository(context);

                // Act
                sut.Create(supplier);
            }
            using (var context = new ECommerceDbContext(options))
            {
                // Assert
                var actual = context.Suppliers.Find(supplier.ID);

                Assert.NotNull(actual);
                Assert.Equal(supplier.Name, actual.Name);
                Assert.Equal(supplier.Description, actual.Description);
            }
        }
Exemple #3
0
        public ActionResult Create(Supplier form)
        {
            if (Request.Form.Count > 0)
            {
                //Supplier newsupplier = new Supplier();
                //newsupplier.SupplierID = Convert.ToInt32(Request.Form["SupplierID"]);
                //newsupplier.SupplierName = Request.Form["SupplierName"];
                //newsupplier.Phone = Request.Form["Phone"];
                //newsupplier.Fax = Request.Form["Fax"];
                //newsupplier.Email = Request.Form["Email"];
                //newsupplier.Address = Request.Form["Address"];
                //newsupplier.CreateDate = Convert.ToDateTime(Request.Form["CreateDate"]);

                //repository.Creat(newsupplier);

                //return RedirectToAction("Index");

                //Supplier ViewBag = new Supplier();
                //ViewBag.SupplierID = form.SupplierID;
                //ViewBag.SupplierName = form.SupplierName;
                //ViewBag.Phone = form.Phone;
                //ViewBag.Fax = form.Fax;
                //ViewBag.Email = form.Email;
                //ViewBag.Address = form.Address;
                //ViewBag.CreateDate = DateTime.Now;
                form.CreateDate = DateTime.Now;
                repository.Create(form);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemple #4
0
        public void Retrieve_WithSkipAndCount_ShouldReturnTheCorrectRecords()
        {
            // Arrange
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (var i = 1; i <= 10; i += 1)
            {
                sut.Create(new Supplier
                {
                    Name        = string.Format("Supplier {0}", i),
                    Description = string.Format("Supplier Description {0}.", i),
                    IsActive    = true
                });
            }

            // Act
            var list = sut.Retrieve(0, 5);

            // Assert
            Assert.True(list.Count() == 5);

            // Cleanup
            list = context.Suppliers.ToList();
            foreach (var item in list)
            {
                sut.Delete(item.ID);
            }
        }
        public void Retrieve_WithSkipAndCount_ShouldReturnValidList()
        {
            //Arrange
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (var i = 1; i <= 20; i += 1)
            {
                sut.Create(new Supplier {
                    Name        = string.Format("Supplier {0}", i),
                    Description = string.Format("Description {0}", i),
                    IsActive    = true
                });
            }

            //Act
            var list = sut.Retrieve(5, 5);

            //Assert
            Assert.True(list.Count() == 5);

            //Cleanup
            list = sut.Retrieve(0, int.MaxValue).ToList();
            foreach (var entity in list)
            {
                sut.Delete(entity.ID);
            }
        }
Exemple #6
0
        public void Retrieve_ValidData_ShouldWork()
        {
            var      context             = new ECommerceDbContext();
            var      sut                 = new SupplierRepository(context);
            string   expectedName        = "Yakult Inc.";
            string   expectedDescription = "Lactobacillus Protectus";
            bool     expectedIsActive    = false;
            Supplier supplier            = new Supplier
            {
                Name        = expectedName,
                Description = expectedDescription,
                IsActive    = expectedIsActive
            };

            sut.Create(supplier);
            //Act
            var result = sut.Retrieve(supplier.ID);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(result.Name, expectedName);
            Assert.Equal(result.Description, expectedDescription);
            Assert.Equal(result.IsActive, expectedIsActive);
            //Cleanup
            sut.Delete(result.ID);
        }
Exemple #7
0
        public void Retrieve_WithSkipAndCount_ReturnsTheCorrectPage()
        {
            //Arrange
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (int i = 0; i < 20; i += 1)
            {
                sut.Create(new Supplier
                {
                    Name        = string.Format("Supplier No. {0}", i),
                    Description = string.Format("Description No. {0}", i),
                    IsActive    = true
                });
            }
            //Act
            var actual = sut.Retrieve(4, 3);

            //Assert
            Assert.True(actual.Count() == 3);
            //Cleanup
            var list = sut.Retrieve(0, Int32.MaxValue);

            foreach (var item in list)
            {
                sut.Delete(item.ID);
            }
        }
Exemple #8
0
        public void Update_WithValidData_ShouldWork()
        {
            var      context             = new ECommerceDbContext();
            var      sut                 = new SupplierRepository(context);
            string   expectedName        = "Yakult Inc.";
            string   expectedDescription = "Lactobacillus Protectus";
            bool     expectedIsActive    = false;
            Supplier supplier            = new Supplier
            {
                Name        = "Jakult inc.",
                Description = "Lactobacillus Aysus",
                IsActive    = true
            };

            sut.Create(supplier);
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            actual.Name        = expectedName;
            actual.Description = expectedDescription;
            actual.IsActive    = expectedIsActive;
            sut.Update(actual.ID, actual);
            //Cleanup
            sut.Delete(actual.ID);
        }
Exemple #9
0
        public void Update_WithValidProperty_ShouldUpdateEntity()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Blast Asia",
                Description = "Software Supplier",
                IsActive    = true
            };

            sut.Create(supplier);
            var expected = sut.Retrieve(supplier.ID);

            //Act
            expected.Name        = "Blaster";
            expected.Description = "Software Engineer Supplier";
            sut.Update(supplier.ID, expected);
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            Assert.Equal(actual, expected);

            //Cleanup
            sut.Delete(supplier.ID);
        }
Exemple #10
0
        public void Retrieve_WithSkipAndCount_Work()
        {
            var context = new ECommerceDbContext();
            var sut     = new SupplierRepository(context);

            for (int i = 0; i < 30; i += 1)
            {
                Supplier supplier = new Supplier
                {
                    Name        = String.Format("Name {0}", i),
                    Description = String.Format("Description {0}", i),
                    IsActive    = true
                };
                sut.Create(supplier);
            }
            var list = sut.Retrieve(3, 3);

            Assert.True(3 == list.Count());//Pano machecheck kung na skip yung unang tatlo

            //Cleanup
            var listToBeDeleted = sut.Retrieve(0, Int32.MaxValue);

            foreach (Supplier supplier in listToBeDeleted)
            {
                sut.Delete(supplier.ID);
            }
        }
Exemple #11
0
        public IHttpActionResult Post(Supplier supplier)
        {
            var CreateSupplier = supplierRepository.Create(supplier);

            if (CreateSupplier == 0)
            {
                return(NotFound());
            }
            return(Ok("data has been inputted"));
        }
 // Create
 public IHttpActionResult Post(Supplier supplier)
 {
     if (supplier.Name == null || supplier.Name.Length <= 6)
     {
         return(BadRequest("- Tidak boleh kosong dan Masukkan 6-50 Karakter (Huruf atau Angka)"));
     }
     supplierRepository.Create(supplier);
     return(Ok("Data sudah masuk!"));
     // Delete
 }
Exemple #13
0
        public IHttpActionResult Post(Supplier supplier)
        {
            var result = supplierRepository.Create(supplier);

            if (result == 0)
            {
                return(Content(HttpStatusCode.InternalServerError, "Terjadi Kesalahan"));
            }
            return(Ok("Berhasil Create"));
        }
Exemple #14
0
        public IHttpActionResult Post(Supplier supplier)
        {
            var create = sp.Create(supplier);

            if (create > 0)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Exemple #15
0
 public IHttpActionResult Post(Supplier supplier)
 {
     if (repository.Create(supplier) == 1)
     {
         return(Ok("Supplier data has been saved"));
     }
     else
     {
         return(BadRequest("Supplier data cannot be stored"));
     }
 }
 public int Create(SupplierVM supplierVM)
 {
     if (string.IsNullOrWhiteSpace(supplierVM.Name) || (string.IsNullOrWhiteSpace(supplierVM.Email)))
     {
         return(0);
     }
     else
     {
         return(_supplierRepository.Create(supplierVM));
     }
 }
 public IHttpActionResult Post(Supplier s)
 {
     sr.Create(s);
     try
     {
         return(Ok());
     }
     catch
     {
         //return Content(HttpStatusCode.BadRequest, "Failed to Create Supplier");
         return(BadRequest("Failed to Create Supplier"));
     }
 }
Exemple #18
0
        public IHttpActionResult Post(Suppliers supplier)
        {
            var result = supplierRepository.Create(supplier);

            if (result == 0)
            {
                var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content    = new StringContent("Terjadi Kesalahan", System.Text.Encoding.UTF8, "text/plain"),
                    StatusCode = HttpStatusCode.BadRequest
                };
                throw new HttpResponseException(response);
            }

            return(Ok());
        }
Exemple #19
0
        public void Create_WithValidEntity_ShouldCreateRecord()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Blast Asia",
                Description = "Software Supplier",
                IsActive    = true
            };


            //Act
            sut.Create(supplier);
            //Assert
            Assert.True(supplier.ID != 0);
            //Cleanup
            sut.Delete(supplier.ID);
        }
Exemple #20
0
        public void Retrive_WithNonExistingID_ShouldReturnsNull()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Blast Asia",
                Description = "Software Description",
                IsActive    = true
            };

            sut.Create(supplier);
            Assert.True(supplier.ID != 0);
            sut.Delete(supplier.ID);
            //Act
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            Assert.Null(actual);
        }
Exemple #21
0
        public void Delete_WithValidID_ShouldRemoveEntity()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Blast Asia",
                Description = "Software Supplier",
                IsActive    = true
            };

            sut.Create(supplier);
            Assert.True(supplier.ID != 0);
            //Act
            sut.Delete(supplier.ID);

            //Assert
            var actual = sut.Retrieve(supplier.ID);

            Assert.Null(actual);
        }
Exemple #22
0
        public void Retrieve_WithValidID_ReturnsValidEntity()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier
            {
                Name        = "Blast Asia",
                Description = "Software Supplier",
                IsActive    = true
            };

            sut.Create(supplier);
            //Act
            var actual = sut.Retrieve(supplier.ID);

            //Assert
            Assert.NotNull(actual);
            Assert.True(actual.Equals(supplier));

            //Cleanup
            sut.Delete(supplier.ID);
        }
Exemple #23
0
        public void Create_WithValidInformation_Works()
        {
            //Arrage
            var      context  = new ECommerceDbContext();
            var      sut      = new SupplierRepository(context);
            Supplier supplier = new Supplier
            {
                Name        = "Yakult Inc.",
                Description = "Lactobacillus Protectus",
                IsActive    = false
            };

            //Act
            sut.Create(supplier);
            var result = sut.Retrieve(supplier.ID);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(result.Name, supplier.Name);
            Assert.Equal(result.Description, supplier.Description);
            //Cleanup
            sut.Delete(result.ID);
        }
Exemple #24
0
        public void Delete_Works()
        {
            //Arrage
            var      context  = new ECommerceDbContext();
            var      sut      = new SupplierRepository(context);
            Supplier supplier = new Supplier
            {
                Name        = "Yakult Inc.",
                Description = "Lactobacillus Protectus",
                IsActive    = false
            };

            sut.Create(supplier);
            var result = sut.Retrieve(supplier.ID);

            Assert.NotNull(result);
            //Act
            sut.Delete(result.ID);
            //Assert
            var newResult = sut.Retrieve(result.ID);

            Assert.Null(newResult);
        }
Exemple #25
0
        public void Retrieve_WithValidEntityID_ShouldReturnAValidSupplier()
        {
            // Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier()
            {
                Name        = "Converse",
                Description = "Converse supplier",
                IsActive    = true
            };

            sut.Create(supplier);

            // Act
            var actual = sut.Retrieve(supplier.ID);

            // Assert
            Assert.NotNull(actual);

            // Cleanup
            sut.Delete(supplier.ID);
        }
Exemple #26
0
        public void Create_WithValidEntity_ShouldCreateDatabaseRecord()
        {
            // Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier()
            {
                Name        = "Converse",
                Description = "Converse supplier",
                IsActive    = true
            };

            // Act
            sut.Create(supplier);

            // Assert
            var result = sut.Retrieve(supplier.ID);

            Assert.NotNull(result);

            // Cleanup
            sut.Delete(result.ID);
        }
        public void GetAllSupplier()
        {
            SupplierRepository repository = new SupplierRepository();

            Supplier supplier = new Supplier()
            {
                CompanyName = "Compañia 1",
                Contact     = new Contact()
                {
                    ContactName  = "contacto 1",
                    ContactTitle = "Sr",
                    Fax          = "111-111111",
                    Phone        = "237616"
                }
            };

            repository.Create(supplier);

            var supplierList = repository.GetAll();

            Assert.AreEqual(supplierList.Count, 1);
            Assert.IsTrue(supplierList[0].Contact != null);
        }
        public void Create_WithValidEntity_ShouldSaveInDatabase()
        {
            //Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier {
                Name        = "Melrose Mejidana",
                Description = "Shoe Supplier",
                IsActive    = true
            };

            //Act
            sut.Create(supplier);

            //Assert
            Assert.True(supplier.ID != 0);

            var actual = sut.Retrieve(supplier.ID);

            Assert.NotNull(actual);

            //Clenup
            sut.Delete(supplier.ID);
        }
Exemple #29
0
        public void Update_WithValidEntity_ShouldUpdateDatabaseRecord()
        {
            // Arrange
            var context  = new ECommerceDbContext();
            var sut      = new SupplierRepository(context);
            var supplier = new Supplier()
            {
                Name        = "Converse",
                Description = "Converse supplier",
                IsActive    = true
            };

            sut.Create(supplier);

            var expectedName        = "Nike";
            var expectedDescription = "Nike supplier";

            supplier.Name        = expectedName;
            supplier.Description = expectedDescription;

            // Act
            sut.Update(supplier.ID, supplier);
            var actual = sut.Retrieve(supplier.ID);

            // Assert
            Assert.Equal(expectedName, actual.Name);
            Assert.Equal(expectedDescription, actual.Description);

            // Cleanup
            //var list = context.Suppliers.ToList();
            //foreach (var item in list)
            //{
            //    sut.Delete(item.ID);
            //}
            sut.Delete(supplier.ID);
        }
 public void Create(Supplier supplier)
 {
     supplierRepo.Create(supplier);
 }