public void Add_WhenIdIsZero_SavesANewEntity() { var point = PricePointEntity.Create(3, 5m, new DateTime(2016, 1, 1)); repository.Add(point); NhibernateUnitOfWork.Current.Commit(); // use session to try to load the product using (ISession session = Fixture.SessionFactory.OpenSession()) { Assert.True(point.Id > 3); var fromDb = session.Get <PricePointEntity>(point.Id); // Test that the product was successfully inserted Assert.NotNull(fromDb); Assert.Equal(fromDb.Id, point.Id); Assert.NotSame(point, fromDb); Assert.Equal(3, fromDb.ItemId); Assert.Equal(5m, fromDb.Price); Assert.Equal(new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc), fromDb.Date); Assert.Equal(2016, fromDb.Year); Assert.Equal(1, fromDb.Month); Assert.Equal(1, fromDb.Day); } }
public void Update_ThrowsException_WhenExecutedOnANewObject() { var first = repository.GetAll().First(); PricePointEntity point = new PricePointEntity() { Id = first.Id }; Assert.ThrowsAny <NonUniqueObjectException>(() => repository.Update(point)); }
public void Update_ExistingItem_WhenFound() { PricePointEntity point = _Items[0]; point.Price = 123m; repository.Update(point); var fromDb = NhibernateUnitOfWork.Current.Session.Get <PricePointEntity>(point.Id); Assert.Equal(123m, fromDb.Price); }
//[Fact] public void GetItemPricesForYears_ReturnsAllRecords() { string dir = Directory.GetCurrentDirectory(); int binIndex = dir.IndexOf("\\bin\\"); dir = dir.Substring(0, binIndex); string path = Path.Combine(dir, "DepartmentOfStatistics\\CSV\\Eksportuota matricinė lentelė.csv"); var reader = new StreamReader(File.OpenRead(path)); List <string> listA = new List <string>(); List <string> listB = new List <string>(); List <string> listC = new List <string>(); string itemName = null; var now = DateTime.UtcNow; while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); if (!string.IsNullOrWhiteSpace(values[0])) { itemName = values[0]; } if (string.IsNullOrWhiteSpace(itemName)) { continue; } int year; var yearOk = int.TryParse(values[1], out year); decimal priceInLtl; var priceOk = decimal.TryParse(values[2], NumberStyles.Number, CultureInfo.InvariantCulture, out priceInLtl); if (yearOk && priceOk) { var item = _itemService.EnsureItemWithUnit(itemName); PricePointEntity pricePoint = new PricePointEntity { Date = new DateTime(year, 10, 1), DateEntered = now, Year = year, Month = 10, Day = 1, ItemId = item.Id, SourceId = 1, Price = CurrencyUtils.ConvertToEur(priceInLtl) }; _pricePointRepository.Add(pricePoint); } } }