Ejemplo n.º 1
0
        // GET: Chat/Delete/5
        public ActionResult Delete(int id)
        {
            FakeDb fakeDb = FakeDb.Instance;

            ChatMetier.Entities.Chat chat = fakeDb.Get(id);
            return(View(chat));
        }
Ejemplo n.º 2
0
        // GET: Chat
        public ActionResult Index()
        {
            FakeDb fakeDb = FakeDb.Instance;
            List <ChatMetier.Entities.Chat> chats = fakeDb.GetAll();

            return(View(chats));
        }
Ejemplo n.º 3
0
 public OrdersService(
     FakeDb fakeRepo,
     IDbConnection repo,
     BurgersService bs)
 {
     _fakeRepo = fakeRepo;
     _repo     = repo;
     _bs       = bs;
 }
Ejemplo n.º 4
0
        public void prinList()
        {
            IDb db = new FakeDb();

            // db.SeedMockList("");
            foreach (var m in db.SeedMockList(""))
            {
                System.Console.WriteLine("here is a list of all movies");
            }
        }
Ejemplo n.º 5
0
        public void CallsDbExecuteQuery()
        {
            var fakeDb = new FakeDb();

            var sqlWriter = new SqlDbItemWriter<string>(fakeDb);

            sqlWriter.Write(null);

            Assert.That(fakeDb.ExecuteCalled, Is.True);
        }
        /// <summary>
        /// This would be our "Grid Page" but with strong typing on our data instead of a DataTable.
        /// Runs Sql to get the full list and gives it to the UserMaintModel Properties to Go to the Front End.
        /// </summary>
        /// <returns></returns>
        public void OnGet()
        {
            FakeDb db = new FakeDb();

            // Build Sql
            string sql = "Select UserId, Owner From UserId";

            // Get Data and store in Property
            Users = db.Query <User>(sql);
        }
Ejemplo n.º 7
0
        public void CallsDbExecuteQuery()
        {
            var fakeDb = new FakeDb();

            var sqlWriter = new SqlDbItemWriter <string>(fakeDb);

            sqlWriter.Write(null);

            Assert.That(fakeDb.ExecuteCalled, Is.True);
        }
Ejemplo n.º 8
0
        public ActionResult Products(int pid)
        {
            IEnumerable <Product> products = FakeDb.GetProductsByCategoryId(pid);
            Category          c            = FakeDb.GetCategoryById(pid);
            ProductsViewModel viewModel    = new ProductsViewModel();

            viewModel.Products = products;
            viewModel.Category = c;
            return(View(viewModel));
        }
Ejemplo n.º 9
0
        public ViewResult Reviews()
        {
            ViewBag.Current = "Reviews";
            List <MovieReview> movrev = new List <MovieReview>();

            movrev = FakeDb.LoadData();
            //string CastString = convertToString(movrev.Cast);
            //ViewBag.CastString = CastString;
            //BERK BERK BERK BERK!!!!!!!!!!!!!!
            return(View(movrev));
        }
Ejemplo n.º 10
0
        // GET: Chat/Edit/5
        public ActionResult Edit(int id)
        {
            FakeDb fakeDb = FakeDb.Instance;

            ChatMetier.Entities.Chat chat = fakeDb.Get(id);
            if (chat == null)
            {
                //throw new HttpNotFoundResult();
            }
            return(View(chat));
        }
Ejemplo n.º 11
0
        public void DbIsCalledForActualExecution()
        {
            var fakeDb = new FakeDb();

            var sqlReader = new SqlDbItemReader <string>(fakeDb)
                            .Query("query")
                            .OrderBy("foo");

            sqlReader.Read(0, 10);

            Assert.That(fakeDb.ExecuteCalled, Is.True);
        }
        /*
         * Simulates our current structure in our Application with a basic page.
         * It can see all the UserIds in the Database and Edit one that is sent back.
         * This is not a working example.
         */

        /// <summary>
        /// This would simulate our "Grid Page".
        /// Runs Sql to get the full list and sends it to the front end.
        /// </summary>
        /// <returns></returns>
        public DataTable OnGet()
        {
            FakeDb db = new FakeDb();

            // Build Sql
            string sql = "Select UserId, Owner From UserId";

            // Get Data
            DataTable data = db.RunSql(sql);

            return(data);
        }
Ejemplo n.º 13
0
 public IActionResult Edit(UserResponse r)
 {
     if (ModelState.IsValid)
     {
         FakeDb.AddResponse(r);
         return(View("Details", r));
     }
     else
     {
         return(View(r));
     }
 }
