Exemple #1
0
        public void CreateShouldCreateSupplierAndIsDefaultShouldStayFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateIsDefaultFalse_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            dbContext.Suppliers.Add(new Supplier {
                Name = "Econt", IsDefault = true
            });
            dbContext.SaveChanges();

            var name          = "DHL";
            var priceToHome   = 5.5M;
            var priceToOffice = 4.5M;

            suppliersService.Create(name, priceToHome, priceToOffice);

            var supplier = dbContext.Suppliers.FirstOrDefault(x => x.Name == name);

            Assert.NotNull(supplier);
            Assert.Equal(name, supplier.Name);
            Assert.Equal(priceToHome, supplier.PriceToHome);
            Assert.Equal(priceToOffice, supplier.PriceToOffice);
            Assert.False(supplier.IsDefault);
        }
 public IActionResult Create([FromBody] SuppliersDTO suppliersDTO)
 {
     if (!suppliersDTO.isValid())
     {
         return(BadRequest());
     }
     if (suppliersService.Create(suppliersDTO))
     {
         return(NoContent());
     }
     return(BadRequest());
 }
Exemple #3
0
        public void CreateShouldCreateSupplierAndAddToDb()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var supplierService = new SuppliersService(dbContext);

            supplierService.Create("Speedy", 5, 4);

            var isSupplierIsCreate = dbContext.Suppliers.ToList();

            Assert.True(isSupplierIsCreate.Count == 1);
        }
Exemple #4
0
        public void CreateShouldCreateSupplierAndMakeDefaultTrue()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Create_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            var name          = "DHL";
            var priceToHome   = 5.5M;
            var priceToOffice = 4.5M;

            suppliersService.Create(name, priceToHome, priceToOffice);

            var supplier = dbContext.Suppliers.FirstOrDefault(x => x.Name == name);

            Assert.NotNull(supplier);
            Assert.Equal(name, supplier.Name);
            Assert.Equal(priceToHome, supplier.PriceToHome);
            Assert.Equal(priceToOffice, supplier.PriceToOffice);
            Assert.True(supplier.IsDefault);
        }