コード例 #1
0
        public void Should_AddVenue()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                Venue venue = new Venue
                {
                    Address1     = "Addr1",
                    Address2     = "Addr2",
                    Address3     = "Addr3",
                    Address4     = "Addr4",
                    Address5     = "Addr5",
                    ContactPhone = "01234567898",
                    Description  = "Test",
                    Name         = "Test",
                    Facilities   = FacilityFlags.Bar,
                    Image        = "",
                    Facebook     = "fb",
                    Twitter      = "tw",
                    Instagram    = "inst",
                    LatLong      = "0,0",
                    Website      = "www"
                };

                var  entity  = new DbRepository <Venue>(context);
                bool created = entity.Create(venue);
                Assert.True(created);
            }
        }
コード例 #2
0
        public void SaveCartDB(int productId, int customerId, int quantity, string color, string size)
        {
            db = new DBModel();

            DbRepository <Cart> repor = new DbRepository <Cart>(db);

            var productDetail = db.Product_Detail.Where(x => x.Color == color && x.Size == size && x.Product_Id == productId).FirstOrDefault();

            var value = db.Cart.Where(x => x.Customer_ID == customerId && x.Product_Detail_Id == productDetail.Product_Detail_Id).FirstOrDefault();

            if (value != null)
            {
                var result = db.Cart.SingleOrDefault(x => x.Product_Detail_Id == productDetail.Product_Detail_Id && x.Customer_ID == customerId);
                result.Quantity += quantity;
                db.SaveChanges();
                return;
            }


            _carts = new Cart()
            {
                Product_Detail_Id = productDetail.Product_Detail_Id,
                Customer_ID       = customerId,
                Quantity          = quantity
            };
            repor.Create(_carts);
            db.SaveChanges();
        }
コード例 #3
0
ファイル: DbRepositoryTests.cs プロジェクト: Yura95st/DBMS
        public void Create_DatabaseIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            IDbRepository target = new DbRepository(this._dbRepositorySettings);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => target.Create(null));
        }
コード例 #4
0
        public void Should_AddRoom()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                Room room = new Room {
                    Name = "Test", Description = "Test", VenueId = 1, Rows = 10, Columns = 10, Isles = "{}"
                };

                var  entity  = new DbRepository <Room>(context);
                bool created = entity.Create(room);
                Assert.True(created);
            }
        }
コード例 #5
0
ファイル: DbRepositoryTests.cs プロジェクト: Yura95st/DBMS
        public void Create_DatabaseWithSuchNameAlreadyExists_ThrowsDbRepositoryException()
        {
            // Arrange
            Database database = new Database {
                Name = this._testDb.Name
            };

            // Arrange - create target
            IDbRepository target = new DbRepository(this._dbRepositorySettings);

            // Act and Assert
            Assert.Throws <DbRepositoryException>(() => target.Create(database));
        }
コード例 #6
0
        public void Should_AddEvent()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                Event @event = new Event {
                    Name = "Test Event", Description = "Test Description", AgeRating = AgeRatingType.PEGI_12, Image = "", Duration = 120
                };

                var  entity  = new DbRepository <Event>(context);
                bool created = entity.Create(@event);
                Assert.True(created);
            }
        }
コード例 #7
0
        public void Should_AddBooking()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                Booking booking = new Booking {
                    CustomerId = 1, ShowingId = 1, Status = 0, BookedDate = DateTime.Now
                };

                var  entity  = new DbRepository <Booking>(context);
                bool created = entity.Create(booking);
                Assert.True(created);
            }
        }
コード例 #8
0
        public void Should_AddShowing()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                Showing showing = new Showing {
                    EventId = 1, RoomId = 2, StartTime = DateTime.Now, EndTime = DateTime.Now.AddHours(1), PricingStrategyId = 1
                };

                var  entity  = new DbRepository <Showing>(context);
                bool created = entity.Create(showing);
                Assert.True(created);
            }
        }
コード例 #9
0
        public void Should_AddFeature()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                Feature feature = new Feature {
                    Name = "Test Feature", Title = "Test Title", Detail = "Test Detail", Link = "Test Link", Image = "Image Data", Order = 1
                };

                var  entity  = new DbRepository <Feature>(context);
                bool created = entity.Create(feature);
                Assert.True(created);
            }
        }
コード例 #10
0
        public void Should_AddBookingItem()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                BookingItem BookingItem = new BookingItem {
                    BookingId = 1, AgreedPriceName = "Adult Test", AgreedPrice = 1f, Location = 24
                };

                var  entity  = new DbRepository <BookingItem>(context);
                bool created = entity.Create(BookingItem);
                Assert.True(created);
            }
        }
コード例 #11
0
        public void Should_AddPricingStrategyItem()
        {
            using (ApplicationDbContext context = SeedContext())
            {
                PricingStrategyItem pricingStrategyItem = new PricingStrategyItem {
                    Name = "Test", Description = "Test", Price = 1, PricingStrategyId = 1
                };

                var  entity  = new DbRepository <PricingStrategyItem>(context);
                bool created = entity.Create(pricingStrategyItem);
                Assert.True(created);
            }
        }
コード例 #12
0
        //API Create Product
        public bool CreatePorduct(Product pvm)
        {
            DBModel contex = new DBModel();
            DbRepository <Product> repo = new DbRepository <Product>(contex);
            string filename             = pvm.Product_Image;

            //FileUpload

            try {
                repo.Create(pvm);
                return(true);
            } catch {//TODO
                return(false);
            }
        }
