Ejemplo n.º 1
0
        public async void ShouldEditExistingCatalogEntry()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase("MyConnection");
            var context = new ApplicationDbContext(optionsBuilder.Options);

            var catalog = new Models.Catalog();

            catalog.Id            = 2;
            catalog.Name          = ".NET Core";
            catalog.Vendor        = "Microsoft";
            catalog.LatestVersion = "2.1";

            var createmodel = new CreateModel(context);

            createmodel.Catalog = catalog;

            await createmodel.OnPostCreateAsync();

            var newcatalog = new Models.Catalog();

            newcatalog.Id            = 2;
            newcatalog.Name          = ".NET Core";
            newcatalog.Vendor        = "Microsoft .NET";
            newcatalog.LatestVersion = "2.1";

            var editmodel = new EditModel(context);

            editmodel.Catalog = newcatalog;

            await editmodel.OnPostAsync();

            Assert.Equal("Microsoft .NET", context.Catalog.Find(2).Vendor);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Catalog = await _context.Catalog.FirstOrDefaultAsync(m => m.Id == id);

            if (Catalog == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 3
0
        public ActionResult Add(ViewModels.CatalogAdd info)
        {
            if (ModelState.IsValid)
            {
                var model = new Models.Catalog();
                model.ID         = dal.GetMaxId();
                model.AddTime    = DateTime.Now;
                model.Intro      = "";
                model.Modifytime = DateTime.Now;
                model.Name       = info.Name;
                model.Status     = 1;
                dal.Add(model);
                return(Redirect("/manage/catalog/index"));
            }

            return(View(info));
        }
Ejemplo n.º 4
0
        public async void ShouldAddNewCatalogEntry()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase("MyConnection");
            var context = new ApplicationDbContext(optionsBuilder.Options);

            var catalog = new Models.Catalog();

            catalog.Id            = 1;
            catalog.Name          = ".NET Core";
            catalog.Vendor        = "Microsoft";
            catalog.LatestVersion = "2.1";

            var createmodel = new CreateModel(context);

            createmodel.Catalog = catalog;

            await createmodel.OnPostCreateAsync();

            Assert.True(context.Catalog.Any());
        }
Ejemplo n.º 5
0
 public static DB.Catalog FromCatalogToDBCatalog(Models.Catalog catalog)
 {
     return(new DB.Catalog(catalog.Name, catalog.Category, catalog.Price, catalog.Quantity));
 }