public void Ensure_valid_prices_would_be_updated2() { var today = Clock.FixedTime.Today; var yesterday = today.AddDays(-1); var priceToUpdate = new Price(10, yesterday) { ValidFrom = yesterday, ValidTo = today }; var priceToSkip = new Price(20, yesterday) { ValidFrom = yesterday, ValidTo = yesterday }; _testHelper.Persist(priceToUpdate, priceToSkip); var rateProviderStub = new RateProviderStub(); var task = new UpdatePricesTask(_sessionManager, Clock.FixedTime, rateProviderStub); task.Run(); var savedPriceToUpdate = _testHelper.Load<Price>(priceToUpdate.Id); var savedPriceToSkip = _testHelper.Load<Price>(priceToSkip.Id); savedPriceToUpdate.Satisfy(x => x.LocalAmount == 325m && x.LastUpdated == Clock.FixedTime.Today); savedPriceToSkip.Satisfy(x => x.LocalAmount == 0 && x.LastUpdated == yesterday); }
public void Ensure_valid_prices_would_be_updated2() { //Arrange. var currentDate = DateTime.Today; var price = new Price(10, currentDate.AddDays(-1)); var pricesToUpdate = new List<Price>{ price }; var repo = new MockRepository(MockBehavior.Loose); var transactionMock = repo.Create<ITransaction>(); transactionMock .Setup(x => x.Commit()) .Verifiable(); var queryMock = repo.Create<IQuery>(); queryMock .Setup(x => x.SetParameter("currentDate", currentDate)) .Returns(queryMock.Object); queryMock .Setup(x => x.List<Price>()) .Returns(pricesToUpdate); var sessionMock = repo.Create<ISession>(); sessionMock .Setup(x => x.BeginTransaction()) .Returns(transactionMock.Object) .Verifiable(); sessionMock .Setup(x => x.CreateQuery("from Price p where p.ValidFrom <= :currentDate and :currentDate <= p.ValidTo")) .Returns(queryMock.Object); var sessionFactoryMock = repo.Create<ISessionManager>(); sessionFactoryMock .Setup(x => x.OpenSession()) .Returns(sessionMock.Object); var clockMock = repo.Create<IClock>(); clockMock .SetupGet( x => x.Today) .Returns(currentDate); var rateProviderMock = repo.Create<IRateProvider>(); rateProviderMock .Setup(x => x.GetRateOn(currentDate)) .Returns(32.5m); var task = new UpdatePricesTask(sessionFactoryMock.Object, clockMock.Object, rateProviderMock.Object); //Act. task.Run(); //Assert. Assert.That(price.LocalAmount, Is.EqualTo(325)); repo.VerifyAll(); }