public async void GetComputerCaseByNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCaseByNameDatabase")
                          .Options;
            var computercase1 = new ComputerCases {
                Name = "test name1", Size = "Mid Tower", Price = 90.99M
            };
            var computercase2 = new ComputerCases {
                Name = "test name2", Size = "Full Tower", Price = 105.99M
            };

            ComputerCase computercase = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(computercase1);
                context.Add(computercase2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                computercase = await service.GetComputerCaseByName("test name1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal("Mid Tower", computercase.Size);
                Assert.Equal(90.99M, computercase.Price);
            }
        }
        public async void GetComputerCasesFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCasesFromDatabase")
                          .Options;
            var computercase = new ComputerCases {
                Name = "test name", Size = "Mid Tower", Price = 79.99M
            };
            List <ComputerCase> listofcomputercases = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(computercase);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofcomputercases = await service.GetComputerCases();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofcomputercases);
                Assert.Equal("test name", context.ComputerCases.Single().Name);
            }
        }
        public async Task <ActionResult> Create(ComputerCases cc)
        {
            try
            {
                string jsonString = JsonConvert.SerializeObject(cc);

                var request = new HttpRequestMessage(HttpMethod.Post, "api/computercases");
                {
                    // we set what the Content-Type header will be here
                    request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");
                };

                var response = await HttpClient.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    return(View("Error"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #4
0
 public void AddCase(List <Case> computerCase)
 {
     foreach (Case c in computerCase)
     {
         ComputerCases.Add(c);
     }
 }
        // GET: Inventorys/Details/5
        public async Task <ActionResult> Details(string name)
        {
            var request = CreateRequestToService(HttpMethod.Get, "api/computercases/" + name);

            try
            {
                var response = await HttpClient.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    TempData["statuscode"] = response.StatusCode;
                    return(View("Error"));
                }
                string jsonString = await response.Content.ReadAsStringAsync();

                ComputerCases cc = JsonConvert.DeserializeObject <ComputerCases>(jsonString);

                return(View(cc));
            }
            catch (HttpRequestException)
            {
                return(View("Error"));
            }
        }
Example #6
0
 public void AddCase(Case computerCase)
 {
     ComputerCases.Add(computerCase);
 }