public async Task TestAsync() { Assert.False(await _testProductRepo.AnyAsync()); var product = new TestProduct { Name = "Fristi Milk Async", Description = "Orange Flavor", Price = 10000 }; await _testProductRepo.AddAsync(product); Assert.True(await _testProductRepo.AnyAsync()); Assert.NotNull(product.Id); var alreadyAddedProduct = _testProductRepo.SingleOrDefault(c => c.Name == "Fristi Milk Async"); Assert.NotNull(alreadyAddedProduct); Assert.Equal(product.Id, alreadyAddedProduct.Id); alreadyAddedProduct.Description = "Lemon Flavor"; await _testProductRepo.UpdateAsync(alreadyAddedProduct); var updatedProduct = await _testProductRepo.GetByIdAsync(product.Id); Assert.NotNull(updatedProduct); Assert.Equal(product.Id, updatedProduct.Id); Assert.Equal("Lemon Flavor", updatedProduct.Description); }
/// <summary> /// Deep load all TestProduct children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.TestProductProvider.GetPaged(tm, 0, 10, out count); DataRepository.TestProductProvider.DeepLoading += new EntityProviderBaseCore <TestProduct, TestProductKey> .DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) { e.Cancel = true; } } ); if (mockCollection.Count > 0) { DataRepository.TestProductProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("TestProduct instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.TestProductProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
public void Generate_report() { var code = new string(Guid.NewGuid().ToString().Take(20).ToArray()); var supplier = TestSupplier.CreateNaked(session); var client = TestClient.CreateNaked(session); var price = supplier.Prices[0]; var order = new TestOrder(client.Users[0], price) { WriteTime = DateTime.Now.AddDays(-5) }; var productSynonym = price.AddProductSynonym(TestProduct.Random(session).First()); session.Save(productSynonym); var item = order.AddItem(TestProduct.RandomProducts(session).First(), 10, 456); item.SynonymCode = productSynonym.Id; item.Code = code; session.Save(order); Property("ReportInterval", 5); Property("SupplierId", supplier.Id); Property("Regions", new List <ulong> { client.RegionCode }); var AFCode = $"{item.Product.Id}_{item.CodeFirmCr ?? 0}"; var sheet = ReadReport <PulsOrderReport>(); var text = ToText(sheet); Assert.That(text, Does.Contain(AFCode)); }
public void FreeOrdersTest() { var supplier = TestSupplier.CreateNaked(session); var client = TestClient.CreateNaked(session); var product = new TestProduct("Тестовый продукт"); session.Save(product); var order = new TestOrder(client.Users.First(), supplier.Prices[0]); order.AddItem(product, 1, 100); session.Save(order); var result = ExecuteReport(); var sum1 = result.AsEnumerable().Where(r => r["OrdersSum"] != DBNull.Value).Sum(r => (decimal)r["OrdersSum"]); var freeOrdersQuery = session.CreateSQLQuery( String.Format("INSERT INTO billing.freeorders VALUES({0}, {1});", order.Address.Payer.Id, supplier.Payer.Id)); freeOrdersQuery.ExecuteUpdate(); result = ExecuteReport(); var sum2 = result.AsEnumerable().Where(r => r["OrdersSum"] != DBNull.Value).Sum(r => (decimal)r["OrdersSum"]); Assert.That(sum2, Is.EqualTo(sum1 - 100)); }
public void Can_get_final_product_price_with_discount() { var product = new TestProduct { Id = 1, Name = "Product name 1", Price = 12.34M, CustomerEntersPrice = false, Published = true }; //customer var customer = new Customer(); //discounts var discount1 = new Discount { Id = 1, Name = "Discount 1", DiscountType = DiscountType.AssignedToSkus, DiscountAmount = 3, DiscountLimitation = DiscountLimitationType.Unlimited }; //discount1.AppliedToProducts.Add(product); product.AddAppliedDiscounts(discount1); //set HasDiscountsApplied property product.HasDiscountsApplied = true; _priceCalcService.GetFinalPrice(product, customer).ShouldEqual(9.34M); }
public void Setup() { var client = TestClient.CreateNaked(session); var address = client.Addresses[0]; supplier = TestSupplier.CreateNaked(session); var waybill = new TestWaybill(new TestDocumentLog(supplier, address)); product1 = session.Query <TestProduct>().First(); product2 = session.Query <TestProduct>().Skip(1).First(); waybill.Lines.Add(new TestWaybillLine(waybill) { Product = "Аксетин", CatalogProduct = product1, Quantity = 10, SerialNumber = "4563", EAN13 = "5290931004832", ProducerCost = 56, SupplierCost = 100, }); waybill.Lines.Add(new TestWaybillLine(waybill) { Product = "Аксетин", CatalogProduct = product2, Quantity = 10, SerialNumber = "4563", EAN13 = "5290931004832", ProducerCost = 56, SupplierCost = 70, }); session.Save(waybill); }
public void Complex_double_firmalize_no_automatic_synonim() { session.CreateSQLQuery("delete from AutomaticProducerSynonyms") .ExecuteUpdate(); var product = new TestProduct("9 МЕСЯЦЕВ КРЕМ ДЛЯ ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ"); product.CatalogProduct.Pharmacie = true; product.CatalogProduct.Monobrend = true; session.Save(product); var producer = new TestProducer("Валента Фармацевтика/Королев Ф"); session.Save(producer); price.AddProductSynonym("9 МЕСЯЦЕВ КРЕМ ДЛЯ ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ", product); price.CreateAssortmentBoundSynonyms( "5 ДНЕЙ ВАННА Д/НОГ СМЯГЧАЮЩАЯ №10 ПАК. 25Г", "Санкт-Петербургская ф.ф."); session.Save(price); TestAssortment.CheckAndCreate(session, product, producer); Reopen(); Price(@"9 МЕСЯЦЕВ КРЕМ ДЛЯ ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ;Валента Фармацевтика/Королев Ф;2864;220.92; 5 ДНЕЙ ВАННА Д/НОГ СМЯГЧАЮЩАЯ №10 ПАК. 25Г;Санкт-Петербургская ф.ф.;24;73.88;"); Formalize(); Formalize(); var count = session.CreateSQLQuery("select count(*) from AutomaticProducerSynonyms") .UniqueResult <long>(); Assert.That(count, Is.EqualTo(0)); }
public void Group_by_code_and_product() { var code = new string(Guid.NewGuid().ToString().Take(20).ToArray()); var supplier = TestSupplier.CreateNaked(session); var client = TestClient.CreateNaked(session); var price = supplier.Prices[0]; var order = new TestOrder(client.Users[0], price) { WriteTime = DateTime.Now.AddDays(-5) }; var productSynonym = price.AddProductSynonym(TestProduct.Random(session).First()); session.Save(productSynonym); var item = order.AddItem(TestProduct.RandomProducts(session).First(), 10, 456); item.SynonymCode = productSynonym.Id; item.Code = code; session.Save(order); Property("ReportInterval", 5); Property("SupplierProductCodePosition", 0); Property("SupplierProductNamePosition", 1); Property("FirmCodeEqual", new List <ulong> { supplier.Id }); var sheet = ReadReport <RatingReport>(); Assert.AreEqual("Оригинальный код товара", sheet.GetRow(2).GetCell(0).StringCellValue); Assert.AreEqual(code, sheet.GetRow(3).GetCell(0).StringCellValue); Assert.AreEqual("Оригинальное наименование товара", sheet.GetRow(2).GetCell(1).StringCellValue); Assert.AreEqual(productSynonym.Name, sheet.GetRow(3).GetCell(1).StringCellValue); }
public IEnumerator GetAmount() { yield return(TestInitConditions()); TestProduct p = new TestProduct(1, "a"); TestProduct p2 = new TestProduct(2, "b"); IProduct[] toRegister = new IProduct[] { p }; wallet.RegisterProducts(toRegister, true); wallet.ChangeAmount(p, 1); uint amount1 = wallet.GetAmount(p); uint amount2 = wallet.GetAmount(p.GetProductId()); LogAssert.Expect(LogType.Error, "Product 2 not properly registered"); uint amount3 = wallet.GetAmount(p2); LogAssert.Expect(LogType.Error, "Product 2 not properly registered"); uint amount4 = wallet.GetAmount(p2.GetProductId()); Assert.True(amount1 == 1, "Unexpected Amount"); Assert.True(amount2 == 1, "Unexpected Amount"); Assert.True(amount3 == 0, "Unexpected Amount"); Assert.True(amount4 == 0, "Unexpected Amount"); }
public async Task TestUpdate() { var data = new QueryTestData(); var connection = await data.SetUp(); connection.Sql().HasColumnSet <TestProduct>("kind+content", x => x.Kind, x => x.Content); var p1Changed = new TestProduct { Id = data.Id1, Kind = 999, Content = "Modified" }; var rows = await connection.UpdateAsync(p1Changed, "kind+content"); Assert.AreEqual(1, rows); var product = (await connection.SelectWhereAsync <TestProduct>("WHERE Content = 'Modified'")).Single(); Assert.IsTrue(product.Id == data.Id1); Assert.AreEqual("Modified", product.Content); Assert.AreEqual(999, product.Kind); Assert.AreEqual(-5, product.Value); Assert.AreEqual(TestEnum.All, product.Enum); }
public void Test() { Assert.False(_testProductRepo.Any()); var product = new TestProduct { Name = "Fristi Milk", Description = "Orange Flavor", Price = 10000 }; _testProductRepo.Add(product); Assert.True(_testProductRepo.Any()); Assert.NotNull(product.Id); var alreadyAddedProduct = _testProductRepo.SingleOrDefault(c => c.Name == "Fristi Milk"); Assert.NotNull(alreadyAddedProduct); Assert.Equal(product.Id, alreadyAddedProduct.Id); alreadyAddedProduct.Description = "Lemon Flavor"; _testProductRepo.Update(alreadyAddedProduct); var updatedProduct = _testProductRepo.GetById(product.Id); Assert.NotNull(updatedProduct); Assert.Equal(product.Id, updatedProduct.Id); Assert.Equal("Lemon Flavor", updatedProduct.Description); }
private Response HttpServerWithNpgsqlInsert(dynamic parameters) { var response = RunDbFunction(options.Database, () => { TestProduct prod = new TestProduct("Test Prod", PROD_DESC); using (var conn = new NpgsqlConnection(options.Database)) { conn.Open(); // Insert some data using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = InsertSQL; //@id, @data, @last_modified, @version, @dotnet_type cmd.Parameters.AddWithValue("id", prod.Id); cmd.Parameters.AddWithValue("data", NpgsqlDbType.Jsonb, JsonConvert.SerializeObject(prod)); cmd.Parameters.AddWithValue("last_modified", DateTimeOffset.Now); cmd.Parameters.AddWithValue("version", Guid.NewGuid()); cmd.Parameters.AddWithValue("dotnet_type", prod.GetType().ToString()); cmd.ExecuteNonQuery(); } } }); return(response); }
public async Task TestInsert() { var data = new QueryTestData(); var connection = await data.SetUp(); var p3 = new TestProduct { Kind = 3, Content = "Reboot", Value = 5, Date = DateTime.UtcNow, MaybeDate = DateTime.UtcNow, Last = false }; connection.Sql().HasColumnSet <TestProduct>("kind+content+value+date+last", x => x.Kind, x => x.Content, x => x.Value, x => x.Date, x => x.Last); var rows = await connection.InsertAsync(p3, "kind+content+value+date+last"); Assert.AreEqual(1, rows); var product = (await connection.SelectWhereAsync <TestProduct>("WHERE Content = 'Reboot'")).Single(); Assert.IsTrue(product.Id > 0); Assert.AreEqual(p3.Content, product.Content); Assert.AreEqual(p3.Value, product.Value); Assert.IsNull(product.MaybeDate); }
public IEnumerator CleanRegisterProducts() { yield return(TestInitConditions()); TestProduct p = new TestProduct(1, "a"); TestProduct p2 = new TestProduct(2, "b"); TestProduct p3 = new TestProduct(3, "a"); TestProduct p4 = new TestProduct(4, "b"); TestProduct p5 = new TestProduct(5, "b"); IProduct[] toRegister = new IProduct[] { p, p2, p3, p4 }; wallet.RegisterProducts(toRegister, true); Assert.IsTrue(wallet.IsProductRegistered(p4), " Product not registered "); Assert.IsFalse(wallet.IsProductRegistered(p5), " Product registered "); Assert.IsTrue(wallet.GetProducts().Length == 4, " Unexpected amount of registered products "); toRegister = new IProduct[] { p, p2 }; wallet.RegisterProducts(toRegister, true); wallet.RegisterProduct(p3); Assert.IsFalse(wallet.IsProductRegistered(p4), " Product registered "); Assert.IsFalse(wallet.IsProductRegistered(p5), " Product registered "); Assert.IsTrue(wallet.GetProducts().Length == 3, " Unexpected amount of registered products "); toRegister = new IProduct[] { p4, p5 }; wallet.RegisterProducts(toRegister, false); Assert.IsTrue(wallet.IsProductRegistered(p4), " Product not registered "); Assert.IsTrue(wallet.IsProductRegistered(p5), " Product not registered "); Assert.IsTrue(wallet.GetProducts().Length == 5, " Unexpected amount of registered products "); }
public void FormalizePositionWithForbiddenProducer() { var product = new TestProduct("9 МЕСЯЦЕВ КРЕМ ДЛЯ ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ"); product.CatalogProduct.Pharmacie = true; session.Save(product); var query = session.CreateSQLQuery("delete from farm.unrecexp"); query.UniqueResult(); var forbiddenProducer = new ForbiddenProducerNames { Name = "Валента Фармацевтика/Королев Ф" }; session.Save(forbiddenProducer); session.Flush(); var producer = new TestProducer("Валента Фармацевтика/Королев Ф"); session.Save(producer); var newPrice = session.Load <Price>(price.Id); var synonym = new ProductSynonym { Price = newPrice, Product = session.Load <Product>(product.Id), Synonym = "9 МЕСЯЦЕВ КРЕМ ДЛЯ ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ" }; session.Save(synonym); Reopen(); Price(@"9 МЕСЯЦЕВ КРЕМ ДЛЯ ПРОФИЛАКТИКИ И КОРРЕКЦИИ РАСТЯЖЕК 150МЛ;Валента Фармацевтика/Королев Ф;2864;220.92;"); Formalize(); query = session.CreateSQLQuery("select count(*) from farm.unrecexp"); var result = Convert.ToInt32(query.UniqueResult()); Assert.That(result == 0); }
public IEnumerator CleanAmount() { yield return(TestInitConditions()); TestProduct p = new TestProduct(1, "a"); TestProduct p2 = new TestProduct(2, "b"); TestProduct p3 = new TestProduct(3, "a"); IProduct[] toRegister = new IProduct[] { p, p2, p3 }; wallet.RegisterProducts(toRegister, true); wallet.ChangeAmount(p, 1); wallet.ChangeAmount(p2, 23); wallet.ChangeAmount(p3, 99); wallet.ChangeAmount(p3, -50); Assert.IsTrue(wallet.GetAmount(p) == 1, "Unexpected Amount"); Assert.IsTrue(wallet.GetAmount(p2) == 23, "Unexpected Amount"); Assert.IsTrue(wallet.GetAmount(p3) == 49, "Unexpected Amount"); wallet.ClearWalletAmounts(); Assert.IsTrue(wallet.IsProductRegistered(p), "Product not registered after clean"); Assert.IsTrue(wallet.IsProductRegistered(p2), "Product not registered after clean"); Assert.IsTrue(wallet.IsProductRegistered(p3), "Product not registered after clean"); Assert.IsTrue(wallet.GetAmount(p) == 0, "Unexpected Amount"); Assert.IsTrue(wallet.GetAmount(p2) == 0, "Unexpected Amount"); Assert.IsTrue(wallet.GetAmount(p3) == 0, "Unexpected Amount"); }
private TestWaybillLine CreateBodyLine(string serialNumber = null, TestProduct product = null) { var user = TestUser.Queryable.First(u => u.AvaliableAddresses.Count > 0); if (product == null) { product = TestProduct.Queryable.First(); } var documentLog = new TestDocumentLog(testSupplier, user.Client) { FileName = Path.GetRandomFileName() + ".txt" }; var document = new TestWaybill(documentLog); var documentLine = new TestWaybillLine { Waybill = document, SerialNumber = serialNumber, CatalogProduct = product }; document.Lines = new List <TestWaybillLine>(); document.Lines.Add(documentLine); document.Save(); Assert.That(document.Lines.Count, Is.EqualTo(1)); Assert.That(document.Lines[0].Id, Is.GreaterThan(0)); return(documentLine); }
public void Resolve_monobrend_producer_synonym() { var exp = new TestUnrecExp("test", "test", price); session.Save(exp); var product = new TestProduct("Тестовый товар монобренд") { CatalogProduct = { Monobrend = true } }; session.Save(product); var producer = new TestProducer("Тестовый производитель"); session.Save(producer); session.Save(new TestAssortment(product, producer, true)); Load(); Resolve(exp, product); Save(); var synonyms = session.Query <TestProducerSynonym>().Where(s => s.Price == price).ToArray(); Assert.AreEqual(1, synonyms.Length, synonyms.Implode()); Assert.AreEqual(synonyms[0].Producer.Id, producer.Id); Assert.AreEqual(synonyms[0].Name, exp.FirmCr); }
public void Insert() { TestProduct entity = _repository.Insert(_testProduct.Generate()); Assert.IsNotNull(entity); Assert.IsNotNull(entity.Id); }
public void Download_source() { var testProduct = new TestProduct("Тестовый продукт"); session.Save(testProduct); var product = Product.Find(testProduct.Id); var source = new KatrenSource(); var certificateSource = new CertificateSource(); certificateSource.SourceClassName = source.GetType().Name; session.Save(certificateSource); var line = new DocumentLine { ProductEntity = product, SerialNumber = "012011", }; var sourceCatalog = new CertificateSourceCatalog { CertificateSource = certificateSource, SerialNumber = line.SerialNumber, CatalogProduct = product.CatalogProduct, SupplierCode = "34266440", SupplierProducerCode = "13483667", OriginFilePath = KatrenSource.ToOriginFileName(0x1B9EFC8), }; session.Save(sourceCatalog); var task = new CertificateTask(certificateSource, line); var files = source.GetCertificateFiles(task, null); Assert.That(files.Count, Is.EqualTo(4)); }
public void Clean_matrix() { var supplier = DataMother.CreateSupplier(); session.Save(supplier); var price = supplier.Prices[0]; price.IsMatrix = true; price.PrepareSave(); session.Save(price); session.Flush(); var testPrice = session.Load <TestPrice>(price.Id); var product = new TestProduct("Тестовый продукт"); session.Save(product); var item = new TestBuyingMatrix(testPrice, product); session.Save(item); Reopen(); price = session.Load <Price>(price.Id); price.IsMatrix = false; price.PrepareSave(); session.Save(price); session.Flush(); Reopen(); item = session.Get <TestBuyingMatrix>(item.Id); Assert.IsNull(item); }
public void SetUp() { var priceParent = TestSupplier.CreateNaked(session).Prices[0]; var price = TestSupplier.CreateNaked(session).Prices[0]; price.ParentSynonym = priceParent.Id; Save(price); _supplier = price.Supplier; var client = TestClient.CreateNaked(session); var testAddress = client.Addresses[0]; var order = new TestOrder(); _product = new TestProduct("Виагра (табл.)"); _product.CatalogProduct.Pharmacie = true; session.Save(_product); _producer = new TestProducer("Пфайзер"); session.Save(_producer); session.Save(new TestSynonym() { Synonym = "Виагра", ProductId = _product.Id, PriceCode = (int?)price.Id }); session.Save(new TestSynonymFirm() { Synonym = "Пфайзер", CodeFirmCr = (int?)_producer.Id, PriceCode = (int?)price.Id }); TestAssortment.CheckAndCreate(session, _product, _producer); var log = new DocumentReceiveLog(session.Load <Supplier>(_supplier.Id), session.Load <Address>(testAddress.Id)) { MessageUid = 123, DocumentSize = 100 }; _doc = new Document(log) { OrderId = order.Id, Address = log.Address, DocumentDate = DateTime.Now }; _supplierCode = new SupplierCode { Code = "45678", Supplier = session.Load <Supplier>(_supplier.Id), ProducerId = _producer.Id, Product = session.Load <Product>(_product.Id), CodeCr = string.Empty }; session.Save(_supplierCode); // сопоставляется по коду _documentLine = _doc.NewLine(); _documentLine.Product = "Виагра"; _documentLine.Producer = " Тестовый производитель "; _documentLine.Code = "45678"; }
///<summary> /// Update the Typed TestProduct Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, TestProduct mock) { TestProductTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
public void Get() { TestProduct entityInsert = _repository.Insert(_testProduct.Generate()); TestProduct entity = _repository.Get(entityInsert.Id); Assert.IsNotNull(entity); Assert.AreEqual(entityInsert.Id, entity.Id); }
public ActionResult Index(TestProduct product) { TestProductBAL productBAL = new TestProductBAL(); var entryInfo = productBAL.GetEntryInfo(product); int result = productBAL.SaveProduct(product); return(View()); }
/// <summary> /// Check the foreign key dal methods. /// </summary> private void Step_10_FK_Generated() { using (TransactionManager tm = CreateTransaction()) { TestProduct entity = CreateMockInstance(tm); bool result = DataRepository.TestProductProvider.Insert(tm, entity); Assert.IsTrue(result, "Could Not Test FK, Insert Failed"); } }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); TestProduct entity = mock.Copy() as TestProduct; entity = (TestProduct)mock.Clone(); Assert.IsTrue(TestProduct.ValueEquals(entity, mock), "Clone is not working"); } }
///<summary> /// Returns a Typed TestProduct Entity with mock values. ///</summary> static public TestProduct CreateMockInstance(TransactionManager tm) { // get the default mock instance TestProduct mock = TestProductTest.CreateMockInstance_Generated(tm); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); // return the modified object return(mock); }
public IEnumerator GetOwnedProductsByType() { yield return(TestInitConditions()); TestProduct p = new TestProduct(1, "a"); TestProduct p2 = new TestProduct(2, "b"); TestProduct p3 = new TestProduct(3, "a"); TestProduct p4 = new TestProduct(4, "b"); TestProduct p5 = new TestProduct(5, "a"); TestProduct p6 = new TestProduct(6, "b"); TestProduct p7 = new TestProduct(7, "a"); IProduct[] toRegister = new IProduct[] { p, p2, p3, p4, p6 }; wallet.RegisterProducts(toRegister, true); wallet.ChangeAmount(p, 1); wallet.ChangeAmount(p2, 0); wallet.ChangeAmount(p3, 3); wallet.ChangeAmount(p3, -2); wallet.ChangeAmount(p4, 4); wallet.ChangeAmount(p4, -4); LogAssert.Expect(LogType.Error, "Product not registered for id 5"); wallet.ChangeAmount(p5, 5); wallet.ChangeAmount(p6, 6); LogAssert.Expect(LogType.Error, "Product not registered for id 7"); wallet.ChangeAmount(p7, 7); IProduct[] productsA = wallet.GetOwnedProductsByType("a"); ISet <IProduct> productSetA = new HashSet <IProduct>(productsA, new IProductEqualityComparer()); IProduct[] productsB = wallet.GetOwnedProductsByType("b"); ISet <IProduct> productSetB = new HashSet <IProduct>(productsB, new IProductEqualityComparer()); Assert.IsTrue(productSetA.Count == 2, "Wrong amount of products in set A"); Assert.IsTrue(productSetA.Contains(p), "Product not owned"); Assert.IsFalse(productSetA.Contains(p2), "Product owned in set A"); Assert.IsTrue(productSetA.Contains(p3), "Product not owned"); Assert.IsFalse(productSetA.Contains(p4), "Product owned in set A"); Assert.IsFalse(productSetA.Contains(p5), "Product owned in set A"); Assert.IsFalse(productSetA.Contains(p6), "Product owned in set A"); Assert.IsFalse(productSetA.Contains(p7), "Product owned in set A"); Assert.IsTrue(productSetB.Count == 1, "Wrong amount of products in set B"); Assert.IsFalse(productSetB.Contains(p), "Product owned in set B"); Assert.IsFalse(productSetB.Contains(p2), "Product owned in set B"); Assert.IsFalse(productSetB.Contains(p3), "Product owned in set B"); Assert.IsFalse(productSetB.Contains(p4), "Product owned in set B"); Assert.IsFalse(productSetB.Contains(p5), "Product owned in set B"); Assert.IsTrue(productSetB.Contains(p6), "Product not owned in set B"); Assert.IsFalse(productSetB.Contains(p7), "Product owned in set B"); }
public void SimpleTest() { var templete = @"@Code @Name @Id"; var entity = new TestProduct(); entity.Id = TestHelper.RandomizeInt(); entity.Code = string.Concat("code-", TestHelper.RandomizeString()); entity.Name = string.Concat("name-", TestHelper.RandomizeString()); Console.WriteLine(entity.ToText()); Console.WriteLine(entity.ToText(templete)); }
public void DeletesEntityBasedOnItsId() { using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { var collection = mongo.GetCollection<TestProduct>("Fake"); var product1 = new TestProduct(); var product2 = new TestProduct(); collection.Insert(new[] { product1, product2 }); Assert.Equal(2, collection.Count()); collection.Delete(product1); Assert.Equal(1, collection.Count()); Assert.Equal(1, collection.Count(new { Id = product2._id })); } }
public async Task GetBlobFromContainer_Should_Return_Blob_When_Blob_Exists() { // Arrange Container container = ContainerConfig.CreateContainer(); IAzureClient client = container.GetInstance<IAzureClient>(); var expected = new TestProduct { ProductId = Guid.NewGuid() }; string productId = expected.ProductId.ToString(); // Act await client.PutBlobToContainer("testblob", productId, JObject.FromObject(expected).ToString()); string content = await client.GetBlobFromContainer("testblob", productId); var actual = JObject.Parse(content).ToObject<TestProduct>(); Uri url = await client.GetBlobUrl("testblob", productId); // Assert actual.ProductId.Should().Be(expected.ProductId); url.Should().NotBeNull(); }
public void InventorySubqueryShouldReturnOneForTwoProducts() { using (var session = new Session()) { //create a Product var p = new TestProduct() { Name = "Test1", Price = 10 }; //change the inventory p.Inventory.Add(new InventoryChange() { AmountChanged = 1 }); session.Add(p); p = new TestProduct() { Name = "Test3", Price = 10 }; //change the inventory p.Inventory.Add(new InventoryChange() { AmountChanged = 1 }); p.Inventory.Add(new InventoryChange() { AmountChanged = 2 }); p.Inventory.Add(new InventoryChange() { AmountChanged = -1 }); session.Add(p); var products = session.Products.Where(x => x.Inventory.Count() > 2).ToArray(); Assert.Equal(1, products.Count()); Assert.Equal("Test3", products[0].Name); } }
public void LinqQueriesShouldSupportExternalObjectProperties2() { var another = new Supplier { Name = "test1" }; var external = new TestProduct { Price = 10, Supplier = another }; using (var session = new Session()) { session.Add(new TestProduct { Name = "test", Price = 30 }); session.Add(new TestProduct { Name = "test1", Price = external.Price }); var queryable = session.Products; var product = queryable .Where(p => p.Name == external.Supplier.Name) .SingleOrDefault(); Assert.Equal(10, product.Price); Assert.Equal(false, queryable.QueryStructure().IsComplex); } }
public void LinqQueriesShouldSupportExternalObjectProperties() { var external = new TestProduct { Price = 10 }; using (var session = new Session()) { session.Add(new TestProduct { Name = "test", Price = 30 }); session.Add(new TestProduct { Name = "test1", Price = external.Price }); var queryable = session.Products; var product = queryable.Where(p => p.Price == external.Price) .ToList(); Assert.Equal(10, product[0].Price); Assert.Equal(false, queryable.QueryStructure().IsComplex); } }
public void LinqQueriesShouldSupportExternalObjectProperties2() { // NOTE: This one fails because there's no support for parsing the object's property. // This even more complex when using a nested type like a product's supplier var another = new Supplier {Name = "test1"}; var external = new TestProduct { Price = 10, Supplier = another }; using (var session = new Session()) { session.Add(new TestProduct { Name = "test", Price = 30 }); session.Add(new TestProduct { Name = "test1", Price = external.Price }); var product = session.Products .Where(p => p.Name == external.Supplier.Name) .SingleOrDefault(); Assert.Equal(10, product.Price); } }
public void InsertingMultipleNewEntityWithObjectIdKeyGeneratesAKey() { using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { var product1 = new TestProduct { _id = null }; var product2 = new TestProduct { _id = null }; mongo.GetCollection<TestProduct>("Fake").Insert(new[] { product1, product2 }); Assert.NotNull(product1._id); Assert.NotEqual(ObjectId.Empty, product1._id); Assert.NotNull(product2._id); Assert.NotEqual(ObjectId.Empty, product2._id); } }
public void SavingANewEntityWithObjectIdKeyGeneratesAKey() { using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { var product = new TestProduct { _id = null }; mongo.GetCollection<TestProduct>("Fake").Insert(product); Assert.NotNull(product._id); Assert.NotEqual(ObjectId.Empty, product._id); } }