コード例 #13
0
        public bool Create(MasterViewModel input)
        {
            DBModel context            = new DBModel();
            DbRepository <Master> repo = new DbRepository <Master>(context);

            if (repo.GetAll().FirstOrDefault((x) => x.master_account == input.master_account) == null)
            {
                Master entity = new Master()
                {
                    master_account  = input.master_account,
                    master_password = input.master_password
                };
                repo.Create(entity);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #14
0
        //internal bool Create(SubCategoryViewModel csv)
        //{
        //    throw new NotImplementedException();
        //}

        // -------- add

        public bool Create(CategoryViewModel input)
        {
            DBModel context = new DBModel();
            DbRepository <CategoryGroup> repo = new DbRepository <CategoryGroup>(context);

            if (repo.GetAll().FirstOrDefault((x) => x.Category_Name == input.Category_Name) == null)
            {
                CategoryGroup entity = new CategoryGroup()
                {
                    Category_Id   = input.Category_Id,
                    Category_Name = input.Category_Name,
                };
                repo.Create(entity);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #15
0
ファイル: DbRepositoryTests.cs プロジェクト: Yura95st/DBMS
        public void Create_DatabaseIsValid_CreatesNewDatabase()
        {
            // Arrange
            Row row = new Row {
                Id = 0, Value = { "someValue" }
            };

            Table table = new Table
            {
                Name       = "someTable", NextRowId = row.Id + 1,
                Attributes = { new Models.Attribute {
                                   Name = "firstAttribute", Type = "someType"
                               } },
                Rows = { { row.Id, row } }
            };

            Database database = new Database
            {
                Name = "testDatabase", Tables = new Dictionary <string, Table> {
                    { table.Name, table }
                }
            };

            string dbFilePath = this.GetDbFilePath(database.Name);

            // Arrange - create target
            IDbRepository target = new DbRepository(this._dbRepositorySettings);

            // Act
            target.Create(database);

            // Assert
            Assert.IsTrue(File.Exists(dbFilePath));

            string dbJson = File.ReadAllText(dbFilePath);

            Assert.AreEqual(JsonConvert.DeserializeObject <Database>(dbJson), database);
        }
コード例 #16
0
ファイル: SaleService.cs プロジェクト: benblackcake/shopMVC
        public bool Create(SaleViewModel input)
        {
            DBModel             context = new DBModel();
            DbRepository <Sale> repo    = new DbRepository <Sale>(context);

            if (repo.GetAll().FirstOrDefault((x) => x.Sale_Product == input.Sale_Product) == null)
            {
                Sale entity = new Sale()
                {
                    Sale_Product   = input.Sale_Product,
                    Sale_UnPrice   = input.Sale_UnPrice,
                    Sale_FristDate = input.Sale_FristDate,
                    Sale_LastDate  = input.Sale_LastDate
                };
                repo.Create(entity);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #17
0
        /*        DBModel context = new DBModel();
         * DbRepository<Customer> repo = new DbRepository<Customer>(context);
         */
        public bool Create(CustomerViewModel input)
        {
            DBModel context = new DBModel();
            DbRepository <Customer> repo = new DbRepository <Customer>(context);

            if (repo.GetAll().FirstOrDefault((x) => x.Customer_Email == input.Customer_Email) == null)
            {
                Customer entity = new Customer()
                {
                    Customer_Name  = input.Customer_Name,
                    Customer_Email = input.Customer_Email,
                    Customer_Phone = input.Customer_Phone,
                    User_Password  = input.User_Password
                };
                repo.Create(entity);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #18
0
        public bool AddSubCategory(SubCategoryViewModel input)
        {
            DBModel context = new DBModel();
            //DbRepository<CategoryGroup> Crepo = new DbRepository<CategoryGroup>(context);
            DbRepository <Sub_Categroy> Srepo = new DbRepository <Sub_Categroy>(context);

            if (Srepo.GetAll().FirstOrDefault((x) => x.Category_Name == input.Category_Name) == null)
            {
                Sub_Categroy entity = new Sub_Categroy()
                {
                    Sub_Category_ID = input.Sub_Category_ID,
                    Category_Name   = input.Category_Name,
                    Category_ID     = input.Category_ID
                };
                Srepo.Create(entity);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #19
0
        public async Task Create_ReturnsId_NewId()
        {
            // Arrange 
            var mockSet = new Mock<DbSet<StoredUser>>();
            var mockContext = new Mock<IAutoSysContext>();

            mockContext.Setup(m => m.Users).Returns(mockSet.Object);
            var user = new StoredUser {Name = "Steven", MetaData = "Validator"};

            // Act 
            var service = new DbRepository<StoredUser>(mockContext.Object);
            var id = await service.Create(user);

            // Assert 
            Assert.AreEqual(user.Id, id); // True for EF but not for interface 
        }
コード例 #20
0
        public async Task Create_SavesUserInContext()
        {
            // Arrange 
            var mockSet = new Mock<DbSet<StoredUser>>();
            var mockContext = new Mock<IAutoSysContext>();
            mockContext.Setup(m => m.Users).Returns(mockSet.Object);

            // Act 
            var service = new DbRepository<StoredUser>(mockContext.Object);
            var id = await service.Create(new StoredUser());

            // Assert 
            // mockSet.Verify(m => m.Add(It.IsAny<StoredUser>()), Times.Once());
            mockContext.Verify(m => m.SaveChangesAsync(), Times.Once());
        }