Ejemplo n.º 14
0
 public IActionResult RsvpForm(GuestResponse guestResponse)
 {
     if (ModelState.IsValid)
     {
         FakeDb.AddResponse(guestResponse);
         return(View("Thanks", guestResponse)); // Thanks.cshtml
     }
     else
     {
         return(View());
     }
 }
Ejemplo n.º 15
0
        public void DbIsCalledForActualExecution()
        {
            var fakeDb = new FakeDb();

            var sqlReader = new SqlDbItemReader<string>(fakeDb)
                .Query("query")
                .OrderBy("foo");

            sqlReader.Read(0, 10);

            Assert.That(fakeDb.ExecuteCalled, Is.True);
        }
Ejemplo n.º 16
0
        public List <User> GetAllUsers()
        {
            FakeDb db = new FakeDb();

            // Build Sql
            string sql = "Select UserId, Owner From UserId";

            // Get Data and store in Property
            List <User> users = db.Query <User>(sql);

            return(users);
        }
Ejemplo n.º 17
0
 public ActionResult Edit(ChatMetier.Entities.Chat chat)
 {
     try
     {
         FakeDb fakeDb = FakeDb.Instance;
         fakeDb.Edit(chat);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 18
0
 public MainViewModel()
 {
     fakedb       = new FakeDb();
     QueryCommand = new RelayCommand(Query);
     ResetCommand = new RelayCommand(() =>
     {
         Search = string.Empty;
         this.Query();
     });
     EditCommand = new RelayCommand <int>(t => Edit(t));
     DelCommand  = new RelayCommand <int>(t => Del(t));
     AddCommand  = new RelayCommand(Add);
 }
Ejemplo n.º 19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddScoped <IPetRepository, PetRepository>();
            services.AddScoped <IPetService, PetService>();
            services.AddScoped <IOwnerRepository, OwnerRepository>();
            services.AddScoped <IOwnerService, OwnerService>();

            services.AddDbContext <PetshopContext>(
                opt => opt.UseSqlite("Data source=Petshop.db"));

            FakeDb.InitData();
        }
Ejemplo n.º 20
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         // TODO: Add delete logic here
         FakeDb fakeDb = FakeDb.Instance;
         fakeDb.Delete(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetRepository, PetRepository>();
            serviceCollection.AddScoped <IPetService, PetService>();
            serviceCollection.AddScoped <IPrinter, Printer>();

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var printer         = serviceProvider.GetRequiredService <IPrinter>();

            printer.startUI();
            FakeDb.InitialisePetData();
        }
Ejemplo n.º 22
0
        static void Main()
        {
            FakeDb.InitData();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetShopRepository, PetShopRepository>();
            serviceCollection.AddScoped <IPetShopService, PetShopService>();
            serviceCollection.AddScoped <IPrinter, Printer>();

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var printer         = serviceProvider.GetRequiredService <IPrinter>();

            printer.ChooseMenuItem();
        }
        /// <summary>
        /// Simulates one of our "Save Pages"
        /// Receives All the Data From Front End to Save
        /// </summary>
        /// <param name="row"></param>
        public void OnPost()
        {
            FakeDb db = new FakeDb();

            // Build Sql with Parameters to minimize risk of Sql Injection
            var sql = "Update UserId Set Owner = :Owner Where UserId = :UserId ";

            // Go through All the Data to Save
            // Ideally there would be a changed indicator to not save everything
            foreach (User user in Users)
            {
                // Because of the Parameters Dapper can automatically bind the Properties of User to the Sql
                db.Execute(sql, user);
            }
        }
Ejemplo n.º 24
0
    private void InitializeTabControl()
    {
        var db         = new FakeDb();
        var floorNames = (from fn in db.Floors select fn.Name).ToList();

        foreach (string floorName in floorNames)
        {
            var item = new TabItem()
            {
                Header  = floorName,
                Content = new Grid(),
            };
            tabControl1.Items.Add(item);
        }
    }
Ejemplo n.º 25
0
        //O que esse método tem a ver com a responsabilidade de reservar?
        //Esse método é tão generico que poderia estar em dezenas de lugares.
        //E provavelmente está, porque as pessoas acabam replicando esse tipo de lógica em todo canto
        public bool ValidaUsuarioTemCadastro(Pessoa usuario)
        {
            if (usuario == null)
            {
                return(false);
            }

            var banco = new FakeDb();

            if (banco.ExistePessoa(usuario.Id))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 26
0
        private static void Main()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetRepository, PetRepository>();
            serviceCollection.AddScoped <IPetService, PetService>();
            serviceCollection.AddScoped <IPrinter, Printer>();



            //then build provider
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var printer         = serviceProvider.GetRequiredService <IPrinter>();

            FakeDb.InitData();
            printer.BeginUI();
        }
Ejemplo n.º 27
0
 public ActionResult Create(PizzaVM pizzaVM)
 {
     try
     {
         Pizza newPizza = new Pizza
         {
             Nom         = pizzaVM.Pizza.Nom,
             Ingredients = FakeDb.IngredientsDisponibles.Where(i => pizzaVM.SelectedIngredients.Contains(i.Id)).ToList(),
             Pate        = FakeDb.PatesDisponibles.SingleOrDefault(p => p.Id == pizzaVM.SelectedPate)
         };
         Pizza addedPizza = FakeDb.AddPizza(newPizza);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        /// <summary>
        /// Simulates one of our "Save Pages"
        /// Receives All the Data From Front End to Save
        /// </summary>
        /// <param name="row"></param>
        public void OnPost(DataTable data)
        {
            FakeDb db = new FakeDb();

            // Not Exactly how we do it but should be enough to get the idea
            foreach (DataRow row in data.Rows)
            {
                // Store the data into individual variables
                string userid   = row.Field <string>(0);
                string newOwner = row.Field <string>(1);

                // Build Sql
                var sql = "Update UserId Set Owner = '" + newOwner + "' Where UserId = '" + userid + "'";

                // Execute Update
                db.RunSql(sql);
            }
        }
Ejemplo n.º 29
0
        public async Task PickSeedTest()
        {
            const string returnUrl   = "Home/Index";
            var          repository  = new FakeDb();
            var          storageMock = new Mock <IStorage>();

            storageMock.Setup(s => s.StoreValue(It.Is <DataSeed>(seed => repository.EmployeesSeeds.Last().Equals(seed))));
            storageMock.Setup(s => s.StoreValue(It.Is <string>(t => t.Equals(returnUrl))));
            storageMock.Setup(s => s.GetValue <string>()).Returns(returnUrl);
            sut = new PickerController(repository, storageMock.Object);


            var model    = (await sut.PickSeed(repository.EmployeesDiagram.DbDiagramId, returnUrl)).Model as List <Seed>;
            var redirect = await sut.PickSeed(repository.EmployeesSeeds.Last().DataSeedId);


            Assert.Equal(returnUrl, redirect.Url);
            Assert.True(model.All(m => m.DiagramId == repository.EmployeesDiagram.DbDiagramId));
            Assert.Equal(2, model.Count);
        }
Ejemplo n.º 30
0
        public async Task PickDiagramTest()
        {
            const string returnUrl   = "Home/Index";
            var          repository  = new FakeDb();
            var          storageMock = new Mock <IStorage>();

            storageMock.Setup(s => s.StoreValue(It.Is <DbDiagram>(diagram => repository.EmployeesDiagram.DbDiagramId == diagram.DbDiagramId)));
            storageMock.Setup(s => s.StoreValue(It.Is <string>(t => t.Equals(returnUrl))));
            storageMock.Setup(s => s.GetValue <string>()).Returns(returnUrl);
            sut = new PickerController(repository, storageMock.Object);


            var model    = (await sut.PickDiagram(returnUrl)).Model as List <DbDiagram>;
            var redirect = sut.PickDiagram(repository.EmployeesDiagram.DbDiagramId) as RedirectResult;


            Assert.Equal(returnUrl, redirect.Url);
            Assert.Equal(repository.EmployeesDiagram.DbDiagramId, model.First().DbDiagramId);
            Assert.Equal(repository.DatasDiagram.DbDiagramId, model.Last().DbDiagramId);
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            //PetPrinter petPrinter = new PetPrinter();

            FakeDb.InitData();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetRepository, PetRepository>();
            serviceCollection.AddScoped <IPrinter, PetPrinter>();
            serviceCollection.AddScoped <IPetService, PetService>();
            serviceCollection.AddScoped <IOwnerService, OwnerService>();
            serviceCollection.AddScoped <IOwnerRepository, OwnerRepository>();

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var petPrinter      = serviceProvider.GetRequiredService <IPrinter>();

            petPrinter.MakeMenu();

            Console.ReadLine();
        }
Ejemplo n.º 32
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //FakeDB.InitData();
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    var repo = scope.ServiceProvider.GetService <IPetRepository>();
                    FakeDb.InitData();
                }
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }