コード例 #1
0
ファイル: CacheTest.cs プロジェクト: Emrahdi/ProductCatalog
        public void TestCache()
        {
            TestCache test = new TestCache();

            test.Add("ProductCode1", CommonTestData.GetTestData("1"));
            test.Add("ProductCode2", CommonTestData.GetTestData("2"));
            test.Add("ProductCode3", CommonTestData.GetTestData("3"));
            Product p;

            test.TryGetValue("ProductCode2", out p);
            Assert.AreEqual(p.Code, "ProductCode2");
            test.Clear();
            Assert.AreEqual(test.Count, 0);

            test.Add("ProductCode1", CommonTestData.GetTestData("1"));
            test.Add("ProductCode2", CommonTestData.GetTestData("2"));
            test.Add("ProductCode3", CommonTestData.GetTestData("3"));
            Assert.AreEqual(test.ContainsKey("ProductCode1"), true);
            test.TryGetValue("ProductCode3", out p);
            Assert.AreEqual(test.Values.Contains(p), true);

            test.Remove("ProductCode1");
            Assert.AreEqual(test.ContainsKey("ProductCode1"), false);
            Assert.AreEqual(test.Count, 2);
        }
コード例 #2
0
        public void ProductDbOperationsOperations()
        {
            DefaultServices.RegisterDefaultServices();
            ProductCatalogContext ctx = new ProductCatalogContext();
            var     result            = ctx.Product.Where(p => p.Code == "Product1").ToList();
            Product product1          = CommonTestData.GetTestData();
            var     addProductResult1 = ctx.Product.Add(product1);

            ctx.SaveChanges();
            var getProductResult1 = ctx.Product.Where(p => p.Code == product1.Code).ToList().FirstOrDefault();

            Assert.AreEqual(getProductResult1.Name, product1.Name);
            getProductResult1.Name = "ProductNameNew";
            ctx.Product.Update(getProductResult1);
            ctx.SaveChanges();
            var getProductResult2 = ctx.Product.Where(p => p.Code == product1.Code).ToList().FirstOrDefault();

            Assert.AreEqual(getProductResult2.Name, "ProductNameNew");
            ctx.Product.Remove(getProductResult2);
            ctx.SaveChanges();
            var finalProductResult = ctx.Product.Find(getProductResult2.Id);

            Assert.AreEqual(finalProductResult, null);
        }